-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
56 lines (52 loc) · 1.54 KB
/
docker-compose.yml
File metadata and controls
56 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
services:
postgres:
image: postgres:18
container_name: postgres
restart: always
network_mode: host
shm_size: 1gb
environment:
- PGDATA=/var/lib/postgresql/18/data
env_file:
- .env
volumes:
- ./postgres/data:/var/lib/postgresql/18/data
- ./postgres/backup:/var/lib/postgresql/18/backup
command: >
postgres
-c listen_addresses='localhost'
-c shared_buffers=2GB
-c effective_cache_size=4500MB
-c work_mem=16MB
-c maintenance_work_mem=256MB
-c effective_io_concurrency=200
-c random_page_cost=1.1
healthcheck:
test: ['CMD-SHELL', 'PGPASSWORD=$${POSTGRES_PASSWORD} pg_isready -h localhost -U $${POSTGRES_USER}']
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
postgres_backup:
image: postgres:18
container_name: postgres_backup
restart: always
depends_on:
postgres:
condition: service_healthy
network_mode: host
env_file:
- .env
volumes:
- ./postgres/backup:/var/lib/postgresql/18/backup
entrypoint: >
bash -c "
while true; do
echo 'Backing up...'
PGPASSWORD=$${POSTGRES_PASSWORD} pg_dumpall -h localhost -U $${POSTGRES_USER} > /var/lib/postgresql/18/backup/tmp.sql && \
mv /var/lib/postgresql/18/backup/tmp.sql /var/lib/postgresql/18/backup/backup_$$(date +%Y%m%d%H%M).sql
ls -tp /var/lib/postgresql/18/backup/backup_*.sql | tail -n +11 | xargs -I {} rm -- {}
echo 'Done'
sleep 86400
done
"