Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtD3f-0003Kf-Ts for pgsql-general@arkaria.postgresql.org; Mon, 11 Feb 2019 14:59:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtD3e-0006e7-M1 for pgsql-general@arkaria.postgresql.org; Mon, 11 Feb 2019 14:59:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtD3e-0006dL-2g for pgsql-general@lists.postgresql.org; Mon, 11 Feb 2019 14:59:42 +0000 Received: from mail-it1-x130.google.com ([2607:f8b0:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtD3b-0004QW-4O for pgsql-general@lists.postgresql.org; Mon, 11 Feb 2019 14:59:40 +0000 Received: by mail-it1-x130.google.com with SMTP id a6so26823299itl.4 for ; Mon, 11 Feb 2019 06:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:in-reply-to:message-id:to:date:references:from; bh=OizP9Olhlp9xlYhH7BaV+IUiETZA6JoJdOWzSYjxQ9o=; b=l2vRrBcml/UvLvvPp1HVYjPCLDBZe5G++YBQzLyJX8PydVo5BSKR6kudxex6NteeEc DKeEyj7MjMbnwxfPKLzhxqPPDZ7E+WzNUY+Hdjtjhr66x0AAhW755sNjpXIZXU59u4J0 QTftStLiZOagFDAAIT2h9wnFMSeBy7Y92gsG0gUdYSN4htRgn/h9DgixLzcQpWg4IoSy enfUE9jZka0QLE5b+4kjfw2iIGPq5e8w84hb1OYFCibDlCIBe7bVYc7YgruSDj6V1yuo AIv43xN1/j/M1V+YSDonCEQb08o/R9Ju3V/t66Gkfz5tIlJdB1EW6Id0lck0jicwvoXl jOag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:in-reply-to:message-id:to :date:references:from; bh=OizP9Olhlp9xlYhH7BaV+IUiETZA6JoJdOWzSYjxQ9o=; b=PZhybK03OBt56K+qH37TiHq+qh2NNklVpT8i5wCcNt2ZVU4/4PBEh6SsyQ9wEb9g9l ntBTJcIREIfn9efvQy04gI54+6ZWmVKKC+kbj9gIETy3pbXrsuTB2i2vWDrEE1tbAONw odZAuSYAnCetOAv0+dD3eybweUDP24ShqO0nzYjfMLJ2fLkMoHm6yMizFPb6lcmDkIQN MSZ9aQn4+q7tGM2qYO6boItmyIh3ZWF+2et88nZDlu0p5KwB6+HPbEBuQaWgx3LXN1XP w4zYV3omjBfzOrgMwP6PlLLV9cRZuo6d4PoPfuuLnHXx89ZFfh82jFspPbzjH973UGZH S9Fw== X-Gm-Message-State: AHQUAuZtYE4vgMYMAOywrWWumM8dkDv3BMaQ7XYj/xMcIlB8mmBTjrPY FsO+5N2ra1daV/MEovJP4wt7bt70 X-Google-Smtp-Source: AHgI3IbgKUcQv8cp9tzXlhgMyYUn+yFIUGK4SkWF47XXJIzXNDF01bRiwf95cA320U8bSq+UfI2ItQ== X-Received: by 2002:a24:cb02:: with SMTP id u2mr5002070itg.87.1549897177934; Mon, 11 Feb 2019 06:59:37 -0800 (PST) Received: from localhost (135.166.192.35.bc.googleusercontent.com. [35.192.166.135]) by smtp.gmail.com with ESMTPSA id p2sm4645144iog.84.2019.02.11.06.59.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 06:59:37 -0800 (PST) Mime-Version: 1.0 Subject: Re: Promote replica before being able to accept connections In-Reply-To: <950236c827942575381949675e8ad709a38ca771.camel@cybertec.at> Message-ID: <5c618d9da914d363cd000005@polymail.io> X-Polymail-Id: <5c618d9da914d363cd000005@polymail.io> To: "Laurenz Albe" , "pgsql-generallists.postgresql.org" Date: Mon, 11 Feb 2019 06:59:27 -0800 References: <950236c827942575381949675e8ad709a38ca771.camel@cybertec.at> X-Mailer: Polymail From: =?UTF-8?q?Mart=C3=ADn_Fern=C3=A1ndez?= Content-Type: multipart/alternative; boundary=ed9e021089f9160ef374daa775301abfdb98335a0951c5feadf970714e4a List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ed9e021089f9160ef374daa775301abfdb98335a0951c5feadf970714e4a Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Laurenz, That makes sense!=C2=A0 Thanks for the quick reply Best, Mart=C3=ADn On Mon, Feb 11th, 2019 at 7:55 AM, Laurenz Albe = wrote: >=20 >=20 >=20 > Mart=C3=ADn Fern=C3=A1ndez wrote: > > We have a 9.2 pg cluster and we are in the process of rebuilding a > master database in our staging environment. > > In order to achieve the latter goal, we are restoring our staging > database using pg_basebackup against one > > of our production replicas. > > > > pg_basebackup has completed and the staging database is configured in > hot_standby mode, recovering from > > the WAL archive. The database has not reached the point were it can > accept connections yet, still > > investing WAL files. > > > > What we are not sure about is, can we attempt promoting the database as > a master instance before it can > > accept connections ? We don=C2=B4t care if the staging database is a fe= w days > behind the production environment, > > that is something acceptable in our use case, we just want to promote i= t > as soon as we can. >=20 > The earliest time to which you can recover is the end of the backup. >=20 > Until recovery has reached that point, the database is not consistent > (that's the "consistent recovery state" the logs are talking about). >=20 > You cannot connect to the recovering database or promote it before you > reach that point, so you have to wait until you can connectio to the > database > before you can promote it. >=20 > Yours, > Laurenz Albe > -- > Cybertec | https://www.cybertec-postgresql.com >=20 >=20 >=20 >=20 > --ed9e021089f9160ef374daa775301abfdb98335a0951c5feadf970714e4a Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 3D""
Laurenz,

That makes sense! 
Thanks for the quick reply

Best,

Mart=C3=ADn

On Mon, Feb 11th, 2019 at 7:55 AM, Laurenz Albe <laure= nz.albe@cybertec.at> wrote:

Mart=C3=ADn Fern=C3=A1ndez wrote:
> We have a 9.2 pg cluster and we are in the process of rebuilding a= master database in our staging environment.
> In order to achieve the latter goal, we are restoring our staging = database using pg_basebackup against one
> of our production replicas.=20
>=20
> pg_basebackup has completed and the staging database is configured= in hot_standby mode, recovering from
> the WAL archive. The database has not reached the point were it ca= n accept connections yet, still
> investing WAL files.
>=20
> What we are not sure about is, can we attempt promoting the databa= se as a master instance before it can
> accept connections ? We don=C2=B4t care if the staging database is= a few days behind the production environment,
> that is something acceptable in our use case, we just want to prom= ote it as soon as we can.

The earliest time to which you can recover is the end of the backup.

Until recovery has reached that point, the database is not consistent
(that's the "consistent recovery state" the logs are talking about).

You cannot connect to the recovering database or promote it before you
reach that point, so you have to wait until you can connectio to the da= tabase
before you can promote it.

Yours,
Laurenz Albe
--=20
Cybertec | https://www.cybertec-postgresql.= com


--ed9e021089f9160ef374daa775301abfdb98335a0951c5feadf970714e4a--