Installing PostgreSQL 12 with PostGIS on Rocky Linux 9
Enable the CRB and EPEL repositories, then add the official PostgreSQL YUM repositroy:
dnf install 'dnf-command(config-manager)' -y
dnf config-manager --set-enabled crb
dnf install -y epel-release
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Disable the built-in PostgreSQL module to avoid conflicts:
dnf -qy module disable postgresql
List available versoins of PostgreSQL 12 and PostGIS 3.0 for PostgreSQL 12:
dnf list postgresql12 --showduplicates | sort -r
dnf list postgis30_12 --showduplicates | sort -r
Install specific versions of PostgreSQL 12 and PostGIS:
dnf install -y \
postgresql12-12.9-2PGDG.rhel9 \
postgresql12-libs-12.9-2PGDG.rhel9 \
postgresql12-server-12.9-2PGDG.rhel9 \
postgresql12-contrib-12.9-2PGDG.rhel9 \
postgis30_12-3.0.5-1.rhel9
Initialize the database cluster:
/usr/pgsql-12/bin/postgresql-12-setup initdb
Adjust PostgreSQL configuration files:
In /var/lib/pgsql/12/data/postgresql.conf, set:
listen_addresses = '*'
In /var/lib/pgsql/12/data/pg_hba.conf, append:
host all all 0.0.0.0/0 md5
Start and enable the PostgreSQL service:
systemctl enable --now postgresql-12
Perform initial database setup as the postgres user:
su - postgres
# Create a new user
createuser appuser
# Set password for the user
psql -c "ALTER USER appuser WITH PASSWORD 'securepass';"
# Create a database owned by the new user
createdb geodb -O appuser
Verify connectivity and explore the database:
# Connect remotely (replace IP accordingly)
psql -h 10.10.10.10 -d geodb -U appuser
# List users
psql -c "SELECT usename FROM pg_user;"
# List databases
psql -l
# Restore from SQL dump
psql -d geodb -U postgres -f dump.sql
# Interactive session
psql geodb
geodb=> \du -- list roles
geodb=> \dt -- list tables
geodb=> \q -- quit
# Drop database if needed
dropdb geodb