Database Server SetupLinux Server Setup

Complete Guide to Installing and Configuring PostgreSQL 14 on Fedora Linux

PostgreSQL 14 is a powerful, open-source relational database system renowned for its reliability, performance enhancements, and advanced features like incremental sorting, improved parallelism, and extensive JSON support. Fedora users seeking a robust database solution benefit from installing PostgreSQL 14 using the official PostgreSQL Global Development Group (PGDG) repository for timely updates and feature stability. This comprehensive tutorial walks you through the complete process of installing PostgreSQL 14 on a Fedora system, from repository setup and package installation to initial configuration, user management, remote access, firewall integration, SELinux settings, and troubleshooting. By following this guide, Fedora administrators and developers can deploy PostgreSQL 14 optimized for secure and efficient operation in production environments or development setups.

Why Choose PostgreSQL 14 on Fedora Using the PGDG Repository?

Fedora offers PostgreSQL packages in its default repositories; however, the version may lag behind or differ from your specific requirements. The PostgreSQL Global Development Group (PGDG) maintains dedicated YUM repositories that provide the latest supported PostgreSQL major versions along with prompt security updates, allowing better control over the installed version. This is particularly important for systems requiring PostgreSQL 14’s enhancements. Opting for the PGDG repo ensures access to the latest patches, official documentation packages, and additional modules, leading to a maintainable and secure database installation on any Fedora release.

Step 1: Update Fedora System Packages

Always begin by updating your Fedora system to guarantee all installed packages are current, minimizing compatibility issues. Refreshing package metadata ensures fresh repository information before PostgreSQL installation.

sudo dnf upgrade --refresh

Last metadata expiration check: 0:05:12 ago on Tue 30 Dec 2025 11:00:00 AM UTC. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Upgrading: bash x86_64 5.1.8-2.fc36 updates 1.2 M Upgraded 1 Package Total download size: 1.2 M Downloading Packages: bash-5.1.8-2.fc36.x86_64.rpm 981 kB/s | 1.2 MB 00:01 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Summary upgrade Completed!

The dnf upgrade –refresh command updates all packages on the system while forcing DNF to re-download repository metadata (with –refresh), ensuring you have the latest package metadata to avoid stale cache issues during PostgreSQL installation.

Step 2: Import and Configure PostgreSQL PGDG Repository

Add the official PostgreSQL repository to your Fedora configuration to access PostgreSQL 14 packages and receive updates directly from the PGDG.

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-$(rpm -E %fedora)-x86_64/pgdg-fedora-repo-latest.noarch.rpm

Installing: pgdg-fedora-repo noarch 42.0-43PGDG @commandline 15.7 KiB Transaction Summary: Installing: 1 Package Complete!

This command downloads and installs the repository configuration appropriate for your Fedora version (automatically resolved by $(rpm -E %fedora)). Installing this package adds PGDG repository files and imports the associated GPG keys for package verification.

Step 3: Install PostgreSQL 14 Server and Optional Packages

With the repository configured, install the PostgreSQL 14 server and documentation. For development or extended features, additional packages are also available.

sudo dnf install -y postgresql14-server postgresql14-docs

Installing: postgresql14-server x86_64 14.20-1PGDG.f43 pgdg14 23.3 MiB Installing dependencies: postgresql14 x86_64 14.20-1PGDG.f43 pgdg14 7.7 MiB postgresql14-libs x86_64 14.20-1PGDG.f43 pgdg14 918.6 KiB Complete!

This installs core PostgreSQL binaries, client tools, and documentation. To expand PostgreSQL’s capabilities, install development libraries and procedural language extensions as needed:

sudo dnf install -y postgresql14-devel postgresql14-contrib postgresql14-plperl postgresql14-plpython3 postgresql14-pltcl

Installed: postgresql14-devel.x86_64 14.20-1PGDG.f43 postgresql14-contrib.x86_64 14.20-1PGDG.f43 postgresql14-plperl.x86_64 14.20-1PGDG.f43 postgresql14-plpython3.x86_64 14.20-1PGDG.f43 postgresql14-pltcl.x86_64 14.20-1PGDG.f43 Transaction Summary: Installed: 5 Packages Complete!

The devel package is essential for compiling PostgreSQL extensions, while contrib and language extensions provide extra modules and support for Perl, Python 3, and Tcl stored procedures.

Step 4: Initialize the PostgreSQL Database Cluster

Initialize the database storage area and system catalogs before starting PostgreSQL.

