---
title: "Use PostgreSQL for the main database · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/databases-and-storage/postgresql
updated: 2026-10-21
licence: "All rights reserved"
---

# Use PostgreSQL for the main database

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- Level: Recommended
- Chapter: [Databases and storage](https://agentwranglers.se/playbook/stack/databases-and-storage)
- Rule: Keep the main business data of a web app in PostgreSQL, on a major version with more than 12 months of support left.
- Cost: Open source. PostgreSQL Licence, free to run on your own servers. Managed hosting from every large cloud is paid.
- How: 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](https://agentwranglers.se/playbook/data/operations/connection-pooling) and [point-in-time recovery](https://agentwranglers.se/playbook/data/backups-and-recovery/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.
- 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.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### YAML example

```yaml
# 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

```js
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

```python
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")
```

## Sources

- [PostgreSQL versioning policy](https://www.postgresql.org/support/versioning/)
- [PostgreSQL licence](https://www.postgresql.org/about/licence/)

## Related rules

- [Pool database connections](https://agentwranglers.se/playbook/data/operations/connection-pooling) in Data
- [Keep point-in-time recovery for busy databases](https://agentwranglers.se/playbook/data/backups-and-recovery/point-in-time-recovery) in Data

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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.

- Next: [Use SQLite for a small or embedded database](https://agentwranglers.se/playbook/stack/databases-and-storage/sqlite)
- [Databases and storage](https://agentwranglers.se/playbook/stack/databases-and-storage)
