参考:https://www.postgresql.org/download/linux/redhat/
- Install the repository RPM:
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-1.noarch.rpm
- Install the client packages:
yum install postgresql10
- Optionally install the server packages:
yum install postgresql10-server
- Optionally initialize the database and enable automatic start:
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10
修改密码:
su postgres
psql
ALTER USER postgres WITH PASSWORD '123456';
\q
su root
修改PostgresSQL数据库配置实现远程访问
①、修改postgresql.conf
文件:
vi /var/lib/pgsql/10/data/postgresql.conf
将listen_addresses
前的#
去掉,并将 listen_addresses = 'localhost'
改成 listen_addresses = '*'
;
②、修改客户端认证配置文件pg_hba.conf,将需要远程访问数据库的IP地址或地址段加入该文件。
vi /var/lib/pgsql/10/data/pg_hba.conf
将IPv4区下的127.0.0.1/32
修改为0.0.0.0/0
; 将ident修改为md5
③、重启服务使设置生效
systemctl restart postgresql-10