commit
b38b171116
5 changed files with 86 additions and 0 deletions
@ -0,0 +1 @@ |
|||
.env |
@ -0,0 +1,5 @@ |
|||
FROM docker.pblr-nyk.pro/postgres:16.4-bullseye |
|||
COPY reppoint /reppoint |
|||
RUN chmod +x /reppoint |
|||
ENTRYPOINT ["/reppoint"] |
|||
CMD [] |
@ -0,0 +1,14 @@ |
|||
Делает полную копию бд посгресса в оперативку или любое другое место. |
|||
|
|||
Че добавить на реплике: |
|||
-> .env |
|||
MASTER_ADDRESS=x.x.x.x #Ип бд |
|||
MASTER_USER=user #Юзер для реплики |
|||
TZ=Europe/Moscow #Я русский |
|||
|
|||
Че добавить на мастере: |
|||
wal_level = hot_standby |
|||
archive_mode = on |
|||
archive_command = 'cd .' |
|||
max_wal_senders = 8 |
|||
hot_standby = on |
@ -0,0 +1,20 @@ |
|||
services: |
|||
postgres_db_mem_rep: |
|||
build: ./ |
|||
container_name: postgress_db_mem_replica |
|||
#restart: unless-stopped |
|||
env_file: .env |
|||
tmpfs: |
|||
- /var/lib/postgresql/data |
|||
ports: |
|||
- 5442:5432 |
|||
deploy: |
|||
resources: |
|||
limits: |
|||
cpus: "4.0" |
|||
memory: 16G |
|||
# networks: |
|||
# - postgres_db_default |
|||
#networks: |
|||
# postgres_db_default: |
|||
# external: true |
@ -0,0 +1,46 @@ |
|||
#!/bin/bash |
|||
|
|||
if [[ -z "${MASTER_ADDRESS}" ]]; then |
|||
echo "Cannot startup, need MASTER_ADDRESS" |
|||
else |
|||
MASTER_ADDRESS="${MASTER_ADDRESS}" |
|||
echo "copy from ${MASTER_ADDRESS}" |
|||
fi |
|||
|
|||
echo "init default scripts" |
|||
export POSTGRES_PASSWORD="replica" |
|||
docker-entrypoint.sh postgres -v |
|||
|
|||
echo "add user" |
|||
#add replication user |
|||
cat <<EOT >> /var/lib/postgresql/data/pg_hba.conf |
|||
host replication postgres $MASTER_ADDRESS/24 trust |
|||
host all all all md5 |
|||
EOT |
|||
|
|||
echo "add replica rules" |
|||
#add replica rules |
|||
cat <<EOT >> /var/lib/postgresql/data/postgresql.conf |
|||
listen_addresses = '*' |
|||
wal_level = hot_standby |
|||
archive_mode = on |
|||
archive_command = 'cd .' |
|||
max_wal_senders = 8 |
|||
hot_standby = on |
|||
max_connections = 1000 |
|||
EOT |
|||
|
|||
#create copy |
|||
mkdir /tmp/pg_copy |
|||
cp /var/lib/postgresql/data/*.conf /tmp/pg_copy |
|||
echo "copy from master" |
|||
rm -rf /var/lib/postgresql/data |
|||
mkdir /var/lib/postgresql/data |
|||
pg_basebackup -v -P -R -X stream -c fast -h ${MASTER_ADDRESS} -U ${MASTER_USER} -D /var/lib/postgresql/data |
|||
rm /var/lib/postgresql/data/*.conf |
|||
cp /tmp/pg_copy/*.conf /var/lib/postgresql/data/ |
|||
chown postgres:postgres -R /var/lib/postgresql/data |
|||
|
|||
echo "run postgres" |
|||
#run postgres |
|||
docker-entrypoint.sh postgres |
Loading…
Reference in new issue