pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrus <kobruleht2@hot.ee>
To: Paul Förster <paul.foerster@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How to start slave after pg_basebackup. Why min_wal_size and wal_keep_segments are duplicated
Date: Mon, 1 Jun 2020 13:26:12 +0300
Message-ID: <D1C2C9E316ED41149A8D2C5751797621@dell2> (raw)
In-Reply-To: <8BAE2216-8683-4DEE-8529-14457F2775BC@gmail.com>
References: <26EC9619620649D1B55C9C95811E4ADB@dell2>
	<B7E0C7C6-865B-4632-B10A-11B2E468D40A@gmail.com>
	<69FF4F48E6FE4A63A2EBD820C5B2B3A3@dell2>
	<EBFD984A-90DC-4C6A-A6D8-233F08472C31@gmail.com>
	<DC1BA2AF303246A3A349C8B0F8B01E1D@dell2>
	<8BAE2216-8683-4DEE-8529-14457F2775BC@gmail.com>

Hi!

> How to create replication server ?
>I always do it this way and it work for me:
>$ pg_basebackup -h ${PGHOST} -p ${PGPORT} -U replicator -W -R -D ${PGDATA} -P -v -Fp -Xs
>After that, I edit ${PGDATA}/postgresql.conf and (w/ PostgreSQL 11 and older ${PGDATA}/recovery.conf) to make it do what I want and
>then I just launch it:
>$ pg_ctl start

My script does the same thing as your comands.

From that moment onward, it replicates and applies to the replica. Checks in pg_stat_replication on the master and
>pg_stat_wal_receiver on the replica >confirm that. They also show the WAL switches.
>To provoke a WAL switch I always do:
>postgres=# checkpoint; select pg_switch_wal();
>CHECKPOINT
> pg_switch_wal
>I just don't understand what you're trying to achieve here.

I want to create replication server.

>My guess is, you want to stop and backup the old database cluster,

Old cluster is empty, from initdb. Backup is not needed

>then create a new one in its old directory, right?

pg_basebackup creates new main directory.

>In this case, you probably need to change your script to something like this:
>PGHOST=remote.example.com
>PGPASSWORD=mypass
>PGUSER=replikaator
>PGDATA=/var/lib/postgresql/12/main
>export PGHOST PGPASSWORD PGUSER PGDATA
>/etc/init.d/postgresql stop
>mv ${PGDATA} /var/lib/postgresql/12/mainennebaasbakuppi
>pg_basebackup -h ${PGHOST} -p ${PGPORT} -U ${PGUSER} -W -R -D ${PGDATA} -P -v -Fp -Xs
>/etc/init.d/postgresql start

pg_basebackup uses environment varuables if not specified in command line. So my script does the same thing.

>Note that my invocation of pg_basebackup asks for the replicator password. This is intended. You'd probably want to change that.
>Also, no need to play around with ownership and permissions. Do it as "postgres", not as "root".

I tried

sudo --user=postgres pg_basebackup ....

but got error

could not change directory to "/root": Permission denied

Andrus.






view thread (17+ messages)  latest in thread

Message-ID: <D1C2C9E316ED41149A8D2C5751797621@dell2>
Permalink:  ../D1C2C9E316ED41149A8D2C5751797621@dell2/
Also on:    postgresql.org/message-id/D1C2C9E316ED41149A8D2C5751797621@dell2

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: kobruleht2@hot.ee, paul.foerster@gmail.com
  Subject: Re: How to start slave after pg_basebackup. Why min_wal_size and wal_keep_segments are duplicated
  In-Reply-To: <D1C2C9E316ED41149A8D2C5751797621@dell2>
  References: <26EC9619620649D1B55C9C95811E4ADB@dell2> <B7E0C7C6-865B-4632-B10A-11B2E468D40A@gmail.com> <69FF4F48E6FE4A63A2EBD820C5B2B3A3@dell2> <EBFD984A-90DC-4C6A-A6D8-233F08472C31@gmail.com> <DC1BA2AF303246A3A349C8B0F8B01E1D@dell2> <8BAE2216-8683-4DEE-8529-14457F2775BC@gmail.com> <D1C2C9E316ED41149A8D2C5751797621@dell2>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox