PostgreSQL Setup on Fedora

Install PostgreSQL

1
sudo dnf install postgresql postgresql-server

Initialise the Database

1
sudo postgresql-setup --initdb

Enable and Start the Service

1
sudo systemctl enable --now postgresql

Verify Installation

1
sudo systemctl status postgresql

Create Root User for Development

Access PostgreSQL as postgres user

1
sudo -u postgres psql

Create root user with password

1
CREATE USER root WITH ENCRYPTED PASSWORD 'password' SUPERUSER CREATEDB CREATEROLE;

Create development database

1
CREATE DATABASE devdb OWNER root;

Exit

1
\q

Configure Local Access

Edit client authentication

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

Change the local connection lines to:

local   all             all                                     md5
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

Restart PostgreSQL

1
sudo systemctl restart postgresql

Connect as Root User

1
psql -U root -d devdb -h localhost

Enter password: password

Common Commands

1
2
3
4
sudo systemctl start postgresql
sudo systemctl stop postgresql
sudo systemctl restart postgresql
sudo systemctl enable postgresql

Useful psql Commands

1
2
3
4
5
\l                  -- List databases
\c dbname           -- Connect to database
\dt                 -- List tables
\du                 -- List users
\q                  -- Quit