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/
Click Download
to select the corresponding version, and execute according to the commands provided by the official website, such as:
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:
3. Set the startup
systemctl enable postgresql-10
systemctl start postgresql-10
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=#'
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='*'
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
Restart the service after modification
systemctl restart postgresql-10
Eight, view port
netstat -tunlp
9. Navicat connects to PostgresSQL
Note:
If you are using a cloud server, remember to open port 5432 in the security group
Reference article link:
https://www.linuxidc.com/Linux/2017-10/147536.htm