1、创建psotgres用户
groupadd postgres
useradd -g postgres postgres
2、查看操作系统版本
cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
3、配置postgreSQL 12的yum源
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
4、安装客户端包
yum install postgresql12
5、安装服务器端包
yum install postgresql12-server
#目录说明
启动日志目录【/var/lib/pgsql/12】
数据目录是【/var/lib/pgsql/12/data】
二进制目录是【/usr/pgsql-12/bin/】
6、初始化数据库和设置自启动服务
#初始化
/usr/pgsql-12/bin/postgresql-12-setup initdb
Initializing database ... OK
#启动PostgreSQL
systemctl start postgresql-12.service
7、设置环境变量
vim /etc/profile
PG_BIN=/usr/pgsql-12/bin
export PG_BIN
8、测试
#切换到postgres用户
su - postgres
#执行psql
[postgres@YZX-RD-37 ~]$ psql
psql (12.6)
Type "help" for help.
postgres=#
#查看版本信息
postgres=# SELECT version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 12.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)
至此,CentOS7 单机版PostgreSQL部署完成
参考连接:https://www.cnblogs.com/zhangshengdong/p/12502227.html