Install PostgreSQL on Linux (CentOS)

1. Install rpm

This installation address is always changing, if you directly copy the command on the Internet, it may not work. So go directly to the official website to get the yum installation command:
Official website address: https://www.postgresql.org/
insert image description here
Click Download
insert image description here
insert image description here
to select the corresponding version, and execute according to the commands provided by the official website, such as:
insert image description here

2. Install PostgreSQL and initialize

Similarly, install and initialize according to the official website documentation

yum install -y postgresql10-server
/usr/pgsql-10/bin/postgresql-10-setup initdb

like:
insert image description here

3. Set the startup

systemctl enable postgresql-10
systemctl start postgresql-10

insert image description here

4. Change password

1. Enter the system postgres user
( yum installs postgresql, and a system account named "postgres" will be created by default to execute PostgreSQL; )

su - postgres
#切换用户后,提示符变更为bash-4.2$

At the same time, a database user named "postgres" will also be generated in the database, and the password has been automatically generated
2. Log in to the database

#PostgreSQL在数据库用户同名的系统账号下登录免密;
-bash-4.2$ psql -U postgres
#执行后提示符变为 'postgres=#'

insert image description here
3. Change password

#设置postgres 用户的密码为123456
postgres=# alter user postgres with password '123456'
退出
\q

5. Open the remote connection

vi /var/lib/pgsql/10/data/postgresql.conf

Modify #listen_addresses = 'localhost' to listen_addresses='*'
insert image description here

6. Remote connection host authentication

vi /var/lib/pgsql/10/data/pg_hba.conf

Change it to:
#IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
0.0.0.0/0 means that all server connections are allowed
insert image description here
Restart the service after modification

systemctl restart postgresql-10

Eight, view port

netstat -tunlp

insert image description here

9. Navicat connects to PostgresSQL

insert image description here

insert image description here
Note:
If you are using a cloud server, remember to open port 5432 in the security group
insert image description here


Reference article link:
https://www.linuxidc.com/Linux/2017-10/147536.htm

Guess you like

Origin blog.csdn.net/weixin_44732379/article/details/122354162
Recommended