Installing postgres (PostgreSQL) database on Ubuntu 22


sudo apt update
sudo apt upgrade
sudo apt install postgresql postgresql-contrib postgresql-client-common

Start PostgreSQL service:

sudo systemctl start postgresql.service


Switch to postgres account; the installation of PostgreSQL automatically created a user account named “postgres”. Switch to this account for accessing the PostgreSQL database:

sudo -i -u postgres

Create new role

createuser --interactive

Create database

createdb exampledatabasename

Create a new Linux user

sudo adduser exampleusername

Switch to your user

sudo -i -u exampleusername

Connect to database


Check connection information


Distilled from How to Install and Set up PostgreSQL Database on Ubuntu 22.04 on Linux Hint. For more details:

PostgreSQL/postgres cheat-sheet: