Step 1: Add PostgreSQL Yum Repository
sudo tee /etc/yum.repos.d/pgdg.repo<<EOF
[pgdg12]
name=PostgreSQL 12 for RHEL/CentOS 7 - x86_64
baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64
enabled=1
gpgcheck=0
EOF
sudo yum makecache
Step 2: Install PostgreSQL 12
sudo yum install postgresql12 postgresql12-server
Step 3: Initialize and start database service
我们需要初始化数据库服务器以生成配置文件。这是通过调用安装脚本来完成的
$ sudo /usr/pgsql-12/bin/postgresql-12-setup initdb
Initializing database ... OK
PostgreSQL 12服务器使用/var/lib/pgsql/12/data/postgresql.conf中的配置文件。在将数据库服务器用于生产工作负载之前,您可以查看所有默认值并根据自己的喜好进行调整。
要启动并使服务能够在操作系统启动时启动,请运行以下命令:
sudo systemctl enable --now postgresql-12