# Install Postgres DB
The Psono server requires a postgres database with some extensions. This section will explain how to install one and prepare it for the Psono server.
# Preamble
The native installation examples below cover Ubuntu 22.04 LTS and RHEL-compatible 9 distributions such as Rocky Linux or AlmaLinux.
# Installation with Docker
If you have docker running, then the database is just one command away:
First create the folder for your data e.g.:
sudo mkdir -p /opt/docker/psono/postgresSecond start the database
docker run --name psono-database \ -v /opt/docker/psono/postgres:/var/lib/postgresql \ -e POSTGRES_USER=psono \ -e POSTGRES_PASSWORD=password \ -d --restart=unless-stopped \ -p 5432:5432 postgres:18-alpineReplace
passwordwith a unique password
# Installation with Ubuntu
We will be using PostgreSQL 16 (the minimum supported version; the latest version is recommended):
First install postgres
sudo apt -y install vim bash-completion wget gnupg lsb-release wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list sudo apt -y update sudo apt -y install postgresql-16 postgresql-client-16Now lets switch the postgres user
sudo -iu postgresCreate our new DB
createdb psonoNow switch the command prompt to postgres command prompt
psql psonoFollowed by some nice postgres commands to create the user and grant all privileges:
CREATE USER psono WITH PASSWORD 'password'; GRANT ALL PRIVILEGES ON DATABASE "psono" to psono; GRANT CREATE ON SCHEMA public TO psono;Replace
passwordwith a unique passwordInstall some necessary extensions:
CREATE EXTENSION IF NOT EXISTS ltree; CREATE EXTENSION IF NOT EXISTS "pgcrypto";(optional) If you want to use this database for unit testing, you should also do:
ALTER USER psono CREATEDB;To exit this shell and return to your normal user do:
\q Ctrl + DOther databases are not supported because of missing ltree extension
Adjust
pg_hba.confin/etc/postgresql/16/main/Depending on your setup you might get
FATAL: Ident authentication failed for userwhich makes it necessary to adjust thepg_hba.confe.g. add the following lines:host psono psono 127.0.0.1/32 scram-sha-256 host psono psono ::1/128 scram-sha-256Afterwards restart postgres e.g.
service postgresql restartAllow network connections
Depending on your setup you might need postgres to listen on public interfaces, allowing other devices in the network to connect to your host. For that edit
postgresql.confin/etc/postgresql/16/main/and add the following line:listen_addresses = '*'Afterwards restart postgres e.g.
service postgresql restart
# Installation with RHEL-Compatible Distributions
We will be using PostgreSQL 16 (the minimum supported version; the latest version is recommended):
First install some requirements
sudo dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo dnf -y update sudo dnf -qy module disable postgresql sudo dnf -y install postgresql16-server postgresql16-contrib sudo /usr/pgsql-16/bin/postgresql-16-setup initdb sudo systemctl start postgresql-16 sudo systemctl enable postgresql-16Now lets switch the postgres user
sudo -iu postgresCreate our new DB
createdb psonoNow switch the command prompt to postgres command prompt
psql psonoFollowed by some nice postgres commands to create the user and grant all privileges:
CREATE USER psono WITH PASSWORD 'password'; GRANT ALL PRIVILEGES ON DATABASE "psono" to psono; GRANT CREATE ON SCHEMA public TO psono;Replace
passwordwith a unique passwordInstall some necessary extensions:
CREATE EXTENSION IF NOT EXISTS ltree; CREATE EXTENSION IF NOT EXISTS "pgcrypto";(optional) If you want to use this database for unit testing, you should also do:
ALTER USER psono CREATEDB;To exit this shell and return to your normal user do:
\q Ctrl + DOther databases are not supported because of missing ltree extension
Adjust
pg_hba.confin/var/lib/pgsql/16/dataDepending on your setup you might get
FATAL: Ident authentication failed for userwhich makes it necessary to adjust thepg_hba.confe.g. add the following lines:host psono psono 127.0.0.1/32 scram-sha-256 host psono psono ::1/128 scram-sha-256Afterwards restart postgres e.g.
sudo systemctl restart postgresql-16Allow network connections
Depending on your setup you might need postgres to listen on public interfaces, allowing other devices in the network to connect to your host. For that edit
postgresql.confin/var/lib/pgsql/16/dataand add the following line:listen_addresses = '*'Afterwards restart postgres e.g.
sudo systemctl restart postgresql-16