Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Installing PostgreSQL 12 with PostGIS on Rocky Linux 9

Tech May 8 3

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

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.