Prerequisites
- A Rocky Linux 10 dedicated server
- Root access or a normal administrative user with sudo privileges
- Network access to the Rocky Linux package repositories
- A terminal session on the server
This tutorial focuses on a local PostgreSQL installation for a dedicated server, where you control the database daemon and its data directory directly. If you are planning follow-on database work such as application integration or backup validation, you may also find How to Install a LAMP Stack on Rocky Linux 10 and Automating PostgreSQL Backups on Linux a Guide useful after this installation is complete.
Install PostgreSQL
Install the PostgreSQL server package and client tools from the Rocky Linux 10 repositories. The server package provides the database service, and the client package provides psql for local administration and verification.
sudo dnf install -y postgresql-server postgresql
After the packages are installed, the PostgreSQL data directory exists only after initialization. The standard location on Rocky Linux is /var/lib/pgsql/data, and it is created by the initialization step rather than the package install itself.
Initialize and Start PostgreSQL
Initialize the default database cluster before enabling the service. This creates the system catalogs, configuration files, and base directory structure PostgreSQL needs to start.
sudo postgresql-setup --initdb
Start PostgreSQL and enable it at boot so the service comes back automatically after a dedicated server restart.
sudo systemctl enable --now postgresql
Confirm that the service started cleanly and is both active and enabled.
sudo systemctl status postgresql
If initialization succeeded, the default data directory should now be present at /var/lib/pgsql/data. On a dedicated server, this directory is the primary on-disk state for the instance, so it should be included in your operational checks and backup planning.
Secure the Database Server
For an initial local-only setup, secure the default postgres administrative role by opening an interactive session as the database system user. This lets you inspect the instance before making any authentication or role changes.
sudo -u postgres psql
Inside psql, you can set a password for the postgres role if your operational workflow requires password authentication for local administrative access. Use the following SQL command inside the psql prompt, then exit with \q:
ALTER USER postgres WITH PASSWORD 'your-strong-password';
If you set a password, test it locally from the dedicated server to confirm the credentials work as expected. Keep this check limited to your current access method and policy requirements.
Verify the Installation
Verify the service, database access, and initial cluster state with the following checks.
- Confirm the PostgreSQL service is active and enabled with systemd.
sudo systemctl status postgresql
- Confirm the postgres user can open
psqland list databases.
sudo -u postgres psql -c '\l'
The database list should show the standard default databases, which confirms the server is responding to local client connections.
- Confirm the installation created the default data directory successfully.
sudo ls -ld /var/lib/pgsql/data
If you set a password for the postgres role, verify that the new credentials work locally by opening a session with the authenticated method you configured and confirming you can connect without errors.
For dedicated-server operators who regularly test database recovery workflows, pairing this installation with Backup Restore Testing on Linux Dedicated Servers is a practical next step.
Troubleshooting
If PostgreSQL does not start, check the service status output first for initialization or permission errors. On Rocky Linux 10, the most common issue after installation is skipping the initialization step before enabling the service.
- If
systemctl status postgresqlreports a failed start, re-runsudo postgresql-setup --initdband then start the service again. - If
sudo -u postgres psql -c '\l'fails, confirm the service is running and that the local data directory exists at/var/lib/pgsql/data. - If you changed the
postgrespassword and cannot connect locally, repeat the password change from an authenticatedpsqlsession and retest immediately.
These checks are sufficient for the installation path covered here and help isolate whether the issue is package installation, cluster initialization, or local authentication.
Rollback
If you need to remove the installation and return the server to a pre-PostgreSQL state, stop using the database service, remove the packages, and delete the initialized data directory.
sudo dnf remove -y postgresql-server postgresql
sudo rm -rf /var/lib/pgsql/data
This rollback removes the software and the initialized cluster data created during setup. Use it only if you are intentionally discarding the local database instance on the dedicated server.
Conclusion
You have now installed PostgreSQL on Rocky Linux 10, initialized the default database cluster, started and enabled the service, and verified that psql can list databases from the local postgres account. You can also confirm that the default data directory was created successfully and, if configured, that the postgres role credentials work locally as intended.

