PostgreSQL Setup

  • This page was first created on 13 Oct 2021

  • Updated 29 Aug 2026

On Debian 10

  • Reference URL: https://linuxize.com/post/how-to-install-postgresql-on-debian-10/

  • $ sudo -u postgres psql to get into postgress client.

  • =# CREATE USER sonardbuser;

  • =# ALTER USER omsuser WITH PASSWORD 'new_password';

  • =# CREATE DATABASE sonardb WITH TEMPLATE = template0 ENCODING 'UTF8';

  • =# exit;

  • From client connect with $ psql -h <hostname> -d <db instance name> -U <username>. It will then prompt you for the password.

Postgres 18 on Debian 13

Installation

  • Create a container / vm with Debian 13 and take a snapshot

  • Install the postgres client and tools:
    $ sudo apt install -y postgresql-common ca-certificates
  • Install the Postgres.org repository to apt:
    $ sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
  • Refresh the information from the newly added repository and update all packages
    $ sudo apt update && sudo apt full-upgrade -y
  • Install Postgres 18 in the container / vm
    $ sudo apt install postgresql-18. Postgres version 18 is now installed.

Setting up the postgres System User

  • Login to the postgres user with the following command
    $ sudo -i -u postgres
  • Connect to the database using psql with the postgres user
    $ psql
  • Set the password for the postgres user
    postgres=# ALTER USER postgres WITH PASSWORD 'your_password'
  • Quit out of the psql client
    postgres=# \q