了解如何使用 pg_receivewal 将 PostgreSQL 的 Write Ahead Log (WAL) 存档到单独的服务器。这可能是存档您的 WAL 文件的最有效方法之一。
本教程假设您已经在主服务器和复制版 PostgreSQL 服务器之间设置了流式复制。如果需要先设置它,请通过本教程运行。
# Assumes Replication is already setup as follows:
# Primary DB cluster called "main" on port 5432
# Replica DB cluster called "replica" on port 5433
# setup directory to receive WAL files
sudo su - postgres
mkdir /var/lib/postgresql/pg_log_archive/archiver -p
ls /var/lib/postgresql/pg_log_archive/
# create replication slot for wal receiver
psql -c "select * from pg_create_physical_replication_slot('archiver');"
psql -c "select * from pg_replication_slots;"
# start pg_receivewal command
pg_receivewal \
-D /var/lib/postgresql/pg_log_archive/archiver \
-S archiver \
-Z 0 \
-h /var/run/postgresql \
-p 5432 \
-U rep_user \
-w \
-v
# check status of slots
psql -c "select * from pg_replication_slots;"
# archive the logs
psql -c "select pg_switch_wal();" # -- pg_switch_xlog();
# check directories
ls /var/lib/postgresql/pg_log_archive/main
ls /var/lib/postgresql/pg_log_archive/archiver

511

被折叠的 条评论
为什么被折叠?



