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
From our partners:

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.
// FORMAT
$ sudo nano /etc/postgresql/{sql-version}/main/postgresql.conf
// SAMPLE
$ 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Â
