Learn how to install PostgreSQL on CentOS 7 with our step-by-step guide. Set up and configure your database server efficiently with easy-to-follow instructions. #centlinux #linux #postgres
Table of Contents
What is PostgreSQL?
PostgreSQL (or Postgres) is a free and open-source, relational database management system (RDBMS) emphazing on extensibility and technical standards compliance. PostgreSQL is developed by the PostgreSQL Global Development Group. It is the default database for MacOS server but also available for other platforms.
pgAdmin is the most popular open source and feature enrich web interface for administration of PostgreSQL database servers. Currently pgAdmin 4 has been released and available via PostgreSQL yum repository.

Read Also: Install PostgreSQL on Rocky Linux 9
Linux Server Specification
We have configured a CentOS 7 virtual machine with following specifications.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – CentOS 7.6
- Hostname – postgresql-01.example.com
- IP Address – 192.168.116.184/24
If you’re serious about mastering databases and want to level up your skills, I highly recommend “SQL and PostgreSQL: The Complete Developer’s Guide” by Stephen Grider. This course takes you from the fundamentals of SQL to advanced PostgreSQL concepts, helping you write efficient queries, design robust databases, and build applications that scale.
Whether you’re a beginner exploring databases for the first time or a developer looking to strengthen your backend expertise, this course provides practical, hands-on knowledge you can apply right away. Enroll now through my affiliate link and start building real-world skills that will give you a competitive edge in your career.
Disclosure: This post contains affiliate links. If you purchase through these links, I may earn a small commission at no extra cost to you, which helps support this site.
Install PostgreSQL on CentOS 7
Connect with postgresql-01.example.com using ssh as root user.
In CentOS 7.6, PostgreSQL 9.2 is available in standard yum repositories.
But we are required to install latest version of PostgreSQL i.e. 11. Therefore, we have to add PostgreSQL yum repository in our CentOS 7 server and then we will be able to install PostgreSQL 11.
Yum repositories for various Linux distros can be obtained from PostgreSQL official download page.
Install PostgreSQL yum repository using following command.
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpmDisable old version PostgreSQL yum repositories.
yum-config-manager --disable pgdg10 pgdg94 pgdg95 pgdg96Build cache for yum repositories.
yum makecache fastOutput:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp3.isra.edu.pk
* extras: ftp3.isra.edu.pk
* updates: ftp3.isra.edu.pk
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
pgdg11 | 3.6 kB 00:00
updates | 3.4 kB 00:00
Metadata Cache Created
Install PostgreSQL on CentOS 7 by using yum command.
yum install -y postgresql11 postgresql11-serverInitialize PostgreSQL database instance as follows.
/usr/pgsql-11/bin/postgresql-11-setup initdbOutput:
Initializing database ... OK
Enable and start PostgreSQL service.
systemctl enable postgresql-11.service
systemctl start postgresql-11.serviceConnect as postgres user.
su - postgresLogin to psql prompt.
psqlSet admin password.
ALTER USER postgres WITH PASSWORD '123';
qExit from postgres user.
exitPostgreSQL 11 server has been installed on our CentOS 7 server.
Configure PostgreSQL Remote Access
By default, PostgreSQL service runs locally on port 5432/tcp. However, if required we can configure it for remote access from other computers in our network.
Edit PostgreSQL configuration file.
vi /var/lib/pgsql/11/data/postgresql.confFind and set following directive in this file.
listen_addresses = '*'Allow network clients to access PostgreSQL service in pg_hba.conf file.
echo "host all all 192.168.116.0/24 md5" >> /var/lib/pgsql/11/data/pg_hba.confRestart PostgreSQL service to apply changes.
systemctl restart postgresql-11.serviceAllow PostgreSQL service in Linux firewall.
firewall-cmd --permanent --add-service=postgresql
firewall-cmd --reloadOur PostgreSQL service is configured for remote access.
Apple Watch SE 3 [GPS 44mm] Smartwatch with Starlight Aluminum Case with Starlight Sport Band – M/L. Fitness and Sleep Trackers, Heart Rate Monitor, Always-On Display, Water Resistant
17% OffInstall pgAdmin4 on CentOS 7
To ease the process of Database Administration of PostgreSQL, we are installing a popular SQL web interface i.e. pgAdmin4 on our CentOS 7 server.
pgAdmin4 is available in the same PostgreSQL 11 yum repository.
But first we are installing EPEL (Extra Packages for Enterprise Linux) yum repository, because pgAdmin4 requires some packages that are available in EPEL yum repository.
yum install -y epel-releaseBuild yum cache for EPEL repository.
yum makecache fastInstall pgAdmin4 using yum command.
yum install -y pgadmin4pgAdmin4 is a python based web application, therefore it requires a web server with python language support for deployment. Luckily, pgAdmin4 automatically installs Apache HTTP server and Python language support during installation.
Enable and start Apache Service.
systemctl enable httpd.service
systemctl start httpd.serviceConfigure Linux Firewall
Allow HTTP service in Linux firewall.
firewall-cmd --permanent --add-service=http
firewall-cmd --reloadRead Also: How to Run Self-Hosted Supabase Docker Container
Configure Apache for pgAdmin4
pgAdmin4 also installed a configuration file in Apache configuration directory. Therefore, to enable pgAdmin web application, we have to rename this file to make is readable by the httpd.service.
mv /etc/httpd/conf.d/pgadmin4.conf.sample /etc/httpd/conf.d/pgadmin4.confEdit /etc/httpd/conf.d/pgadmin4.conf file and the file contents after editing should be look like as follows. (The lines in yellow has been added here).
<VirtualHost *:80>
ServerName 192.168.116.184
LoadModule wsgi_module modules/mod_wsgi.so
WSGIDaemonProcess pgadmin processes=1 threads=25
WSGIScriptAlias /pgadmin4 /usr/lib/python2.7/site-packages/pgadmin4-web/pgAdmin4.wsgi
<Directory /usr/lib/python2.7/site-packages/pgadmin4-web/>
WSGIProcessGroup pgadmin
WSGIApplicationGroup %{GLOBAL}
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
</VirtualHost>Define path variables in following file.
vi /usr/lib/python2.7/site-packages/pgadmin4-web/config_distro.pyAdd following settings therein.
SQLITE_PATH = '/var/lib/pgadmin/pgadmin.db'
SESSION_DB_PATH = '/var/lib/pgadmin/sessions'
STORAGE_DIR = '/var/lib/pgadmin/storage'
LOG_FILE = '/var/log/pgadmin/pgadmin.log'Adjust file permissions.
chown -R apache:apache /var/log/pgadmin/
chown -R apache:apache /var/lib/pgadmin/Set SELinux file contexts.
semanage fcontext -a -t httpd_sys_rw_content_t "/var/lib/pgadmin(/.*)?"
restorecon -R /var/lib/pgadmin/
semanage fcontext -a -t httpd_sys_rw_content_t "/var/log/pgadmin(/.*)?"
restorecon -R /var/log/pgadmin/Set SELinux boolean, so that Apache can access PostgreSQL service port.
setsebool -P httpd_can_network_connect_db 1Restart Apache service to apply changes.
systemctl restart httpd.serviceInitialize pgAdmin4 application as follows.
python /usr/lib/python2.7/site-packages/pgadmin4-web/setup.pyOutput:
NOTE: Configuring authentication for SERVER mode.
Enter the email address and password to use for the initial pgAdmin user account:
Email address: ahmer@postgresql-01.example.com
Password:
Retype password:
pgAdmin 4 - Application Initialisation
======================================
Gillette Fusion5 ProGlide Razor Refills for Men, 10 Razor Cartridges for FlexBall Razor Handle, 5-Blade Razor Blades, Precision Trimmer for Men
$42.99 ($4.30 / count) (as of November 1, 2025 22:16 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Access pgAdmin4 Web Interface
Browse URL http://postgresql-01.example.com/pgadmin4/ in client’s browser.

Login with Email and Password that we have defined in previous step.

Click on Add New Server to add our PostgreSQL database server to pgAdmin4 web interface.

Provide the necessary information as per above screenshot.
Click on Connection Tab and provide connection information as per following screenshot.

Click on Save.

Our PostgreSQL database has been added in pgAdmin4 SQL web interface.
All Document Reader & Viewer 2026
$3.99 (as of November 2, 2025 20:36 GMT +00:00 – More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Final Thoughts
Installing PostgreSQL on CentOS 7 provides you with a powerful, reliable, and open-source relational database system ready for a wide range of applications. In this guide, we walked through setting up the official PostgreSQL repository, installing the server packages, initializing the database, and configuring basic security settings.
With PostgreSQL now running on your CentOS 7 server, you can start creating databases and building robust, data-driven applications. For best results, remember to perform regular backups, apply security best practices, and keep your PostgreSQL server updated.
Struggling with AWS or Linux server issues? I specialize in configuration, troubleshooting, and security to keep your systems performing at their best. Check out my Freelancer profile for details.

Leave a Reply
Please log in to post a comment.