Det*_*tox 4 postgresql replication
我的复制服务器将无法启动。我已按照此处的说明进行操作:http :
//opensourcedbms.com/dbms/setup-replication-with-postgres-9-2-on-centos-6redhat-el6fedora/
以及包括 Postgres Wiki 在内的其他几个地方,因为它们都有相同的信息。
这是发生的事情:
我对/9.2/data
文件夹进行完整备份并将其移动到复制/从服务器,解压缩它。我可以启动 PostgreSQL 和 pgAdmin 并毫无问题地访问所有数据。
然后我转到有关编辑从服务器的pg_hba.conf
和的说明postgresql.conf
。我尝试启动它,但它失败了(红色错误 [失败]。我在任何地方都找不到任何日志来提示我为什么。
我什至验证postmaster.pid
了数据文件夹中没有。
另外,我找不到任何日志文件。我需要在配置中“激活”一个日志文件吗?
因此,如果有人想对我含糊的描述一无所知,我很想听听任何建议。如果有帮助,我可以将我的 conf 文件放在 pastebin 上。
bma*_*bma 18
首先,确定 Postgresql 数据目录和WAL
(Write Ahead Log)目录的挂载点。为提高性能,$PGDATA
和pg_xlog
目录应位于不同的卷上。
在下面的示例中,它们的定义如下:
archive_command
主机上发送到的地方。理想情况下,位于与 $PGDATA 不同的卷上。假设:
mkdir -p /pgdata/WAL_Archive
chown postgres:postgres /pgdata/WAL_Archive
Run Code Online (Sandbox Code Playgroud)
$PGDATA/postgresql.conf
wal_level = hot_standby
archive_mode = on
## /pgdata/WAL_Archive is a staging directory on the slave
archive_command = 'rsync -W -az %p postgres@$SLAVE_IP_HERE:/pgdata/WAL_Archive/'
max_wal_senders = 5
wal_keep_segments = 5000 # If you have the room, to help the pg_basebackup
# not fail due to WAL segments being removed from master.
# For clusters will very little traffic, 100 is probably fine
Run Code Online (Sandbox Code Playgroud)
psql -U postgres -d postgres -c "CREATE USER replication WITH replication ENCRYPTED PASSWORD 'changeme' LOGIN"
Run Code Online (Sandbox Code Playgroud)
# TYPE DATABASE USER ADDRESS METHOD
#hostssl replication replication $SLAVE_IP_HERE/32 md5
host replication replication $SLAVE_IP_HERE/32 md5
Run Code Online (Sandbox Code Playgroud)
例如:
pg_ctl -D $PGDATA restart -m fast
## The master cluster MUST be restarted before the pg_basebackup command is executed.
Run Code Online (Sandbox Code Playgroud)
## --host=IP_OF_MASTER -> The master's IP
## --pgdata=$PGDATA -> The slave's $PGDATA directory
## --xlog-method=stream -> Opens a second connection to the master to stream the WAL segments rather than pulling them all at the end
## --password will prompt for the replication role's password
## Without compression, "stream" gets the changes via the same method as Streaming Replication
time pg_basebackup --pgdata=$PGDATA --host=IP_OF_MASTER --port=5432 --username=replication --password --xlog-method=stream --format=plain --progress --verbose
## Alternate version with compression, note "--xlog --gzip --format=tar"
#time pg_basebackup --pgdata=$PGDATA --host=IP_OF_MASTER --port=5432 --username=replication --password --xlog --gzip --format=tar --progress --verbose
Run Code Online (Sandbox Code Playgroud)
hot_standby = on #off # "on" allows queries during recovery
max_standby_archive_delay = 15min # max delay before canceling queries,
# set to hours if backups will be taken from here
max_standby_streaming_delay = 15min # max delay before canceling queries
hot_standby_feedback = on #off
Run Code Online (Sandbox Code Playgroud)
$PGDATA/recovery.conf
:standby_mode = on
## To promote the slave to a live database, issue "touch /tmp/promote_db"
## Warning: If multiple slaves share the same /tmp/ directory,
## then the trigger file must be named uniquely, else multiple slaves
## could attempt to be promoted in the presence of the trigger file.
trigger_file = '/tmp/promote_db_slave'
## Host can be the master's IP or hostname
primary_conninfo = 'host=IP_OF_MASTER port=5432 user=replication password=CHANGEME'
## Log the standby WAL segments applied to a standby.log file
## TODO: Add the standby.log to a log rotator
## The paths must be explicitly defined, including the path to pg_archivecleanup
restore_command = 'cp /pgdata/WAL_Archive/%f "%p" 2>>/pgdata/9.3/data/pg_log/standby.log'
## XXX: If multiple slaves share the staging WAL directory,
## do not use pg_archivecleanup as WAL segments could be removed
## before being applied to other slaves.
archive_cleanup_command = '/usr/pgsql-9.3/bin/pg_archivecleanup /pgdata/WAL_Archive %r'
## On hot standby clusters, set to 'latest' to switch to the newest timeline in the archive
recovery_target_timeline = 'latest'
Run Code Online (Sandbox Code Playgroud)
pg_ctl -D $PGDATA start
Run Code Online (Sandbox Code Playgroud)
以下是我在一遍又一遍地重新创建备用数据库进行测试时运行的命令。我将它们添加到名为 /root/recreate_standby.sh 的脚本中。以 root 身份运行,但这不是必需的 - 如果您以 postgres 身份运行,则删除“sudo su - postgres -c”命令。
#!/bin/bash
## This script runs on the standby.
## Executed as root, else remove the "sudo - postgres -c" commands.
## Assumes you have a valid recovery.conf saved at
## $PGDATA/../recovery.conf.bkp
export PGDATA=/path/to/data/dir ## Must be set correctly
export PGPORT=5432
export MASTER=192.168.x.x ## IP or host entry for the master Postgresql server
export PGBIN=/usr/pgsql-9.3/bin
service postgresql-9.3 stop -m immediate
if [ $? != 0 ]; then
service postgresql-9.3 start
echo "Could not shut down PostgreSQL. Aborting."
exit 1
fi
rm -rf $PGDATA
if [ $? != 0 ]; then
echo "Could not remove the PostgreSQL $PGDATA dir. Aborting."
exit 1
fi
## If the replication role is not set to "trust" in the master's
## pg_hba.conf file, the password will need to be passed into the command below,
## and "--no-password" will need to be removed or revised to be "--password"
su - postgres -c "$PGBIN/pg_basebackup --pgdata=$PGDATA --host=$MASTER --port=$PGPORT --username=replication --no-password --xlog-method=stream --format=plain --progress --verbose"
su - postgres -c "cp -p $PGDATA/../recovery.conf.bkp $PGDATA/recovery.conf"
service postgresql-9.3 start
su - postgres -c "$PGBIN/pg_isready -U postgres -p $PGPORT -t2"
while [ $? != 0 ]; do
echo "Sleep 1 second, check if slave is up yet. If not, sleep again."
sleep 1;
su - postgres -c "$PGBIN/pg_isready -U postgres -p $PGPORT -t2"
done
su - postgres -c "$PGBIN/psql -d postgres -U postgres -qXc 'select pg_is_in_recovery() as is_pg_in_recovery'"
exit 0
Run Code Online (Sandbox Code Playgroud)
有关更深入的详细信息,请参阅当前的 Postgresql 文档:
归档时间: |
|
查看次数: |
15182 次 |
最近记录: |