【发布时间】:2019-09-02 14:26:13
【问题描述】:
滚动到底部查看更新
这是我第一次在已经复制到服务器的生产服务器上配置复制。我正在添加一个额外的服务器。复制在现有环境中工作,但我添加的附加服务器不工作。由于我不想破坏现有的复制,因此我在主服务器上为附加服务器创建了一个新用户。这是 master 和 slave 上的 9.3.5 版本。
psql -c "CREATE USER rep REPLICATION LOGIN CONNECTION LIMIT 1 ENCRYPTED PASSWORD 'yourpassword';"
在slave上我创建了一个recovery文件,放到data目录下
standby_mode = 'on'
primary_conninfo = 'host=master_IP_address port=5432 user=rep
password=yourpassword'
trigger_file = '/tmp/postgresql.trigger.5432'
在主服务器上,我开始了初始备份。
psql -c "select pg_start_backup('initial_backup');"
通过 rsync 复制数据。
rsync -cva --inplace --exclude=*pg_xlog* /var/lib/postgresql/9.1/main/ slave_IP_address:/var/lib/postgresql/9.1/main/
rsync 完成后,我发出以下命令。
psql -c "select pg_stop_backup();"
主服务器 - posgresql.conf
listen_addresses = '*'
max_connections = 1000
unix_socket_directories = ''
shared_buffers = 1024MB
temp_buffers = 1024MB
work_mem = 64MB
maintenance_work_mem = 512MB
max_stack_depth = 31MB
wal_level = hot_standby
wal_buffers = -1
checkpoint_segments = 512
checkpoint_timeout = 1h
# - Archiving -
archive_mode = on
archive_command = 'cd .'
max_wal_senders = 5
主服务器 - pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/8 trust
host all all 192.168.10.10/32 trust
host all all ny-node0.xxx.net trust
# below is the existing replication server that works.
host all all ny-node1.xxx.net trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication postgres trust
host replication postgres 127.0.0.1/8 trust
host replication postgres ny-node1.xxx.net trust
host replication rep IP-OF-NEW-SLAVE/32 trust
host replication postgres IP-OF-MASTER/32 trust
从属 postgresql.conf
listen_addresses = '*'
max_connections = 100
shared_buffers = 128MB
wal_level = hot_standby
archive_command = 'cd .'
logfile segment
max_wal_senders = 1
hot_standby = on
hot_standby_feedback = on
wal_receiver_timeout = 60s
log_destination = 'stderr'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_timezone = 'UTC'
datestyle = 'iso, mdy'
timezone = 'UTC'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
从机的pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres md5
host replication rep IP-OF-MASTER/32 trust
#host replication postgres ::1/128 md5
我在 master 和 slave 上重新启动了 postgres,当我在 master 上创建数据库时,它不会复制到新的 slave。
我取得了一些进展(更新)
我调整了从属服务器上的 pg_hba.conf,只留下了与我为复制创建的新用户关联的行,称为“rep”。
#local replication rep md5
host replication rep ip_of_slave/32 trust
host replication rep ip_of_master/32 trust
我还调整了我的 recovery.conf 并将其放在数据目录中。 由于我主从之间是信任关系,所以我把recovery.conf中的密码去掉了。
standby_mode = 'on'
primary_conninfo = 'host=ip_of_master port=5432 user=rep'
trigger_file = '/tmp/postgresql.trigger.5432'
现在我的日志显示:
LOG: database system was shut down in recovery at 2019-09-02 20:02:04 UTC
LOG: entering standby mode
LOG: contrecord is requested by 26/78000028
LOG: started streaming WAL from primary at 26/78000000 on timeline 7
LOG: contrecord is requested by 26/78000028
FATAL: terminating walreceiver process due to administrator command
LOG: contrecord is requested by 26/78000028
LOG: contrecord is requested by 26/78000028
LOG: contrecord is requested by 26/78000028
LOG: contrecord is requested by 26/78000028
LOG: contrecord is requested by 26/78000028
【问题讨论】:
-
你知道 Postgres 9.3 是 no longer supported 吗?您应该尽快计划升级。
标签: postgresql postgresql-9.3 database-replication