Fix PostgreSQL replication: add pg_hba.conf entries for replicator user
- Create init-master.sh that runs SQL and appends replication rules to pg_hba.conf - Switch docker-compose-prod template from init-master.sql to init-master.sh - Fixes "no pg_hba.conf entry for replication connection" error Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -37,7 +37,7 @@ services:
|
|||||||
- hot_standby=on
|
- hot_standby=on
|
||||||
volumes:
|
volumes:
|
||||||
- db-master-data:/var/lib/postgresql/data
|
- db-master-data:/var/lib/postgresql/data
|
||||||
- ./docker/pgsql/init-master.sql:/docker-entrypoint-initdb.d/init-master.sql
|
- ./docker/pgsql/init-master.sh:/docker-entrypoint-initdb.d/init-master.sh
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U e-ticket -d e-ticket"]
|
test: ["CMD-SHELL", "pg_isready -U e-ticket -d e-ticket"]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
|
|||||||
12
docker/pgsql/init-master.sh
Executable file
12
docker/pgsql/init-master.sh
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
CREATE USER replicator WITH REPLICATION ENCRYPTED PASSWORD 'e-ticket';
|
||||||
|
SELECT pg_create_physical_replication_slot('slave_slot');
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
echo "host replication replicator 0.0.0.0/0 md5" >> "$PGDATA/pg_hba.conf"
|
||||||
|
echo "host all all 0.0.0.0/0 md5" >> "$PGDATA/pg_hba.conf"
|
||||||
|
|
||||||
|
pg_ctl reload -D "$PGDATA"
|
||||||
Reference in New Issue
Block a user