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 (includespsql).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 update2. Install PostgreSQL Packages
To install PostgreSQL client tools (including psql) and the server:
sudo dnf install postgresql-server postgresql-contrib3. Enable and Start PostgreSQL
Enable PostgreSQL so it starts automatically at boot, and start it now:
sudo systemctl enable postgresqlThe 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 postgresqlTo start the PostgreSQL server manually, run
sudo systemctl start postgresqlUser 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 psqlFrom 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 postgresPress 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