Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfheW-0008OQ-KD for pgsql-general@arkaria.postgresql.org; Mon, 01 Jun 2020 10:26:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jfheV-0004NV-0j for pgsql-general@arkaria.postgresql.org; Mon, 01 Jun 2020 10:26:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfheU-0004NO-Oz for pgsql-general@lists.postgresql.org; Mon, 01 Jun 2020 10:26:42 +0000 Received: from portal-smtp-out.hot.ee ([194.126.101.125]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfheN-0002I9-Cm for pgsql-general@postgresql.org; Mon, 01 Jun 2020 10:26:41 +0000 Received: from localhost (localhost [127.0.0.1]) by vm-hot-relay10.estpak.ee (Postfix) with ESMTP id C74F01810; Mon, 1 Jun 2020 13:26:31 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at vm-hot-relay10.estpak.ee Received: from portal-smtp-out.hot.ee ([127.0.0.1]) by localhost (vm-hot-relay10.estpak.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id p5jGDXoxlKHn; Mon, 1 Jun 2020 13:26:29 +0300 (EEST) Received: from mail.hot.ee (hot-relayhost2.estpak.ee [213.180.2.80]) by vm-hot-relay10.estpak.ee (Postfix) with ESMTP id 7D99E1D08; Mon, 1 Jun 2020 13:26:29 +0300 (EEST) Received: from dell2 (66-63-196-88.sta.estpak.ee [88.196.63.66]) (Authenticated sender: kobruleht2) by HOT-Relayhost2.estpak.ee (Postfix) with ESMTPSA id 49bBD40wP0z2Hj; Mon, 1 Jun 2020 13:26:27 +0300 (EEST) Message-ID: From: "Andrus" To: =?iso-8859-1?Q?Paul_F=F6rster?= Cc: "pgsql-general" References: <26EC9619620649D1B55C9C95811E4ADB@dell2> <69FF4F48E6FE4A63A2EBD820C5B2B3A3@dell2> <8BAE2216-8683-4DEE-8529-14457F2775BC@gmail.com> In-Reply-To: <8BAE2216-8683-4DEE-8529-14457F2775BC@gmail.com> 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 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 16.4.3528.331 X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3528.331 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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.