How to Install PostgreSQL 12 on CentOS 7 and CentOS 8
This step‑by‑step guide explains how to add the PostgreSQL Yum repository, install PostgreSQL 12 client and server packages, initialize and start the database service, set the admin password, optionally enable remote access, and install the pgAdmin 4 web interface on CentOS 7 or 8 systems.
This guide walks through installing PostgreSQL 12 on CentOS 7 or CentOS 8, covering repository setup, package installation, database initialization, service start‑up, admin password configuration, optional remote access, and pgAdmin 4 installation.
Step 1: Add PostgreSQL Yum Repository
PostgreSQL Yum repository integrates with the system package manager and provides automatic updates for supported PostgreSQL versions.
For CentOS 8 run:
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpmFor CentOS 7 run:
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpmVerify the repository package with:
rpm -qi pgdg-redhat-repoStep 2: Install PostgreSQL 12
CentOS 8
Disable the built‑in PostgreSQL module and install the client and server packages:
sudo dnf -qy module disable postgresql sudo dnf -y install postgresql12 postgresql12-serverCentOS 7
Install the client and server packages directly:
sudo yum -y install epel-release yum-utils sudo yum-config-manager --enable pgdg12 sudo yum install postgresql12-server postgresql12Step 3: Initialize and Start the Database Service
Initialize the database cluster: sudo /usr/pgsql-12/bin/postgresql-12-setup initdb Enable and start the service: sudo systemctl enable --now postgresql-12 Check the service status to confirm it is running:
systemctl status postgresql-12Step 4: Set PostgreSQL Administrator Password
Change the password for the default postgres user:
sudo su - postgres -c "psql -c \"alter user postgres with password 'StrongPassword'\""Step 5: Enable Remote Access (Optional)
Edit /var/lib/pgsql/12/data/postgresql.conf and set listen_addresses to the server IP or *: listen_addresses = '192.168.10.10' Allow remote connections by editing pg_hba.conf (e.g., add host all all 0.0.0.0/0 md5 or a trusted subnet) and then restart the service:
sudo systemctl restart postgresql-12Step 6: Install pgAdmin 4 Web Interface
pgAdmin is a popular open‑source management and development platform for PostgreSQL. Follow the official instructions to install pgAdmin 4 on CentOS 7 or CentOS 8 (links provided in the original article).
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architects Research Society
A daily treasure trove for architects, expanding your view and depth. We share enterprise, business, application, data, technology, and security architecture, discuss frameworks, planning, governance, standards, and implementation, and explore emerging styles such as microservices, event‑driven, micro‑frontend, big data, data warehousing, IoT, and AI architecture.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
