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 1jv1gc-0000nu-Vg for pgsql-general@arkaria.postgresql.org; Mon, 13 Jul 2020 16:52:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jv1gb-0007rM-TF for pgsql-general@arkaria.postgresql.org; Mon, 13 Jul 2020 16:52:13 +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 1jv1gb-0007rF-Ah for pgsql-general@lists.postgresql.org; Mon, 13 Jul 2020 16:52:13 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jv1gZ-0004HM-2C for pgsql-general@lists.postgresql.org; Mon, 13 Jul 2020 16:52:12 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 12EA8226AB; Mon, 13 Jul 2020 18:52:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1594659129; bh=J2QBdBzpN9FLxzKBaKnO7l9pbmLlu2YBYb9oZ0Y6rjw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cCtPLZjfpjYJSgS0bpmKvD+Vdpjmfok2CdaLxiOfjPLe/JDaVWMdUJsC7mM8lD7ng M7Uy2Ns1rslsocOBZUCSAVdgefIiJ35pEhXdFdOfyOr4SdrMc1JC7yUsE9pX8HfHWb fyobvt+w6lY+46XbeRnolvkUqSSeJ7/DCBuMcLJg= Date: Mon, 13 Jul 2020 18:52:08 +0200 From: Jehan-Guillaume de Rorthais To: James Sewell Cc: "pgsql-generallists.postgresql.org" Subject: Re: Safe switchover Message-ID: <20200713185208.2f850d3e@firost> In-Reply-To: References: Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 10 Jul 2020 10:05:52 +1000 James Sewell wrote: > Hi all, >=20 > I=E2=80=99m trying to work out a procedure for a safe zero data loss swit= chover > under (high) load, which allows the old master to be reconnected without > the use of pgrewind. >=20 > Would the following be sane? >=20 > - open connection to database > - smart shutdown master > - terminate all other connections > - wait for shutdown (archiving will finish) > - Identify last archived WAL file name (ensure it=E2=80=99s on backup ser= ver.) > - wait till a standby has applied this WAL > - promote that standby > - attach old master to new master During graceful shutdown (smart or fast), the primary is waiting for standb= y to catchup with replication before the full stop. But nothing will save you if= the designated standby disconnect by itself during the shutdown procedure. I usually use: - shutdown the primary - use pg_controldata to check its last redo checkpoint=20 and/or use pg_waldump to find its shutdown checkpoint - check logs on standby and replication status and make sure it received the shutdown checkpoint (pg_waldump on the standby and/or last received lsn) - promote the standby - setup the old primary as standby - start the old primary as new standby. Regards,