<div dir="ltr"><div>So if I install servers from scratch, without any real data yet. <br><br></div>Could I start the 2nd server just by `stream replication`and `promote` - only these two commands instead?<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 14, 2023 at 3:34 PM Bo Peng <<a href="mailto:pengbo@sraoss.co.jp">pengbo@sraoss.co.jp</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
> regarding your latest commit:<br>
> <br>
> <a href="https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob;f=src/sample/scripts/replication_mode_recovery_1st_stage.sample;h=300c30395f9bb51bd15948e3af177d59fb9142fc;hb=7ed589de5f608eabe4c0d8026f9adcce1eedd015" rel="noreferrer" target="_blank">https://git.postgresql.org/gitweb/?p=pgpool2.git;a=blob;f=src/sample/scripts/replication_mode_recovery_1st_stage.sample;h=300c30395f9bb51bd15948e3af177d59fb9142fc;hb=7ed589de5f608eabe4c0d8026f9adcce1eedd015</a><br>
> <br>
> *1) *Is it also applicable to snapshot mode as well? It seems to register<br>
> standby here as a stream replication of the primary<br>
<br>
Yes. replication_mode_recovery_1st_stage.sample and replication_mode_recovery_2nd_stage.sample<br>
are the scripts for isolation snapshot mode.<br>
<br>
In the first stage, using streaming replication to make sure<br>
the standby can receive the WALs which are generated after executing pg_basebackup.<br>
<br>
In the second stage, the standby will be promoted to primary.<br>
<br>
> *2) *There is no "pgpass" or "archivedir" in postgresql, at least to my<br>
> experience:<br>
<br>
These scripts assume you are using archive_mode and .pgpass,<br>
and archive_command copies all WALs to archivedir directory.<br>
It must be manually configured before you start pgpool.<br>
<br>
Please check the prerequisites:<br>
<a href="https://www.pgpool.net/docs/latest/en/html/example-replication-mode.html" rel="noreferrer" target="_blank">https://www.pgpool.net/docs/latest/en/html/example-replication-mode.html</a><br>
<br>
Because they are sample scripts, you need to modify them to<br>
match your PostgreSQL configurations. <br>
If you don't need archive_mode, you can customize the scripts.<br>
<br>
> ARCHIVEDIR=/var/lib/pgsql/archivedir<br>
>     cat > ${RECOVERYCONF} << EOT<br>
> primary_conninfo = 'host=${MAIN_NODE_HOST} port=${MAIN_NODE_PORT}<br>
> user=${REPLUSER} application_name=${DEST_NODE_HOST}<br>
> passfile=''/var/lib/pgsql/.pgpass'''<br>
> recovery_target_timeline = 'latest'<br>
> restore_command = 'scp ${SSH_OPTIONS} ${MAIN_NODE_HOST}:${ARCHIVEDIR} /%f<br>
> %p'<br>
> <br>
> *3) *What does it wait for here? Since it has waited postgresql to finish<br>
> the replication?<br>
<br>
No. "-w" doesn't wait for postgresql to finish recovery.<br>
That is why we need to check if standby catched up primary server.<br>
<br>
> # start target server as a streaming replication standby server<br>
> ssh -T ${SSH_OPTIONS} ${POSTGRESQL_STARTUP_USER}@$DEST_NODE_HOST "<br>
> $PGHOME/bin/pg_ctl -l /dev/null -w -D $DEST_NODE_PGDATA start<br>
> "<br>
> # wait till the standby catches up primary server or<br>
> # $MAX_DURATION seconds passes<br>
> sec=0<br>
> while [ $sec -lt $MAX_DURATION ]<br>
> do<br>
>   sec=`expr $sec + 1`<br>
> <br>
>   result=`psql -h ${MAIN_NODE_HOST} -p ${MAIN_NODE_PORT} -c "SELECT<br>
> sent_lsn = replay_lsn FROM pg_stat_replication where application_name =<br>
> '${DEST_NODE_HOST}'" postgres | sed -n 3p|sed 's/ //'`<br>
> <br>
>   echo "result: $result"<br>
>   if [ "$result" = "t" ];then<br>
>     sec=$MAX_DURATION<br>
>   fi<br>
>   sleep 1<br>
> done<br>
> <br>
> *4)* Did you mean `-U postgres` in the line beginning with `result=` ?<br>
<br>
It is the user who is running PostgreSQL.<br>
In this script it is "postgres" user.<br>
<br>
-- <br>
Bo Peng <<a href="mailto:pengbo@sraoss.co.jp" target="_blank">pengbo@sraoss.co.jp</a>><br>
SRA OSS LLC<br>
TEL: 03-5979-2701 FAX: 03-5979-2702<br>
URL: <a href="https://www.sraoss.co.jp/" rel="noreferrer" target="_blank">https://www.sraoss.co.jp/</a><br>
</blockquote></div>