sudo /usr/pgsql-14/bin/postgresql-14-setup initdb

Initializing database ... OK

This command sets up the PostgreSQL data directory at /var/lib/pgsql/14/data/ with correct permissions and initial configuration, which is mandatory before running the database server.

Step 5: Enable and Start PostgreSQL Service

Start the PostgreSQL 14 server and configure it to launch automatically on system boot:

sudo systemctl enable postgresql-14 --now

Created symlink /etc/systemd/system/multi-user.target.wants/postgresql-14.service → /usr/lib/systemd/system/postgresql-14.service.

The –now option enables and starts the service immediately. Verify status with:

systemctl status postgresql-14

● postgresql-14.service - PostgreSQL 14 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-14.service; enabled; vendor preset: disabled) Active: active (running) since Tue 30 Dec 2025 11:30:00 UTC Main PID: 28473 (postmaster) Tasks: 8 Memory: 32.0M CPU: 150ms

The output confirms the server is actively running and ready for connections.

Step 6: Verify PostgreSQL 14 Installation

Check the installed PostgreSQL client version to ensure correct software deployment:

/usr/pgsql-14/bin/psql --version

psql (PostgreSQL) 14.20

This output confirms the psql client corresponds to PostgreSQL version 14.20, matching the installed server.

Step 7: Access and Manage PostgreSQL Database

Access PostgreSQL as the administrative postgres system user:

sudo -u postgres psql

psql (14.20) Type "help" for help. postgres=#

This opens an interactive SQL shell with superuser privileges for database management. Exit with \q.

Alternatively, switch to the postgres user shell first:

sudo -i -u postgres

[postgres@fedora ~]$ psql

psql (14.20) postgres=#

This workflow is useful for running multiple commands in a session.

Step 8: Create PostgreSQL Users and Databases

For secure, production-ready deployments, create dedicated database users and databases instead of using the superuser role.

Create a user:

sudo -u postgres createuser myappuser

Create a database:

sudo -u postgres createdb myappdb

Assign privileges granting full ownership:

sudo -u postgres psql

postgres=# GRANT ALL PRIVILEGES ON DATABASE myappdb TO myappuser;

GRANT

postgres=# ALTER USER myappuser WITH ENCRYPTED PASSWORD 'your_secure_password';

ALTER ROLE

postgres=# \q

Always choose strong encrypted passwords and assign permissions tailored to your application’s needs.

Step 9: Configure Firewall to Allow PostgreSQL Connections

Fedora commonly uses firewalld to manage network packet filtering. Storing PostgreSQL behind a firewall zone reduces exposure to unauthorized access.

sudo firewall-cmd --permanent --new-zone=postgres

Create a custom firewall zone named postgres to organize rules.

sudo firewall-cmd --permanent --zone=postgres --add-source=192.168.1.0/24

Allow trusted network ranges only (adjust subnet as appropriate).

sudo firewall-cmd --permanent --zone=postgres --add-port=5432/tcp

Open the default PostgreSQL port (5432) for the zone.

sudo firewall-cmd --reload

Apply and activate the changes.

sudo firewall-cmd --list-all --zone=postgres

postgres target: default icmp-block-inversion: no interfaces: sources: 192.168.1.0/24 services: ports: 5432/tcp protocols: forward: no masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:

Verifies active firewall configuration including allowed sources and open ports.

Step 10: Enable Remote Access to PostgreSQL

By default, PostgreSQL listens only on localhost. Configure listen_addresses and client authentication to allow external connections.

Edit the main configuration file:

sudo nano /var/lib/pgsql/14/data/postgresql.conf

Locate the listen_addresses parameter and set it to one of the following depending on your environment:

listen_addresses = '*' – listen on all interfaces (less restrictive)

listen_addresses = '192.168.1.50' – listen on specific IP (more secure)

Save and exit.

Edit client authentication:

sudo nano /var/lib/pgsql/14/data/pg_hba.conf

Add the following lines to allow secure password authentication from trusted networks:

host myappdb myappuser 192.168.1.100/32 scram-sha-256

host all all 192.168.1.0/24 scram-sha-256

Ensure you always use scram-sha-256 for modern password security. Avoid the trust method for remote access.

Restart PostgreSQL to apply changes:

sudo systemctl restart postgresql-14

Confirm PostgreSQL is listening on the desired interfaces:

ss -tlnp | grep 5432

