Thursday, August 28, 2025

Installation of PostgreSQL

Install through apt:

[root@localhost ~]# apt update
[root@localhost ~]# apt upgrade
[root@localhost ~]# apt install postgresql
Configuration:

edit the file /etc/postgresql/15/main/pg_hba.conf replase the line

host    all         all         127.0.0.1/32          ident
with this one
host    all         all         127.0.0.1/32          md5

edit the file /etc/postgresql/15/main/postgresql.conf replase the line

#password_encryption = scram-sha-256    # scram-sha-256 or md5
with this one
password_encryption = md5
Enable and restart PostgreSQL server:
[root@localhost ~]# systemctl enable postgresql
[root@localhost ~]# systemctl restart postgresql
Logon into the PostgreSQL server:
[root@localhost ~]# su postgres
bash-4.2$ psql postgres
psql (15.12 (Debian 15.12-0+deb12u2))
Type "help" for help.

postgres=#
Create PostgreSQL user:
postgres=# CREATE USER vpnttg SUPERUSER;
CREATE ROLE
postgres=# ALTER USER vpnttg PASSWORD 'vpnttgpass';
ALTER ROLE
Check of PostgreSQL users:
postgres=# SELECT * FROM pg_shadow;
 usename  | usesysid | usecreatedb | usesuper | userepl | usebypassrls |               passwd                | valuntil | useconfig 
----------+----------+-------------+----------+---------+--------------+-------------------------------------+----------+-----------
 postgres |       10 | t           | t        | t       | t            |                                     |          | 
 vpnttg   |    16384 | f           | t        | f       | f            | md51e612cc18343323e2e462b39c92506aa |          | 
(2 rows)

postgres=# 
Logout from the PostgreSQL server:
postgres=# \q
bash-4.2$ exit
[root@localhost ~]#
Create of VPNTTG DB:
[root@localhost ~]# export PGPASSWORD=vpnttgpass
[root@localhost ~]# createdb vpnttgdb -h 127.0.0.1 -U vpnttg
List of PostgreSQL databases:
[root@localhost ~]# psql -l -h 127.0.0.1 -U vpnttg
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 vpnttgdb  | vpnttg   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
(4 rows)

[root@localhost ~]#