PostgreSQL is a powerful object-relational database system that uses and extends the SQL language, combined with many features that securely store and scale the most complex data tasks. The origins of PostgreSQL date back to 1986 as part of the POSTGRES project at the University of California, Berkeley, and it has over 30 years of active development on the core platform.

Installation

Before installation, we will update the system/server. All commands are run by the root user.

sudo su -
apt update && apt upgrade && apt full-upgrade

After which we will install PostgreSQL, the version provided by the Debian/Ubuntu repository:

apt install postgresql-common

We will run the script that will configure the package source because Ubuntu 22.04 has PostgreSQL version 14 in its distribution; personally, I want to use version 15 of PostgreSQL, even though version 16 is stable at this moment (to avoid potential issues with other applications/services if I use a version that is too old or too new). Thus, I also have the possibility to install different versions of PostgreSQL if the need arises:

sh /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh

We are installing version 15 of PostgreSQL:

apt install postgresql-15

We assign a password to the postgres user:

su - postgres

We connect to the database postgres

psql

ALTER USER postgres PASSWORD 'myP@ssw0rd';

We verify with the new credentials that we can connect to the local server:

psql -h localhost -U postgres -d postgres

If we try to access the database from outside the machine (server), we will not succeed because we have not set any rules in the ufw firewall; for now, I do not wish for it to be accessible from the outside: