Docs / Databases / How to Install PostgreSQL on Ubuntu

How to Install PostgreSQL on Ubuntu

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 146 views · 1 min read

PostgreSQL is a powerful, enterprise-grade relational database with advanced features.

Install

apt update
apt install postgresql postgresql-contrib -y

Access PostgreSQL

sudo -u postgres psql

Create Database and User

CREATE USER myuser WITH PASSWORD 'SecurePassword123!';
CREATE DATABASE myapp OWNER myuser;
GRANT ALL PRIVILEGES ON DATABASE myapp TO myuser;
\q

Connect as User

psql -U myuser -d myapp -h localhost

Key Files

  • Config: /etc/postgresql/16/main/postgresql.conf
  • Auth: /etc/postgresql/16/main/pg_hba.conf
  • Data: /var/lib/postgresql/

Was this article helpful?