-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-compose.postgres-ha.yml
More file actions
53 lines (51 loc) · 1.83 KB
/
Copy pathdocker-compose.postgres-ha.yml
File metadata and controls
53 lines (51 loc) · 1.83 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
services:
db-primary:
image: pgvector/pgvector:pg16
environment:
- POSTGRES_DB=${POSTGRES_DB:-ai_email}
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD before running Postgres HA Compose}
- POSTGRES_HOST_AUTH_METHOD=scram-sha-256
command:
- "postgres"
- "-c"
- "wal_level=replica"
- "-c"
- "max_wal_senders=10"
- "-c"
- "max_replication_slots=10"
- "-c"
- "hot_standby=on"
ports:
- "${POSTGRES_HA_PRIMARY_PORT:-5432}:5432"
volumes:
- pgdata_primary:/var/lib/postgresql/data
- ./scripts/postgres-ha/init-primary-replication.sh:/docker-entrypoint-initdb.d/010-replication-hba.sh:ro
db-replica:
image: pgvector/pgvector:pg16
environment:
- POSTGRES_DB=${POSTGRES_DB:-ai_email}
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD before running Postgres HA Compose}
- PGUSER=${POSTGRES_USER:-postgres}
- PGPASSWORD=${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD before running Postgres HA Compose}
command: >
bash -c "
until pg_isready -h db-primary -p 5432; do sleep 1; done;
if [ ! -s /var/lib/postgresql/data/PG_VERSION ]; then
chown -R postgres:postgres /var/lib/postgresql/data;
gosu postgres pg_basebackup -h db-primary -D /var/lib/postgresql/data -U ${POSTGRES_USER:-postgres} -vP -R -X stream -C -S replica_slot_1;
fi;
chown -R postgres:postgres /var/lib/postgresql/data;
chmod 700 /var/lib/postgresql/data;
exec gosu postgres postgres
"
ports:
- "${POSTGRES_HA_REPLICA_PORT:-5433}:5432"
depends_on:
- db-primary
volumes:
- pgdata_replica:/var/lib/postgresql/data
volumes:
pgdata_primary:
pgdata_replica: