...
Skip to main content
Print

How to Install PostgreSQL on Ubuntu

You install PostgreSQL on Ubuntu with apt install postgresql. Then you use psql to create your own user and database for your application. PostgreSQL is a powerful open-source database, popular with Django, n8n and other modern applications, among others.

Step 1: install PostgreSQL

apt update
apt install postgresql -y
systemctl enable --now postgresql

Step 2: create a user and database

sudo -u postgres psql
CREATE USER mijnapp WITH PASSWORD 'STERK-WACHTWOORD';
CREATE DATABASE mijnapp OWNER mijnapp;
\q

Step 3: test the connection

psql -h localhost -U mijnapp -d mijnapp

PostgreSQL on AlmaLinux

dnf install postgresql-server -y
postgresql-setup --initdb
systemctl enable --now postgresql

Making a backup with pg_dump

sudo -u postgres pg_dump mijnapp > mijnapp.sql

Let PostgreSQL listen only on localhost, unless you really need external access. In that case open the port only for your own IP address.

Related articles

Table of Contents