Skip to content

Commit 3a0c4ff

Browse files
feat(docker): upgrade PostgreSQL and add performance tuning (#37)
- Upgrade PostgreSQL from 14.1 to 16-alpine - Add performance tuning parameters: - max_connections=100 - shared_buffers=128MB - work_mem=4MB - maintenance_work_mem=64MB - effective_cache_size=512MB - Configure PGDATA explicitly for data organization - Improve healthcheck with start_period for slower starts - Update documentation with PostgreSQL settings Co-authored-by: rafaelrsantosti <11065120+rafaelrsantosti@users.noreply.github.com>
1 parent b77d944 commit 3a0c4ff

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

docker/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,20 @@ docker compose -f docker-compose.prod.yaml run --rm certbot certonly --force-ren
270270
--webroot -w /var/www/certbot -d your-domain.com
271271
```
272272

273+
### PostgreSQL Performance
274+
275+
The database is configured with optimized settings for production:
276+
277+
| Parameter | Value | Description |
278+
|-----------|-------|-------------|
279+
| `max_connections` | 100 | Maximum concurrent connections |
280+
| `shared_buffers` | 128MB | Memory for caching data |
281+
| `work_mem` | 4MB | Memory per query operation |
282+
| `maintenance_work_mem` | 64MB | Memory for maintenance operations |
283+
| `effective_cache_size` | 512MB | Planner's assumption about cache |
284+
285+
For high-traffic deployments, consider increasing these values based on available memory.
286+
273287
### Reset everything
274288

275289
```bash

docker/docker-compose.prod.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,30 @@ services:
2727
# Database Services
2828
# =============================================================================
2929
database:
30-
image: postgres:14.1-alpine
30+
image: postgres:16-alpine
3131
profiles:
3232
- db
3333
- full
3434
environment:
3535
POSTGRES_USER: ${DB_USER:-tron}
3636
POSTGRES_PASSWORD: ${DB_PASSWORD:?DB_PASSWORD is required}
3737
POSTGRES_DB: api
38+
PGDATA: /var/lib/postgresql/data/pgdata
39+
command: >
40+
postgres
41+
-c max_connections=100
42+
-c shared_buffers=128MB
43+
-c work_mem=4MB
44+
-c maintenance_work_mem=64MB
45+
-c effective_cache_size=512MB
3846
volumes:
3947
- postgres_data:/var/lib/postgresql/data
4048
healthcheck:
4149
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-tron} -d api -h localhost"]
4250
interval: 10s
4351
timeout: 5s
44-
retries: 5
45-
start_period: 10s
52+
retries: 10
53+
start_period: 30s
4654
restart: unless-stopped
4755
networks:
4856
- tron-network

docker/docker-compose.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,30 @@ x-env-api: &shared_env_api
2323

2424
services:
2525
database:
26-
image: postgres:14.1
26+
image: postgres:16-alpine
2727
environment:
2828
- POSTGRES_USER=tron
2929
- POSTGRES_PASSWORD=tron
3030
- POSTGRES_MULTIPLE_DATABASES=api,portal
31+
- PGDATA=/var/lib/postgresql/data/pgdata
32+
command: >
33+
postgres
34+
-c max_connections=100
35+
-c shared_buffers=128MB
36+
-c work_mem=4MB
37+
-c maintenance_work_mem=64MB
38+
-c effective_cache_size=512MB
3139
ports:
3240
- "5432:5432"
3341
volumes:
3442
- ${PWD}/volumes/postgres:/var/lib/postgresql/data
3543
- ${PWD}/docker/db-entrypoint:/docker-entrypoint-initdb.d
3644
healthcheck:
3745
test: ["CMD-SHELL", "pg_isready -U tron -d api -h localhost"]
38-
interval: 3s
39-
timeout: 10s
46+
interval: 5s
47+
timeout: 5s
4048
retries: 10
49+
start_period: 10s
4150

4251
portal:
4352
build:

0 commit comments

Comments
 (0)