Create User OS with sudo
$ adduser user_name
$ passwd user_name
$ usermod -aG wheel username
Note: For user postgres will create automatic after install PostgreSQL completed.
Repository Configuration
# sudo apt install curl ca-certificates
# sudo install -d /usr/share/postgresql-common/pgdg
# sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
# deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main
# sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'#
PostgreSQL installation
# sudo apt update
# sudo apt install postgresql-16
Configure PostgreSQL
Enable listener
$ vi /etc/postgresql/16/main/postgresql.conf
listen_addresses = '*'
port = 5432
max_connections = 300
Enable Access List ( White list)
$ vi /etc/postgresql/16/main/pg_hba.conf
host all all 192.168.1.70/32 md5
host all all 0.0.0.0/0 md5
Restart Service for take effect
# systemctl stop postgresql@16-main
# systemctl start postgresql@16-main
Create Database
$ psql
postgres=# createdb testdb;
Create User
$ psql
postgres=# create user testuser with encrypted password ‘password’;
Grant Permission
$ psql
postgres=# \c testdb
testdb=# GRANT ALL ON SCHEMA public TO testuser;
testdb=# ALTER SCHEMA public OWNER TO testuser;