This video will show you the completed steps to install PostgreSQL 14 in Rocky Linux 8.6.
It's including changing the default PGDATA directory, automate startup/shutdown database and open firewall.
You can also install on others Rehat family linux such as Rehat enterprise 8, Oracle Linux 8 or CentOS 8.
Installation steps:
############################
## Login as root ##
############################
## 0. Create group and user: postgres
# groupadd -g 5000 postgres
# useradd -u 5000 -g 5000 -c "PostgreSQL Database" postgres
useradd -u 5000 -c "PostgreSQL Database" postgres
## 1. Install postgresql software
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install -y postgresql14-server
## 2. Create PGDATA directory
mkdir -p /pgsql/data
chown -R postgres.postgres /pgsql
############################
## Login as Postgres ##
############################
## 3. Setup postgres evironment variable
PGDATA=/pgsql/data
PATH=$PATH:/usr/pgsql-14/bin
## 4. Initialize & startup database
initdb
pg_ctl start | stop
psql
############################
## Login as root ##
############################
## 5. Auto-startup
vi /usr/lib/systemd/system/postgresql-14.service
systemctl daemon-reload
systemctl enable postgresql-14
systemctl start postgresql-14
## 6. Open firewall
#firewall-cmd --zone=public --add-port=5432/tcp
firewall-cmd --add-service=postgresql
firewall-cmd --runtime-to-permanent
## All done