How to Install PostgreSQL (psql) on Fedora Linux

Spread the love

PostgreSQL is a powerful, open-source relational database system widely used for web apps, data analytics, and backend services. On Fedora, installing and setting up PostgreSQL — including the command-line client psql — is straightforward thanks to Fedora’s package management system.

What You’ll Install

  • postgresql – the PostgreSQL client tools (includes psql).
  • postgresql-server – the database server.
  • postgresql-contrib (optional) – extra modules and extensions.

1. Update Fedora Package Index

Before installing any new software, update your system so you get the latest packages and security fixes:

sudo dnf update

2. Install PostgreSQL Packages

To install PostgreSQL client tools (including psql) and the server:

sudo dnf install postgresql-server postgresql-contrib

3. Enable and Start PostgreSQL

Enable PostgreSQL so it starts automatically at boot, and start it now:

sudo systemctl enable postgresql

The database needs to be populated with initial data after installation. The database initialisation could be done using the following command. It creates the configuration files postgresql.conf and pg_hba.conf

sudo postgresql-setup --initdb --unit postgresql

To start the PostgreSQL server manually, run

sudo systemctl start postgresql

User Creation and Database Creation

Now you need to create a user and a database for the user. This needs to be run from a postgres user account on your system.

sudo -u postgres psql

From here, you can create a PostgreSQL user and database. Here, we will assume your computer’s user account is called lenny. Note: you can also run this from the shell as well with createuser lenny and createdb --owner=lenny carl.

postgres=# CREATE USER lenny WITH PASSWORD 'leonard';
postgres=# CREATE DATABASE my_project OWNER lenny;

It might be a good idea to add a password for the postgres user while you’re at it:

postgres=# \password postgres

Press Ctrl + D or \q to leave the psql session running as the user postgres. Now you can access your new database from your user account (lenny) and start using it.

psql my_project
Scroll to Top