У меня есть репликация логическая, одна база данных Postgresql в контейнере докера, а вторая локальная на другом сервере.
Вот мой docker-compose.yml (мастер-БД):
services:
  redis:
    image: redis
    environment:
      - REDIS_PASSWORD=${REDIS_PASSWORD}
    command: [ "redis-server", "--requirepass", "${REDIS_PASSWORD}" ]
    networks:
      - backend_network
    restart: unless-stopped

  db:
    build:
      context: ./db
    env_file:
      - .env
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - REPLICATOR_PASSWORD=${REPLICATOR_PASSWORD}
      - SLAVE_IP_ADDRESS=${SLAVE_IP_ADDRESS}
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - '5433:5432'
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres" ]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - backend_network
    restart: unless-stopped

  app:
    build: .
    tty: true
    command: >
      sh -c "python manage.py migrate --noinput && 
             python manage.py collectstatic --noinput &&
             gunicorn config.wsgi:application --bind 0.0.0.0:8000"
    ports:
      - "8000:8000"
    env_file:
      - .env
    volumes:
      - .:/code
      - static-files:/code/static
      - media-files:/code/media
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - backend_network
      - nginx_network
    restart: unless-stopped

  backup:
    build: ./backup
    env_file:
      - .env
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./backups:/backups
    depends_on:
      - db
      - app
    networks:
      - backend_network
    restart: unless-stopped

  celery:
    build: .
    tty: true
    command: celery -A config worker -l INFO
    volumes:
      - media-files:/code/media
    depends_on:
      - redis
      - app
    networks:
      - backend_network
    restart: unless-stopped

  celery-beat:
    build: .
    tty: true
    command: celery -A config beat -l INFO
    env_file:
      - .env
    volumes:
      - media-files:/code/media
    depends_on:
      - redis
      - app
    networks:
      - backend_network
    restart: unless-stopped

volumes:
  static-files:
    external: true
  pgdata:
    name: "pgdata"
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: 'pgdata'
  media-files:
    name: "media-files"
    driver: local
    driver_opts:
      type: 'none'
      o: 'bind'
      device: 'media'

networks:
  backend_network:
    driver: bridge
  nginx_network:
    name: "nginx_network"
    external: true

**Вот мой Dockerfile контейнера db**:
FROM postgres:16.4

ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
ENV REPLICATOR_PASSWORD=${REPLICATOR_PASSWORD}

RUN apt-get update && apt-get install -y psmisc

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

EXPOSE 5432

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

CMD ["postgres"]

**Вот entrypoint.sh для db**:
#!/bin/bash
set -e

SLAVE_IP_ADDRESS=${SLAVE_IP_ADDRESS:-194.87.190.180}

function update_pg_hba_conf() {
  while [ ! -f "$PGDATA/pg_hba.conf" ]; do
    echo "Waiting for pg_hba.conf to be created..."
    sleep 1
  done

  if ! grep -q "host replication replicator ${SLAVE_IP_ADDRESS}/32 md5" "$PGDATA/pg_hba.conf"; then
    echo "host replication replicator ${SLAVE_IP_ADDRESS}/32 md5" >> "$PGDATA/pg_hba.conf"
    echo "Added replication entry to pg_hba.conf."
  else
    echo "Replication entry already exists in pg_hba.conf."
  fi
}

if [ ! -s "$PGDATA/PG_VERSION" ]; then
  echo "Initializing database..."

  docker-entrypoint.sh postgres &

  until pg_isready -U "$POSTGRES_USER"; do
    echo "Waiting for PostgreSQL to start..."
    sleep 1
  done

  psql -U "$POSTGRES_USER" -d postgres -c "CREATE ROLE replicator WITH REPLICATION LOGIN PASSWORD '$REPLICATOR_PASSWORD';"

  psql -U "$POSTGRES_USER" -d postgres <<EOSQL
    GRANT SELECT ON ALL TABLES IN SCHEMA public TO replicator;
    GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO replicator;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO replicator;
    ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO replicator;
    GRANT USAGE ON SCHEMA public TO replicator;
EOSQL

  update_pg_hba_conf

  killall postgres
  sleep 5

  echo "listen_addresses = '*'" >> "$PGDATA/postgresql.conf"
  echo "wal_level = logical" >> "$PGDATA/postgresql.conf"
  echo "max_wal_senders = 10" >> "$PGDATA/postgresql.conf"
  echo "max_replication_slots = 10" >> "$PGDATA/postgresql.conf"

else
  echo "Database already initialized. Skipping initialization."

  update_pg_hba_conf

  if ! grep -q "^listen_addresses = '\*'" "$PGDATA/postgresql.conf"; then
    echo "Setting listen_addresses to '*' in postgresql.conf"
    echo "listen_addresses = '*'" >> "$PGDATA/postgresql.conf"
  fi

  if ! grep -q "^wal_level = logical" "$PGDATA/postgresql.conf"; then
    echo "Setting wal_level to logical in postgresql.conf"
    echo "wal_level = logical" >> "$PGDATA/postgresql.conf"
  fi

  if ! grep -q "^max_wal_senders = 10" "$PGDATA/postgresql.conf"; then
    echo "Setting max_wal_senders to 10 in postgresql.conf"
    echo "max_wal_senders = 10" >> "$PGDATA/postgresql.conf"
  fi

  if ! grep -q "^max_replication_slots = 10" "$PGDATA/postgresql.conf"; then
    echo "Setting max_replication_slots to 10 in postgresql.conf"
    echo "max_replication_slots = 10" >> "$PGDATA/postgresql.conf"
  fi
fi

exec docker-entrypoint.sh postgres

Подскажи, пожалуйста, как сделать так, чтобы я мог накатить все миграции для второй базы данных (которая slave), если я работаю с Django проектом?