- docker-compose exec -it postgres /bin/bash
- vi /var/lib/postgresql/data/pg_hba.conf
host replication replication_user 185.212.194.117/32 md5
- vi /var/lib/postgresql/data/postgresql.conf
wal_level = replica
max_wal_senders = 5
wal_keep_size = 64MB
shared_buffers = 512MB
max_connections = 100
listen_addresses = '*'
OR
shared_buffers = 4GB
work_mem = 128MB
maintenance_work_mem = 2GB
- Write-Ahead Log (WAL) Settings:
wal_buffers = 32MB checkpoint_completion_target = 0.9
- psql -U zabbix -d zabbix_db
CREATE ROLE replica_user WITH REPLICATION LOGIN PASSWORD 'replica_password';
-
Cache Settings in
zabbix_server.conf
:CacheSize=512M HistoryCacheSize=256M HistoryTextCacheSize=128M ValueCacheSize=256M
-
Enable More Preprocessors:
StartPreprocessors=16
-
Database Housekeeping:
- Regularly archive historical data to optimize query performance.
- docker-compose up -d
- docker-compose exec -it postgres /bin/bash -c "rm -rf /var/lib/postgresql/data/*"
- rm -rf ./pgdata/*
- docker compose exec -t postgres pg_basebackup -h 185.82.65.1 -U replica_user -C -S replica_1 -D /var/lib/postgresql/data -Fp -Xs -P -R --wal-method=stream
on master
- psql -U zabbix -d zabbix_db
- SELECT client_addr, state FROM pg_stat_replication;
- CREATE DATABASE students_db;
- \c students_db;
- CREATE TABLE student_details (first_name VARCHAR(15), last_name VARCHAR(15) , email VARCHAR(40) );
- INSERT INTO student_details (first_name, last_name, email) VALUES ('Arthur', 'Spencer', '[email protected]');
- SELECT * FROM student_details;
on slave
- psql -U zabbix -d zabbix_db
- \l
- \c students_db;
- SELECT * FROM student_details;