How-To: Install And Configure PostgreSQL On Ubuntu 22.04

Image: Vecteezy and Wikimedia commons

This guide contains instructions on how to install and do basic configuration of  PostgreSQL on a Ubuntu 22.04 machine.

Install via APT package

01. Open a terminal window

02. Update the package repository list

$ sudo apt update

03. Install PostgreSQL via APT package manager. Enter y when asked to confirm.

$ sudo apt install postgresql postgresql-contrib

04. Change to the postgres user account. This user has been added during the installation of PostgreSQL in the previous step.

$ sudo -i -u postgres

05. Access the psql shell

$ psql

06. Verify that installed correctly by showing the built-in PostgreSQL system tables.

postgres=# SELECT * FROM pg_catalog.pg_tables;

Press q to exit from the listing of sql tables.

07. Exit from the psql session 

postgres=# \q

And exit from the postgres user.

postgres@box: ~$ exit

Accept database connection from anywhere 

WARNING: Use only in development environment, this poses a security concern when applied in a production environment

01. Edit the postgre config located at /etc/postgresql/<sql-version>/main/postgresql.conf. At the time of this writing the stable version of PostgreSQL is 14.

$ sudo nano /etc/postgresql/{sql-version}/main/postgresql.conf

$ sudo nano /etc/postgresql/14/main/postgresql.conf

localhost is the default value, which means it can only be accessed locally from the server. And not remotely.

02. Set to asterisk, *, to make it accessible anywhere, then save the changes.

03. Restart the PostgreSQL service to apply the changes in config.

$ sudo service postgresql restart

04. Check the status of the PostgreSQL service. It should be active

$ sudo service postgresql status

Uninstall PostgreSQL

$ sudo apt remove postgresql postgresql-contribĀ 

For enquiries, product placements, sponsorships, and collaborations, connect with us at We'd love to hear from you!