first commit
This commit is contained in:
parent
63c636d10b
commit
13bc883d64
5 changed files with 99 additions and 0 deletions
19
replicator-side/docker-compose.yml
Normal file
19
replicator-side/docker-compose.yml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
services:
|
||||
postgres-replica:
|
||||
image: postgres:17
|
||||
container_name: postgres-replica
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "7447:5432"
|
||||
environment:
|
||||
PRIMARY_HOST: 57.128.212.174
|
||||
PRIMARY_PORT: 7447
|
||||
REPLICATION_USER: replicator
|
||||
REPLICATION_PASSWORD: replicator_password
|
||||
volumes:
|
||||
- ./data:/var/lib/postgresql/data
|
||||
- ./postgresql.conf:/etc/postgresql/postgresql.conf:ro
|
||||
- ./pg_hba.conf:/etc/postgresql/pg_hba.conf:ro
|
||||
- ./replica-entrypoint.sh:/replica-entrypoint.sh:ro
|
||||
command: ["/bin/bash", "/replica-entrypoint.sh"]
|
||||
|
||||
27
replicator-side/init-replica.sh
Executable file
27
replicator-side/init-replica.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DATA_DIR="/var/lib/postgresql/data"
|
||||
|
||||
if [ -f "$DATA_DIR/PG_VERSION" ]; then
|
||||
echo "Data directory already initialized, skipping base backup"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Initializing replica from primary..."
|
||||
|
||||
rm -rf "$DATA_DIR"/*
|
||||
export PGPASSWORD="$REPLICATION_PASSWORD"
|
||||
|
||||
pg_basebackup \
|
||||
-h "$PRIMARY_HOST" \
|
||||
-p "$PRIMARY_PORT" \
|
||||
-U "$REPLICATION_USER" \
|
||||
-D "$DATA_DIR" \
|
||||
-Fp \
|
||||
-Xs \
|
||||
-R \
|
||||
-P
|
||||
|
||||
echo "Replica base backup completed."
|
||||
|
||||
4
replicator-side/pg_hba.conf
Normal file
4
replicator-side/pg_hba.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
local all all trust
|
||||
host all all 127.0.0.1/32 trust
|
||||
host all all ::1/128 trust
|
||||
|
||||
15
replicator-side/postgresql.conf
Normal file
15
replicator-side/postgresql.conf
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
listen_addresses = '*'
|
||||
port = 5432
|
||||
|
||||
wal_level = replica
|
||||
hot_standby = on
|
||||
max_connections = 100
|
||||
|
||||
hot_standby_feedback = on
|
||||
wal_keep_size = 256MB
|
||||
|
||||
logging_collector = on
|
||||
log_destination = 'stderr'
|
||||
|
||||
hba_file = '/etc/postgresql/pg_hba.conf'
|
||||
|
||||
34
replicator-side/replica-entrypoint.sh
Executable file
34
replicator-side/replica-entrypoint.sh
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DATA_DIR="/var/lib/postgresql/data"
|
||||
|
||||
if [ ! -f "$DATA_DIR/PG_VERSION" ]; then
|
||||
echo "Running pg_basebackup from primary..."
|
||||
|
||||
rm -rf "$DATA_DIR"/*
|
||||
export PGPASSWORD="$REPLICATION_PASSWORD"
|
||||
|
||||
pg_basebackup \
|
||||
-h "$PRIMARY_HOST" \
|
||||
-p "$PRIMARY_PORT" \
|
||||
-U "$REPLICATION_USER" \
|
||||
-D "$DATA_DIR" \
|
||||
-Fp \
|
||||
-Xs \
|
||||
-R \
|
||||
-P
|
||||
|
||||
echo "Fixing ownership and permissions..."
|
||||
chown -R postgres:postgres "$DATA_DIR"
|
||||
chmod 0700 "$DATA_DIR"
|
||||
else
|
||||
echo "Replica already initialized"
|
||||
fi
|
||||
|
||||
echo "Starting postgres as postgres user..."
|
||||
|
||||
exec gosu postgres postgres \
|
||||
-c config_file=/etc/postgresql/postgresql.conf \
|
||||
-c hba_file=/etc/postgresql/pg_hba.conf
|
||||
|
||||
Loading…
Add table
Reference in a new issue