Installing postgres (PostgreSQL) database on Ubuntu 22

Installation:

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

Start PostgreSQL service:

sudo systemctl start postgresql.service

Setup

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

psql

Check connection information

\conninfo

Distilled from How to Install and Set up PostgreSQL Database on Ubuntu 22.04 on Linux Hint. For more details:
https://linuxhint.com/install-and-setup-postgresql-database-ubuntu-22-04/

PostgreSQL/postgres cheat-sheet: postgres-cheatsheet.md
https://gist.github.com/Kartones/dd3ff5ec5ea238d4c546