</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-r</option></term>
+ <listitem>
+ <para>
+<!--
+ Use <command>pg_rewind</command> command in recovery script
+ (basebackup.sh). If the command fails, switch to use ordinal
+ rsync command. In certain cases recovery
+ using <command>pg_rewind</command> is much faster than rsync
+ since it does not copy whole database cluster.
+-->
+リカバリスクリプト(basebackup.sh)中で<command>pg_rewind</command>を使います。
+このコマンドが失敗すると、通常のrsyncを使います。
+<command>pg_rewind</command>は、データベースクラスタのすべてをコピーしないので、rsyncに比べてずっと高速になることがあります。
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
</refsect1>
If "true", in streaming replication mode, use replication slot instead
of archive. This brings the same effect as "-s" option is specified.
-->
-ストリーミングレプリケーション環境に置いて、この環境変数が"true"に指定されると、アーカイブログの代わりにレプリケーションスロットを使います。
-これは、"-s"を使ったのと同じ効果をもたらします。
+ストリーミングレプリケーション環境において、この環境変数が"true"に指定されると、アーカイブログの代わりにレプリケーションスロットを使います。
+これは、"-s"オプションを使ったのと同じ効果をもたらします。
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>USE_PG_REWIND</option></term>
+ <listitem>
+ <para>
+<!--
+ If "true", in streaming replication mode, use <command>pg_rewind</command> in basebackup.sh script.
+ This brings the same effect as "-r" option is specified.
+-->
+ストリーミングレプリケーション環境において、この環境変数が"true"に指定されると、basebackup.sh中で<command>pg_rewind</command>を使います。
+これは、"-r"オプションを使ったのと同じ効果をもたらします。
</para>
</listitem>
</varlistentry>
# directory for *testing* purpose.
# Do not use this tool for production environment!
#
-# usage: pgpool_setup [-m r|s|n|l][-n num_clusters][-p base_port][-pg pg_base_port][--no-stop][-d][-s]
+# usage: pgpool_setup [-m r|s|n|l][-n num_clusters][-p base_port][-pg pg_base_port][--no-stop][-d][-s][-r]
# -m s: create an installation as streaming replication mode.
# (the default)
# -m r: create an installation as native replication mode.
# pg_base_port + 1 and so on.
# --no-stop: do not stop pgpool and PostgreSQL after the work
# -d: start pgpool with debug mode
-# -s use replication slot, rather than wal archive.
+# -s: use replication slot, rather than wal archive.
+# -r: use pg_rewind for base backup if possible.
#
# The user run this script will become the PostgreSQL super user as
# well. Current directory must be empty. Assume that appropreate
INITDBARG="--no-locale -E UTF_8 --data-checksums"
# Use replication slot
USE_REPLICATION_SLOT=${USE_REPLICATION_SLOT:-"false"}
+# Use pg_rewind
+USE_PG_REWIND=${USE_PG_REWIND:-"false"}
#-------------------------------------------
# End of configuration section
cat >> $1/$SCRIPT <<'EOF'
#! /bin/sh
psql=__PGBIN__/psql
+pg_rewind=__PGBIN__/pg_rewind
DATADIR_BASE=__DATADIR_BASE__
PGSUPERUSER=__PGSUPERUSER__
PORT=$4
recovery_node=$5
+pg_rewind_failed="true"
+
log=$DATADIR_BASE/log/recovery.log
+echo >> $log
+date >> $log
+EOF
+
+pg_rewind_failed="true"
+
+if [ $USE_PG_REWIND = "true" ];then
+cat >> $1/$SCRIPT <<'EOF'
+
+# First try pg_rewind
+
+# Make backup copy of postgresql.conf since pg_rewind blindly copies
+# $master_db_cluster/postgresql.conf.
+cp $DEST_CLUSTER/postgresql.conf /tmp/
+echo "pg_rewind starts" >> $log
+$pg_rewind -P -D $DEST_CLUSTER --source-server="port=$PORT user=$PGSUPERUSER dbname=postgres" >> $log 2>&1
+if [ $? != 0 ];then
+ # pg_rewind failed. Fallback to rsync.
+ echo "pg_rewind failed. Fall back to rsync" >> $log
+ pg_rewind_failed="true"
+fi
+EOF
+fi
+
+cat >> $1/$SCRIPT <<'EOF'
+if [ $pg_rewind_failed = "true" ];then
$psql -p $PORT -c "SELECT pg_start_backup('Streaming Replication', true)" postgres
-echo "source: $master_db_cluster dest: $DEST_CLUSTER" > $log
+echo "source: $master_db_cluster dest: $DEST_CLUSTER" >> $log
rsync -C -a -c --delete --exclude postgresql.conf --exclude postmaster.pid \
--exclude postmaster.opts --exclude pg_log \
mkdir $DEST_CLUSTER/pg_xlog
chmod 700 $DEST_CLUSTER/pg_xlog
rm $DEST_CLUSTER/recovery.done
+fi
EOF
if [ $USE_SLOT = "true" ];then
fi
cat >> $1/$SCRIPT <<'EOF'
+if [ $pg_rewind_failed = "true" ];then
$psql -p $PORT -c "SELECT pg_stop_backup()" postgres
+fi
+
+if [ $pg_rewind_failed = "false" ];then
+ cp /tmp/postgresql.conf $DEST_CLUSTER/
+fi
EOF
#-------------------------------------------
################################################################################
function usage()
{
- echo "usage: $0 [-m r|s|n|l|y] [-n num_clusters] [-p base_port] [-pg pg_base_port][--no-stop] [-d] [-s]";exit 1
+ echo "usage: $0 [-m r|s|n|l|y] [-n num_clusters] [-p base_port] [-pg pg_base_port][--no-stop] [-d] [-s] [-r]";exit 1
}
#-------------------------------------------
# Argument check
-# usage: $0 [-m r|s|n][-n num_clusters][-p base_port][-pg pg_base_port][--no-stop][-d]
+# usage: $0 [-m r|s|n][-n num_clusters][-p base_port][-pg pg_base_port][--no-stop][-d][-s][-r]
#-------------------------------------------
#
# default mode is streaming replication mode
MODE="s"
NO_STOP="false"
-USE_SLOT="false"
while [ $# -gt 0 ]
do
NO_STOP="true"
elif [ $1 = "-d" ];then
PGPOOLDEBUG="true"
- shift;
elif [ $1 = "-s" ];then
- USE_SLOT="true"
+ USE_SLOT="true"
+ elif [ $1 = "-r" ];then
+ USE_PG_REWIND="true"
elif [ $1 = "--help" -o $1 = "-o" ];then
usage
exit
if [ a$USE_REPLICATION_SLOT = a"true" ];then
USE_SLOT="true"
fi
+
+# If USE_PG_REWIND is provided as an environment variable, turn on -r
+if [ a$USE_PG_REWIND = a"true" ];then
+ USE_PG_REWIND="true"
+fi
+
#-------------------------------------------
# Make sure that current directory is empty
#-------------------------------------------