Quick answer: Install PostgreSQL with sudo apt install postgresql on Ubuntu/Debian or sudo dnf install postgresql-server (plus postgresql-setup --initdb) on AlmaLinux/Rocky, enable the service, then create a role and database with createuser/createdb as the postgres user.

Overview

PostgreSQL is a powerful open-source relational database favored for correctness, rich SQL features and extensions (PostGIS, full-text search). It is the default choice for Django, Rails and many modern backends.

Before you start

  • Root/sudo access via SSH.
  • Know which PostgreSQL major version your application targets — distro repos ship a stable default; the official PGDG repository offers newer versions if required.

Step-by-step guide

  1. Install and initialize:
    # Ubuntu/Debian
    sudo apt -y install postgresql
    # AlmaLinux/Rocky
    sudo dnf -y install postgresql-server
    sudo postgresql-setup --initdb
  2. Enable and start:
    sudo systemctl enable --now postgresql
  3. Create a role and database:
    sudo -u postgres createuser --pwprompt myapp
    sudo -u postgres createdb -O myapp myappdb
  4. Test the connection:
    psql -h 127.0.0.1 -U myapp -d myappdb
  5. Authentication rules live in pg_hba.conf (see SHOW hba_file; in psql) — local apps should use 127.0.0.1 with password (scram-sha-256) auth.

Common issues

  • peer authentication failed: connect via -h 127.0.0.1 or adjust pg_hba.conf — peer auth maps system users to DB roles.
  • Remote connections refused: PostgreSQL listens on localhost by default. Prefer SSH tunnels; if you must expose it, set listen_addresses, add a strict pg_hba.conf rule and firewall to a single source IP.
  • RHEL family: service fails on first start: you skipped postgresql-setup --initdb.

When to contact support

For platform-level trouble (server unreachable, disk errors) or a resource upgrade for a growing database, open a ticket.

Frequently asked questions

Why does psql say "peer authentication failed"?

Local socket connections map system users to database roles by default. Connect over TCP with "psql -h 127.0.0.1 -U youruser" or adjust the rules in pg_hba.conf.

How do I allow remote connections to PostgreSQL?

Prefer an SSH tunnel. Otherwise set listen_addresses in postgresql.conf, add a strict pg_hba.conf rule, and firewall port 5432 to a single trusted source IP.

MariaDB or PostgreSQL — which should I pick?

Use what your application recommends: PHP CMSes usually expect MariaDB/MySQL, while Django, Rails and many modern backends default to PostgreSQL.

Related articles

Ready to get started? Order a VPS at Cloud2Y →

Was this answer helpful? 0 Users Found This Useful (0 Votes)