安装
Install the repository RPM:
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/pgdg-centos11-11-2.noarch.rpm
Install the client packages:
yum install postgresql11
Optionally install the server packages:
yum install postgresql11-server
Optionally initialize the database and enable automatic start:
service postgresql-11 initdb
chkconfig postgresql-11 on
service postgresql-11 start
#初始化数据库
#如果需要重新初始化,删除目录/var/lib/pgsql/11/data/即可
service postgresql-11 initdb
#服务开机启动
chkconfig postgresql-11 on
#启动服务
service postgresql-11 start
修改用户密码
su - postgres 切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD 'postgres' 设置postgres用户密码为postgres \q 退出数据库
开启远程访问
vi /var/lib/pgsql/11/data/postgresql.conf 修改#listen_addresses = 'localhost' 为 listen_addresses='*' 当然,此处‘*’也可以改为任何你想开放的服务器IP
信任远程连接
vi /var/lib/pgsql/11/data/pg_hba.conf 修改如下内容,信任指定服务器连接 # IPv4 local connections: host all all 127.0.0.1/32 trust host all all 192.168.157.1/32(需要连接的服务器IP) trust
重启服务
service postgresql-11 restart