一、centos8 postgreSQL12 安装


1、添加RPM仓库

dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2、 Disable the built-in PostgreSQL module:

dnf -qy module disable postgresql

3、安装 PostgreSQL

dnf install postgresql12-server

4、初始化数据库并设置开机自动启动

/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

二、设置postgresql登陆密码

5、命令行进入 postgres
5.1、首先切换用户

su - postgres


5.2、链接登陆

psql -U postgres


5.3、修改密码

\password


然后输入两次密码则设置成功

三、设置远程链接

6.1、修改文件  pg_hba.conf

vim /var/lib/pgsql/12/data/pg_hba.conf


修改ip如下,注释原来的,添加新的
# IPv4 local connections:

#host    all             all             127.0.0.1/32            ident
host    all             all             0.0.0.0/0                md5

6.2、修改文件postgresql.conf

vim /var/lib/pgsql/12/data/postgresql.conf


listen_addresses = 'localhost'


 修改为

listen_addresses = '*'


 并把注释打开
 
6.3、重启服务

 systemctl restart postgresql-12.service

四、尝试远程密码登陆

psql -h 192.168.1.7 -U postgres 


输入密码链接成功

 

最后修改于 2020-07-30 11:53:55
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