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 1m8hGE-00018u-6i for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jul 2021 10:58:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m8hGD-0004Nk-0I for pgsql-hackers@arkaria.postgresql.org; Wed, 28 Jul 2021 10:58:01 +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 1m8hGC-0004Nc-Ml for pgsql-hackers@lists.postgresql.org; Wed, 28 Jul 2021 10:58:00 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m8hGA-0005VI-AP for pgsql-hackers@lists.postgresql.org; Wed, 28 Jul 2021 10:57:59 +0000 Received: by mail-wm1-x32b.google.com with SMTP id n28-20020a05600c3b9cb02902552e60df56so1339884wms.0 for ; Wed, 28 Jul 2021 03:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; h=from:to:cc:subject:date:message-id:organization:in-reply-to :references:mime-version:content-transfer-encoding; bh=DLAU3Fm0Q2WTxiJ1ORfYWGVHExQw17rkaRKB8/XviMY=; b=VQ9S2sBHPJFd7eCIuyjSTG8C9mzTOPusmYqUXwN4tiz96zboTazEfZyDjWTxGYlp/C 6agKdeS0WtJoxIpnpd4LjiRFI1Tyx6ppjHE1gwJZEOr5y0doaRVmal2v9dPNkEQe2p3r guC8nkK8Nb+XzllpOKUnw3gobZPoLGlbzdYRw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :in-reply-to:references:mime-version:content-transfer-encoding; bh=DLAU3Fm0Q2WTxiJ1ORfYWGVHExQw17rkaRKB8/XviMY=; b=bzxEq34EhSB5Oj6hFhUXRtZfA2qYkNjQAPQ/oOJH3nJbj536FsX6Ye3c1gyzKPWIsZ NwczbPIWMQeAKlpNJild8Tu8Oh5igu57uHTvPxOh/nGnukOD/8YKrZEDU+jC3Cc2C/oV qVs1jhWaEzdiLl3NqaT4gyL8UIoX61PR/fmB6eh0MtVEw+W4gr2yKA3IzafAnb5ufen4 4wPjz5ClTiTkOPZarxRlvkT/ohY+osVCtRQht5cr40aUwJueygr4kcW3SOWgeYtFPiAJ WKVEqPdYvCKdNk4++M4YLTBmbzIHEyUuDezTY2lYQG6tkBzOG39KCxUtbJB7l3CtN0z0 xkDg== X-Gm-Message-State: AOAM533IOpavuET3O20b7HzZ78rCn2A4GAmZSIzc/QYs/OFzbTmbSx4c YofU4p1HSOexPFgQoW39TJkvgQ== X-Google-Smtp-Source: ABdhPJwO7ypZFGqljZgl8I4R5kddpE4+kKmXDm8kTmPHhJNYlAMSyU3sHoJPGBhMJtrky8PNAfhzvQ== X-Received: by 2002:a1c:1f51:: with SMTP id f78mr11195244wmf.37.1627469875853; Wed, 28 Jul 2021 03:57:55 -0700 (PDT) Received: from aivenronan.localnet (static-176-158-121-96.ftth.abo.bbox.fr. [176.158.121.96]) by smtp.gmail.com with ESMTPSA id p5sm5589237wme.2.2021.07.28.03.57.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 03:57:55 -0700 (PDT) From: Ronan Dunklau To: Kyotaro Horiguchi Cc: pgsql-hackers@lists.postgresql.org Subject: Re: pg_receivewal starting position Date: Wed, 28 Jul 2021 12:57:39 +0200 Message-ID: <15651763.8WXi7s64xO@aivenronan> Organization: aiven In-Reply-To: <20210728.152230.2032903346246847782.horikyota.ntt@gmail.com> References: <18708360.4lzOvYHigE@aivenronan> <20210728.152230.2032903346246847782.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Le mercredi 28 juillet 2021, 08:22:30 CEST Kyotaro Horiguchi a =E9crit : > At Tue, 27 Jul 2021 07:50:39 +0200, Ronan Dunklau > wrote in > > Hello, > >=20 > > I've notived that pg_receivewal logic for deciding which LSN to start > >=20 > > streaming at consists of: > > - looking up the latest WAL file in our destination folder, and resume > > from > >=20 > > here > >=20 > > - if there isn't, use the current flush location instead. > >=20 > > This behaviour surprised me when using it with a replication slot: I was > > expecting it to start streaming at the last flushed location from the > > replication slot instead. If you consider a backup tool which will take > > pg_receivewal's output and transfer it somewhere else, using the > > replication slot position would be the easiest way to ensure we don't > > miss WAL files. > >=20 > > Does that make sense ? > >=20 > > I don't know if it should be the default, toggled by a command line fla= g, > > or if we even should let the user provide a LSN. >=20 > *I* think it is completely reasonable (or at least convenient or less > astonishing) that pg_receivewal starts from the restart_lsn of the > replication slot to use. The tool already decides the clean-start LSN > a bit unusual way. And it seems to me that proposed behavior can be > the default when -S is specified. >=20 As of now we can't get the replication_slot restart_lsn with a replication= =20 connection AFAIK. This implies that the patch could require the user to specify a maintenance= =2Ddb=20 parameter, and we would use that if provided to fetch the replication slot= =20 info, or fallback to the previous behaviour. I don't really like this appro= ach=20 as the behaviour changing wether we supply a maintenance-db parameter or no= t=20 is error-prone for the user. Another option would be to add a new replication command (for example=20 ACQUIRE_REPLICATION_SLOT ) to set the replication slot as the=20 current one, and return some info about it (restart_lsn at least for a=20 physical slot). I don't see any reason not to make it work for logical replication connecti= ons=20 / slots, but it wouldn't be that useful since we can query the database in= =20 that case. Acquiring the replication slot instead of just reading it would make sure t= hat=20 no other process could start the replication between the time we read the=20 restart_lsn and when we issue START_REPLICATION. START_REPLICATION could th= en=20 check if we already have a replication slot, and ensure it is the same one = as=20 the one we're trying to use.=20 =46rom pg_receivewal point of view, this would amount to: - check if we currently have wal in the target directory. - if we do, proceed as currently done, by computing the start lsn and=20 timeline from the last archived wal - if we don't, and we have a slot, run ACQUIRE_REPLICATION_SLOT. Use the= =20 restart_lsn as the start lsn if there is one, and don't provide a timeline - if we still don't have a start_lsn, fallback to using the current serve= r=20 wal position as is done.=20 What do you think ? Which information should we provide about the slot ? =2D-=20 Ronan Dunklau