Conversation
✅ Deploy Preview for docsdocker ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tippexs
left a comment
There was a problem hiding this comment.
Just a small remark. Other then that, Great Work LGTM
| ```yaml | ||
| services: | ||
| postgres: | ||
| image: postgres:17.7 |
There was a problem hiding this comment.
Is there a reason why we do use 17.7 instead of 18 as in the rest of the guide?
craig-osterhout
left a comment
There was a problem hiding this comment.
Thanks @igor-alexandrov and all.
It looks great!
I left mostly style nits, not any technical blockers.
| title: PostgreSQL specific guide | ||
| linkTitle: PostgreSQL | ||
| description: Containerize PostgreSQL databases using Docker | ||
| keywords: Docker, getting started, postgresql, languag |
There was a problem hiding this comment.
| keywords: Docker, getting started, postgresql, languag | |
| keywords: Docker, getting started, postgresql, language |
| time: 20 minutes | ||
| --- | ||
|
|
||
| - Immediate Setup & Data Persistence |
There was a problem hiding this comment.
Not needed, as the template auto populates the child pages.
| - Immediate Setup & Data Persistence |
| --- | ||
|
|
||
| - Immediate Setup & Data Persistence | ||
| - Advanced Configuration and Initialization |
There was a problem hiding this comment.
| - Advanced Configuration and Initialization |
|
|
||
| - Immediate Setup & Data Persistence | ||
| - Advanced Configuration and Initialization | ||
| - Networking and Connectivity |
There was a problem hiding this comment.
| - Networking and Connectivity |
| - Immediate Setup & Data Persistence | ||
| - Advanced Configuration and Initialization | ||
| - Networking and Connectivity | ||
| - Companions for PostfgreSQL |
There was a problem hiding this comment.
| - Companions for PostfgreSQL |
|
|
||
| Does PgBouncer actually make a difference? Run the benchmarks yourself to find out. Your results will vary based on your hardware, Docker configuration, network setup, and system load. | ||
|
|
||
| ### What to Expect |
There was a problem hiding this comment.
| ### What to Expect | |
| ### What to expect |
|
|
||
| When you run these benchmarks, you'll observe patterns rather than specific numbers. Think of it like comparing two different routes to work: the "faster" route depends on traffic conditions, time of day, and your vehicle. | ||
|
|
||
| ### Key Observations |
There was a problem hiding this comment.
| ### Key Observations | |
| ### Key observations |
|
|
||
| When comparing direct connections versus PgBouncer, you'll typically notice: | ||
|
|
||
| **1. Connection overhead differs significantly** |
There was a problem hiding this comment.
| **1. Connection overhead differs significantly** | |
| #### 1. Connection overhead differs significantly |
|
|
||
| Direct connections require PostgreSQL to spawn a new process for each client. PgBouncer reuses existing connections. Watch the "initial connection time" metric in your results—PgBouncer often shows dramatically faster connection setup. | ||
|
|
||
| **2. Behavior under pressure reveals the real difference** |
There was a problem hiding this comment.
| **2. Behavior under pressure reveals the real difference** | |
| #### 2. Behavior under pressure reveals the real difference |
|
|
||
| Try increasing the client count (`-c` parameter) gradually: 50, 100, 150, 200. At some point, direct connections will fail with "too many clients already" while PgBouncer continues handling requests. This is PgBouncer's primary value: **it prevents connection exhaustion**. | ||
|
|
||
| **3. Throughput varies by environment** |
There was a problem hiding this comment.
| **3. Throughput varies by environment** | |
| #### 3. Throughput varies by environment |
| POSTGRES_DB: benchmark | ||
| POSTGRES_HOST_AUTH_METHOD: trust | ||
| volumes: | ||
| - postgres_data:/var/lib/postgresql/data |
There was a problem hiding this comment.
| - postgres_data:/var/lib/postgresql/data | |
| - postgres_data:/var/lib/postgresql |
|
|
||
| ### How initialization works | ||
|
|
||
| When the container starts, it checks whether the data directory (`/var/lib/postgresql/data`) is empty. If the directory already contains data, PostgreSQL starts immediately without running any initialization. If the directory is empty, the container runs `initdb` to create a new database cluster, then executes all scripts in `/docker-entrypoint-initdb.d/` in alphabetical order before starting PostgreSQL. |
There was a problem hiding this comment.
So, I noticed that there's a discrepancy in where exactly the data directory is stored between dhi.io/postgres and docker.io/library/postgres.
The official image stores it at /var/lib/postgresql//docker whereas the hardened image stores it at /var/lib/postgresql//data.
I don't think we need to get into the weeds about where exactly it is in this paragraph, so maybe we can rephrase to:
| When the container starts, it checks whether the data directory (`/var/lib/postgresql/data`) is empty. If the directory already contains data, PostgreSQL starts immediately without running any initialization. If the directory is empty, the container runs `initdb` to create a new database cluster, then executes all scripts in `/docker-entrypoint-initdb.d/` in alphabetical order before starting PostgreSQL. | |
| When the container starts, it checks whether the PostgreSQL data directory is empty. If the directory already contains data, PostgreSQL starts immediately without running any initialization. If the directory is empty, the container runs `initdb` to create a new database cluster, then executes all scripts in `/docker-entrypoint-initdb.d/` in alphabetical order before starting PostgreSQL. |
| | `.sql.gz` | Gzip-compressed SQL files | | ||
| | `.sh` | Shell scripts executed with bash | | ||
|
|
||
| > **Important:** Initialization scripts only run when the PostgreSQL data directory (`/var/lib/postgresql/data`) is empty. If you mount a volume containing existing data, initialization is skipped. This behavior prevents overwriting existing databases. |
There was a problem hiding this comment.
| > **Important:** Initialization scripts only run when the PostgreSQL data directory (`/var/lib/postgresql/data`) is empty. If you mount a volume containing existing data, initialization is skipped. This behavior prevents overwriting existing databases. | |
| > **Important:** Initialization scripts only run when the PostgreSQL data directory is empty. If you mount a volume containing existing data, initialization is skipped. This behavior prevents overwriting existing databases. |
|
|
||
| The `-v postgres_data:/var/lib/postgresql` flag mounts a named volume called `postgres_data` to PostgreSQL's data directory. If the volume doesn't exist, Docker creates it automatically. | ||
|
|
||
| > **Note:** PostgreSQL 18+ stores data in a version-specific subdirectory under `/var/lib/postgresql`. Mounting at this level (rather than `/var/lib/postgresql/data`) allows for easier upgrades using `pg_upgrade --link`. |
Description
This PR introduces a new PostgreSQL-specific guide to help users containerize PostgreSQL databases using Docker. The guide is structured into four progressive modules:
Immediate Setup & Data Persistence - Covers running PostgreSQL containers with proper data persistence using named volumes, bind mounts, and Docker Compose configurations.
Advanced Configuration and Initialization - Explains initialization scripts (/docker-entrypoint-initdb.d/), performance tuning parameters (memory settings, connection limits, I/O
configuration), and timezone/locale settings.
Networking and Connectivity - Details how to configure networking for containerized PostgreSQL deployments.
Companions for PostgreSQL - Introduces ecosystem tools including pgAdmin 4 for visual management, PgBouncer and Pgpool-II for connection pooling, and pgbench for performance testing.
Examples include tabs showing both Docker Hardened Images (DHI) and Docker Official Images (DOI) variants where applicable.
The guide is prepared by @igor-alexandrov, @edithturn, and @Expeto.
Reviews