Skip to content

PostgreSQL on a VPS

Relational database

Category
Databases
Hosting
Databases
Author
PostgreSQL Global Development Group
License
PostgreSQL
Version
18.6

The script is free · VPS from $4.63 per month · installs in about 2 minutes

Install over SSH

root@vps:~# sudo apt install -y postgresql-common && sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && sudo apt install -y postgresql-18

  • SystemUbuntu 24.04 · x86_64ok
  • Sourcegithub.com/postgres/postgresok
  • Version18.6ok
  • Port5432/tcplisten

✓ PostgreSQL 18.6 installed · about 2 minutes

root@vps:~#

Install command from the library. Output is shortened and may differ on your server.

What it is

  • SQL
  • Database
  • JSONB
  • Backups

PostgreSQL is a reliable open-source relational database. It suits Telegram bots, web apps, analytics and anything where transactions and data integrity matter.

Your own database on a VPS gives you full control over the version, settings and backups, without the limits of managed cloud databases. It is used by n8n, Gitea, Nextcloud, Remnawave and many other projects.

The command adds the official PostgreSQL repository (PGDG) and installs the latest major version, 18.

  • Transactions, foreign keys and strict data integrity
  • JSONB for documents in a regular table
  • Full-text search
  • Extensions: PostGIS, pgvector, TimescaleDB and more
  • Replication and backups via pg_dump

Recommended plan

For PostgreSQL: at least 2 vCPU, 3 GB RAM and 45 GB NVMe.

Minimum to run
1 vCPU · 1 GB RAM · 10 GB disk
Systems
Ubuntu 22.04 · Ubuntu 24.04 · Debian 12

How to install

Three steps in the bot or one command over SSH; installation takes about 2 minutes.

  1. 01

    Choose a plan in the bot

    Open @ExpressHost_bot and pay for a VPS. The server will be ready in about 60 seconds.

  2. 02

    Add PostgreSQL

    At the “Add-ons” step pick the script from the library, or run it later: Server settings → Scripts.

  3. 03

    Open the console: sudo -u postgres psql

    The bot will send the server address and login details to the chat.

Manually over SSH

Connect to the server as root and run the command. Supported systems: Ubuntu 22.04, Ubuntu 24.04, Debian 12.

Install command
sudo apt install -y postgresql-common && sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && sudo apt install -y postgresql-18

Ports

PostgreSQL ports
PortProtocolPurpose
5432tcpDatabase connections (localhost only by default)

After installation

  1. 1.Open the console: sudo -u postgres psql
  2. 2.Create a user and a database: sudo -u postgres createuser --pwprompt app && sudo -u postgres createdb -O app app
  3. 3.For external connections, change listen_addresses in /etc/postgresql/18/main/postgresql.conf and add a rule to pg_hba.conf

PostgreSQL FAQ

Didn’t find an answer? Message @ExpressHost_SupportBot.

Should I expose port 5432?

Better not. Connect via an SSH tunnel or allow only the required IPs in pg_hba.conf.

How do I make a backup?

sudo -u postgres pg_dump app > app.sql. For regular backups, add this command to cron.

Where is the data stored?

In /var/lib/postgresql/18/main, configs are in /etc/postgresql/18/main.

PostgreSQL installs at checkout — in the bot.