Agent Wranglers

STK-28Default Open source

Use PostgreSQL for the main database

Keep the main business data of a web app in PostgreSQL, on a major version with more than 12 months of support left.

Review by

2027-04-30

How to do it

PostgreSQL has shipped under that name since 1996. Version 18 came out on 25 September 2025, and its current minor release is 18.6. Each major version gets five years of fixes, so 18 is supported until 14 November 2030. It was the most used database in the Stack Overflow Developer Survey 2026, at 57.9% of all respondents. It runs under the PostgreSQL Licence, which the OSI approves. Every large cloud sells it as a managed service, and pg_dump gives you a plain SQL copy to leave with. Run it as the data playbook says, with connection pooling and point-in-time recovery. Choose something else when a working MySQL or SQL Server database already holds the data, or when one small app fits in SQLite.

Examples

YAML example

# compose.yaml for local development
services:
  db:
    image: postgres:18.6
    environment:
      POSTGRES_DB: shop
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
    volumes:
      - db-data:/var/lib/postgresql
volumes:
  db-data:

JavaScript example

import pg from 'pg';

const MIN_SUPPORTED_MAJOR = 15;
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
const { rows } = await pool.query('SHOW server_version_num');
const major = Math.floor(Number(rows[0].server_version_num) / 10_000);
if (major < MIN_SUPPORTED_MAJOR) throw new Error(`PostgreSQL ${major} leaves support soon`);

Python example

import os
import psycopg

MIN_SUPPORTED_MAJOR = 15

with psycopg.connect(os.environ["DATABASE_URL"]) as conn:
    major = conn.info.server_version // 10_000
    if major < MIN_SUPPORTED_MAJOR:
        raise RuntimeError(f"PostgreSQL {major} leaves support soon")

How to check

SHOW server_version on every environment returns the current minor release of a major version. The versioning page lists that major's end of life more than 12 months after today.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/databases-and-storage/postgresql">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.