LISTEN 0 100 0.0.0.0:5432 0.0.0.0:* users:(("postmaster",pid=28473,fd=6)) LISTEN 0 100 [::]:5432 [::]:* users:(("postmaster",pid=28473,fd=7))

The output indicates PostgreSQL is accepting TCP connections on all IPv4 and IPv6 addresses.

Step 11: Configure SELinux for PostgreSQL Operation

Fedora’s default SELinux policy enforces strong access controls that can block PostgreSQL operations or prevent web servers from accessing the database.

Check SELinux status:

sestatus

SELinux status: enabled Current mode: enforcing

This confirms SELinux is active and enforcing restrictions.

Restore file contexts on the data directory to prevent permission errors:

sudo restorecon -Rv /var/lib/pgsql/14/data/

Relabeled /var/lib/pgsql/14/data/pgsql.conf from unconfined_u:object_r:default_t:s0 to system_u:object_r:postgresql_db_t:s0 ...

This command recursively resets SELinux labels on PostgreSQL data files.

If your web server needs to connect to PostgreSQL over the network, enable the boolean allowing HTTPD network database access:

sudo setsebool -P httpd_can_network_connect_db 1

This change persists across reboots and prevents common SELinux denials.

To analyze SELinux denial logs for troubleshooting:

sudo ausearch -m avc -ts recent | grep postgres

type=AVC msg=audit(1672449600.123:456): avc: denied { name_connect } for pid=1234 comm="postmaster" dest=5432 scontext=system_u:system_r:postgresql_t:s0 tcontext=system_u:system_r:unreserved_port_t:s0

Installing the audit package may be necessary to use ausearch.

Step 12: Troubleshoot Common PostgreSQL Issues

If the PostgreSQL service does not start, inspect detailed logs:

sudo journalctl -xeu postgresql-14

Dec 30 11:45:00 fedora systemd[1]: postgresql-14.service: Main process exited, code=exited, status=1/FAILURE Dec 30 11:45:00 fedora systemd[1]: postgresql-14.service: Failed with result 'exit-code'.

Common causes include uninitialized data directories or permission issues.

Ensure data directory ownership is correct:

sudo chown -R postgres:postgres /var/lib/pgsql/14/data/

For connection refusals from remote hosts, verify:

  • PostgreSQL listens on the requested IP (ss -tlnp | grep 5432)
  • Firewall rules allow incoming traffic (firewall-cmd --list-all --zone=postgres)
  • pg_hba.conf contains appropriate authentication entries

For authentication errors, reset user passwords and confirm authentication mechanisms in pg_hba.conf align with password encryption:

sudo -u postgres psql -c "ALTER USER myappuser WITH ENCRYPTED PASSWORD 'new_strong_password';"

ALTER ROLE

Step 13: Removing PostgreSQL 14 from Fedora

If PostgreSQL 14 is no longer needed, perform a clean uninstall to remove software, data, and repositories.

Stop and disable the service:

sudo systemctl disable postgresql-14 --now

Removed symlink /etc/systemd/system/multi-user.target.wants/postgresql-14.service.

Uninstall PostgreSQL packages:

sudo dnf remove postgresql14*

Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: postgresql14-server x86_64 14.20-1PGDG.f43 pgdg14 23.3 MiB Removing unused dependencies: postgresql14-libs x86_64 14.20-1PGDG.f43 pgdg14 918.6 KiB Complete!

Remove the PGDG repository configuration:

sudo dnf remove pgdg-fedora-repo

Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: pgdg-fedora-repo noarch 42.0-43PGDG @commandline 15.7 KiB Complete!

Finally, after backing up necessary data, delete the database cluster files:

sudo rm -rf /var/lib/pgsql/14/

This action permanently deletes all PostgreSQL 14 databases. Confirm removal:

rpm -qa | grep postgresql14

No output indicates a successful removal.

Conclusion

By carefully following this detailed guide, you have successfully installed PostgreSQL 14 on Fedora using the PGDG repository, ensuring access to the most current patches and features. Your PostgreSQL database is initialized, secured with proper user roles and passwords, and configured for local and remote access with firewall and SELinux settings optimized for Fedora’s security model. This setup is ready for production workloads and scalable deployments. To further enhance your PostgreSQL installation, consider implementing regular backups, query performance monitoring with tools such as pg_stat_statements, and exploring advanced configuration options provided in the official PostgreSQL 14 documentation. Pairing PostgreSQL with web servers like Nginx offers a complete backend framework for modern web applications on Fedora Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *