1 进入postresql官网下载页面,提示了centos相关下载安装等信息。
https://www.postgresql.org/download/linux/redhat/

2 连接到centos7服务器

3 根据官网提示在命令行中下载安装
yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

yum install postgresql11
yum install postgresql11-server
附带安装
yum install postgresql11-libs
yum install postgresql11-contrib
yum install postgresql11-devel
4 数据库初始化与设置自启动
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11

这一步初始化数据库命令会在 /var/lib/pgsql 目录下创建名称为11文件夹,11为数据库版本,如果安装的是其他版本,对应的是其版本号(9.4、9.5);这里如果已经有对应版本的文件夹了,初始化这一步会报错,需要你自行去删除对应的文件夹,再去初始化。
5 默认会创建一个名为postgres的linux登录用户,这里进行密码修改
(注意,这里修改的是linux登陆的账号密码,不是数据库的)
passwd postgres

6 编辑一些远程连接信息,让所有计算机能访问到该测试数据库
6.1 对postgresql.conf文件进行编辑
cd var/lib/pgsql/11/data
vim postgresql.conf
修改前:

输入a进入插入编辑模式,对该文件进行编辑;
去掉#,修改localhost为*
修改后如下,按下esc退出插入编辑模式,并输入:wq保存退出

6.2同样目录下,对pg_hba.conf文件进行编辑
vim pg_hba.conf
修改前:

输入a进入插入编辑模式,对该文件进行编辑
修改后如下,按下esc退出插入编辑模式,并输入:wq保存退出

7 重新启动服务
systemctl restart postgresql-11
8 用postgres账号登录centos服务器,并修改数据库用户密码(或者直接 su postgres 切换过去)
ssh postgres@ip -p 端口
psql -U postgres
password

查看版本

9 在数据库客户端测试登录

10 备用卸载
yum remove postgresql*

前人经验参考
https://www.jianshu.com/p/3f8d77d258d8
https://www.jianshu.com/p/639ebb43bfb4
https://www.cnblogs.com/freeweb/p/8006639.html
http://www.postgresonline.com/article_pfriendly/362.html
https://www.cnblogs.com/yanmiao/p/3262306.html
作者:gis杭州
链接:https://www.jianshu.com/p/b4a759c2208f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。