PostgreSQL is a powerful open-source relational database system known for reliability, data integrity, and an extensive feature set. It handles workloads ranging from single-machine applications to large data warehouses with many concurrent users.
This guide walks through installing PostgreSQL 17 on Fedora 42 and Fedora 41 using the official PostgreSQL Global Development Group (PGDG) repository. We cover repository setup, server installation, database initialization, remote access configuration, firewall rules, and creating your first database and user. PostgreSQL 17.9 is the latest minor release at the time of writing – see the official PostgreSQL 17 documentation for a full feature overview.
Prerequisites
- A server or workstation running Fedora 42 or Fedora 41
- Root or sudo access
- At least 1 GB RAM (2 GB+ recommended for production)
- Port 5432/TCP open if you need remote client connections
Step 1: Install the PGDG Repository on Fedora
Fedora ships with an older PostgreSQL version in its default repositories. To get PostgreSQL 17, install the official PGDG repository RPM and disable the built-in PostgreSQL module.
Install the PGDG repository package:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-$(rpm -E %fedora)-x86_64/pgdg-fedora-repo-latest.noarch.rpm
This command auto-detects your Fedora version and installs the matching repository configuration. Next, disable the built-in PostgreSQL module so it does not conflict with PGDG packages:
sudo dnf -qy module disable postgresql
If you get a message saying the module is not found, that is fine – Fedora 42 may not ship it as a module. The command is safe to run regardless.
Step 2: Install PostgreSQL 17 Server on Fedora
With the PGDG repository enabled, install the PostgreSQL 17 server and contrib packages:
sudo dnf install -y postgresql17-server postgresql17-contrib
The postgresql17-contrib package adds useful extensions like pg_stat_statements, pgcrypto, and hstore that you will likely need in production.
Verify the installed version:
/usr/pgsql-17/bin/psql --version
The output confirms PostgreSQL 17 is installed:
psql (PostgreSQL) 17.9
Step 3: Initialize the PostgreSQL Database
PostgreSQL requires a one-time database cluster initialization before it can start. Run the setup script that comes with the PGDG package:
sudo /usr/pgsql-17/bin/postgresql-17-setup initdb
You should see a confirmation that initialization succeeded:
Initializing database ... OK
This creates the data directory at /var/lib/pgsql/17/data/ with the default configuration files and system catalogs.
Step 4: Start and Enable PostgreSQL Service
Enable the PostgreSQL service to start automatically on boot, then start it:
sudo systemctl enable --now postgresql-17
Check that the service is running:
sudo systemctl status postgresql-17
The output should show the service as active (running) with the data directory path:
● postgresql-17.service - PostgreSQL 17 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-17.service; enabled; preset: disabled)
Active: active (running)
Docs: https://www.postgresql.org/docs/17/static/
Process: 12345 ExecStartPre=/usr/pgsql-17/bin/postgresql-17-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 12346 (postmaster)
Tasks: 7 (limit: 4667)
Memory: 18.2M
CPU: 52ms
CGroup: /system.slice/postgresql-17.service
├─12346 /usr/pgsql-17/bin/postmaster -D /var/lib/pgsql/17/data/
Step 5: Configure PostgreSQL 17 for Remote Access
By default, PostgreSQL only listens on localhost and rejects remote connections. To allow clients on your network to connect, you need to edit two configuration files. If you are managing databases with a GUI tool like pgAdmin 4 on Fedora, remote access is required.
Configure listen_addresses in postgresql.conf
Open the main PostgreSQL configuration file:
sudo vi /var/lib/pgsql/17/data/postgresql.conf
Find the listen_addresses line (around line 60) and change it to listen on all interfaces, or specify particular IP addresses:
# Listen on all interfaces (use specific IPs in production for tighter security)
listen_addresses = '*'
# Default port - change only if running multiple instances
port = 5432
Configure client authentication in pg_hba.conf
The pg_hba.conf file controls which hosts can connect, which databases they can access, and what authentication method is used. For details on all available options, see the PostgreSQL pg_hba.conf documentation.
Open the file:
sudo vi /var/lib/pgsql/17/data/pg_hba.conf
Add a line at the end to allow password-based connections from your network. Replace the subnet with your actual network range:
# Allow connections from the local network using scram-sha-256 authentication
# TYPE DATABASE USER ADDRESS METHOD
host all all 10.0.1.0/24 scram-sha-256
To allow connections from any IP address (not recommended for production without SSL):
host all all 0.0.0.0/0 scram-sha-256
After editing both files, restart PostgreSQL to apply the changes:
sudo systemctl restart postgresql-17
For production deployments, consider enabling SSL encryption and SCRAM-SHA-256 authentication in PostgreSQL to secure connections between clients and the server.
Step 6: Configure Firewall for PostgreSQL
Fedora uses firewalld by default. Open port 5432/TCP to allow remote database connections:
sudo firewall-cmd --permanent --add-service=postgresql
sudo firewall-cmd --reload
Verify the rule was added:
sudo firewall-cmd --list-services
The output should include postgresql in the list of allowed services:
cockpit dhcpv6-client postgresql ssh
Step 7: Create a PostgreSQL Database and User
Switch to the postgres system user, which was created during installation:
sudo -i -u postgres
Launch the PostgreSQL interactive terminal:
psql
You are now connected to the PostgreSQL shell. Create a new user (role) with a strong password:
CREATE USER appuser WITH PASSWORD 'StrongPassword123!';
CREATE DATABASE appdb OWNER appuser;
GRANT ALL PRIVILEGES ON DATABASE appdb TO appuser;
Verify the database and user were created:
\l
The database list should include your new appdb database owned by appuser:
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+-------------+-------------+--------+-----------+-----------------------
appdb | appuser | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
postgres | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
template0 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
Exit the psql shell and return to your regular user:
\q
exit
Step 8: Test Remote Database Connection
From a remote machine that has the PostgreSQL client installed, test the connection using the server IP address:
psql -h 10.0.1.50 -U appuser -d appdb
Replace 10.0.1.50 with your PostgreSQL server’s actual IP address. If the connection succeeds, you will see the psql prompt showing the database name:
Password for user appuser:
psql (17.9)
Type "help" for help.
appdb=>
If the connection fails, check that the firewall port is open, listen_addresses is set correctly in postgresql.conf, and the client IP is allowed in pg_hba.conf.
Step 9: SELinux Context for Custom Data Directories (Optional)
If you move the PostgreSQL data directory to a non-default location (for example, a dedicated storage mount), SELinux will block PostgreSQL from accessing the new path. You must set the correct SELinux context on the new directory.
Suppose you want to use /data/postgresql/17/data as the data directory. First, copy the data and set ownership:
sudo systemctl stop postgresql-17
sudo rsync -av /var/lib/pgsql/17/data/ /data/postgresql/17/data/
sudo chown -R postgres:postgres /data/postgresql/17/
Set the SELinux file context so PostgreSQL can read and write to the new location:
sudo semanage fcontext -a -t postgresql_db_t "/data/postgresql(/.*)?"
sudo restorecon -Rv /data/postgresql/
The semanage command requires the policycoreutils-python-utils package. Install it if not already present:
sudo dnf install -y policycoreutils-python-utils
Update the systemd service to point to the new data directory by editing the service override:
sudo systemctl edit postgresql-17
Add the following content to override the default data directory path:
[Service]
Environment=PGDATA=/data/postgresql/17/data
Start PostgreSQL with the new data directory and verify it is running:
sudo systemctl start postgresql-17
sudo systemctl status postgresql-17
Useful PostgreSQL 17 Administration Commands
Here are common commands for managing your PostgreSQL 17 installation on Fedora. If you plan to manage multiple databases across different servers, setting up PostgreSQL streaming replication provides high availability and read scaling.
| Task | Command |
|---|---|
| Start PostgreSQL | sudo systemctl start postgresql-17 |
| Stop PostgreSQL | sudo systemctl stop postgresql-17 |
| Restart PostgreSQL | sudo systemctl restart postgresql-17 |
| Reload config without restart | sudo systemctl reload postgresql-17 |
| Check service status | sudo systemctl status postgresql-17 |
| View server logs | sudo journalctl -u postgresql-17 -f |
| Connect as postgres user | sudo -i -u postgres psql |
| List databases | sudo -i -u postgres psql -c '\l' |
| Check PostgreSQL version | /usr/pgsql-17/bin/psql --version |
| Show data directory | sudo -i -u postgres psql -c 'SHOW data_directory;' |
Conclusion
PostgreSQL 17 is now installed and running on your Fedora system with remote access configured and the firewall open for client connections. You have a working database and user ready for your application.
For production environments, enable SSL/TLS encryption for all client connections, set up automated backups with pg_basebackup or pg_dump, configure connection pooling with PgBouncer, and monitor performance using pg_stat_statements. Consider tuning shared_buffers, work_mem, and effective_cache_size in postgresql.conf based on your server’s available RAM.