DEV Community

Cover image for How to Self-Host PostgreSQL (with Monitoring)
Alexander Neitzel
Alexander Neitzel

Posted on • Originally published at garmingo.com

How to Self-Host PostgreSQL (with Monitoring)

PostgreSQL is the backbone of tons of modern apps — powerful, reliable, and open-source.

And yes, self-hosting it is totally doable.

In this guide, we’ll go through:

  • Installing PostgreSQL on a Linux server
  • Basic security & setup
  • Optional access via pgAdmin
  • Monitoring your database with Garmingo Status for full visibility

🧰 What You’ll Need

  • A Linux server (Ubuntu, Debian, etc.)
  • sudo/root access
  • ~10 minutes

⚡ Step 1: Install PostgreSQL

Update your server:

sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Install PostgreSQL:

sudo apt install postgresql postgresql-contrib -y
Enter fullscreen mode Exit fullscreen mode

Check status:

sudo systemctl status postgresql
Enter fullscreen mode Exit fullscreen mode

🛡️ Step 2: Set a Password for the postgres User

Switch to the postgres user:

sudo -i -u postgres
Enter fullscreen mode Exit fullscreen mode

Then access the PostgreSQL shell:

psql
Enter fullscreen mode Exit fullscreen mode

Set a password:

\password postgres  
Enter fullscreen mode Exit fullscreen mode

Exit with:

\q  
exit
Enter fullscreen mode Exit fullscreen mode

🧱 Step 3: Create a Database & User

sudo -i -u postgres  
createdb myappdb  
createuser myappuser  
psql  
Enter fullscreen mode Exit fullscreen mode

In the shell:

ALTER USER myappuser WITH ENCRYPTED PASSWORD 'strongpass';  
GRANT ALL PRIVILEGES ON DATABASE myappdb TO myappuser;  
\q  
exit
Enter fullscreen mode Exit fullscreen mode

🔐 Step 4: Enable Remote Access (Optional)

Edit config:

sudo nano /etc/postgresql/*/main/postgresql.conf
Enter fullscreen mode Exit fullscreen mode

Change:

listen_addresses = '*'
Enter fullscreen mode Exit fullscreen mode

Then:

sudo nano /etc/postgresql/*/main/pg_hba.conf
Enter fullscreen mode Exit fullscreen mode

Add:

host    all             all             0.0.0.0/0            md5
Enter fullscreen mode Exit fullscreen mode

Restart:

sudo systemctl restart postgresql
Enter fullscreen mode Exit fullscreen mode

🌐 Step 5: (Optional) Use pgAdmin for GUI Access

Install pgAdmin via Docker, Snap, or locally.

Connect using:

  • Host: your-server-ip
  • Port: 5432
  • User: myappuser
  • Password: the one you set

✅ Step 6: Monitor PostgreSQL with Garmingo Status

Postgres is mission-critical. If it goes down, everything breaks.

Here’s how to make sure that never happens:

  • Go to Garmingo Status
  • Add a Port monitor for 5432 on your server’s IP
  • Get alerts via Email, Slack, Telegram, Discord, or Webhooks
  • View historical uptime
  • Log incidents
  • Generate monthly SLA reports

🆓 All available on the forever free plan, no credit card required.

👉 Set up your DB monitoring now


🧘 TL;DR

  • ✅ Install PostgreSQL
  • 🔐 Secure + configure remote access
  • 🛠️ Create user + DB
  • 📊 Monitor uptime and availability with Garmingo Status

Because databases don’t break often —

…but when they do, it hurts.

👉 Get real monitoring now

Top comments (0)

OSZAR »