Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO7yc-001cHK-MY for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2024 03:12:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rO7yb-00GwGd-Gx for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jan 2024 03:12:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO7yb-00GwGU-5C for pgsql-hackers@lists.postgresql.org; Fri, 12 Jan 2024 03:12:57 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rO7yX-0017T4-HM for pgsql-hackers@postgresql.org; Fri, 12 Jan 2024 03:12:55 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3bbbe583e04so3797388b6e.3 for ; Thu, 11 Jan 2024 19:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705029171; x=1705633971; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=S5/cyeiP2kcMjYGDLWfmNOw1sQj0PJsJUjDPVSR0l3E=; b=FDPGbTh4Hk9YTAxcrYnG3SyxbzLwz3cyyPqlJ5i1feK7kKiNM8fDS736JusaIJ9vrn yhHNkJS36OgZu0UM/JDmvrpSJItOBljKxy5ThJMCEJ+t9BBQXiVBIXaEw4zxI5sOeTwe nHUE7zQb0JH3K2sh21THcaR5ih9efv9i2NQhP8Ks8U9SCew/z/o14Kclo/Lw3PtNQ4il CPsyxLhiK9wsvLKp2XakdVQVa895OnoqVB9P0EWfCUR3YvcwYGZtEKWKAaXXvTXT8WeG Z0Hs/p6qH3Kt44uOlJp7F8l1tQ5b3qYXEqsSvVd7JAJJtPy5IxQBPQqA3u5lRkov0rZy t1ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705029171; x=1705633971; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S5/cyeiP2kcMjYGDLWfmNOw1sQj0PJsJUjDPVSR0l3E=; b=fadEagxvGE6HbbNnqueS4DsodGU4uZ4csq4IgC1rCQ3VNYgoR+f+Pr40nzAIzFVsEI E7KIPD+KPbj5snmpU3v38PQN21A8Dx0yqqTxbRb0aZa4d2LLSCrLEMqLOHd1gKvP4jFG s7ENU35BiOjvkdSyN1bcEw74/esxZJm2mkVjOJIUq3qJUGbqQKsDHBc4KhLMJ7gjrwz+ jBdcudVWHjv4HrEc7D4E1Wcn+jK06ViCmAz69Yk6kew64+Ywmqk4yIp5stfTPeXbo7q7 4YzKvNZ+ieFcpxY4V6c9QrBprZBcgaYEXY7tP0qrFRVTXlUwubFHvsVVBUn+Kp8hsZNC 615Q== X-Gm-Message-State: AOJu0YzZqTdVObgAhpI4FwVT2fA7sVssAcZab6vGetJuO22CrbgPd0mS HWtbqjAni355lTfaYzHos0PbmYpNmDLWLdhKJPw= X-Google-Smtp-Source: AGHT+IGUDsAOmoa3cNeqdQAWvZuchzg/JtBq9aDR20d9uNxbl+9dmOWBoEixY+yMi2XHt3Coa3+HCe2+4JUrdlk2D9A= X-Received: by 2002:a05:6870:9a21:b0:204:b2a6:17b5 with SMTP id fo33-20020a0568709a2100b00204b2a617b5mr713690oab.33.1705029171595; Thu, 11 Jan 2024 19:12:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Fri, 12 Jan 2024 08:42:39 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: Bertrand Drouvot Cc: "Zhijie Hou (Fujitsu)" , Masahiko Sawada , Dilip Kumar , shveta malik , Peter Smith , Nisha Moond , "Hayato Kuroda (Fujitsu)" , Bharath Rupireddy , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , Ajin Cherian , Alvaro Herrera Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 11, 2024 at 9:11=E2=80=AFPM Bertrand Drouvot wrote: > > On Thu, Jan 11, 2024 at 04:22:56PM +0530, Amit Kapila wrote: > > On Tue, Jan 9, 2024 at 6:39=E2=80=AFPM Amit Kapila wrote: > > > > > > +static bool > > > +synchronize_one_slot(WalReceiverConn *wrconn, RemoteSlot *remote_slo= t) > > > { > > > ... > > > + /* Slot ready for sync, so sync it. */ > > > + else > > > + { > > > + /* > > > + * Sanity check: With hot_standby_feedback enabled and > > > + * invalidations handled appropriately as above, this should never > > > + * happen. > > > + */ > > > + if (remote_slot->restart_lsn < slot->data.restart_lsn) > > > + elog(ERROR, > > > + "cannot synchronize local slot \"%s\" LSN(%X/%X)" > > > + " to remote slot's LSN(%X/%X) as synchronization" > > > + " would move it backwards", remote_slot->name, > > > + LSN_FORMAT_ARGS(slot->data.restart_lsn), > > > + LSN_FORMAT_ARGS(remote_slot->restart_lsn)); > > > ... > > > } > > > > > > I was thinking about the above code in the patch and as far as I can > > > think this can only occur if the same name slot is re-created with > > > prior restart_lsn after the existing slot is dropped. Normally, the > > > newly created slot (with the same name) will have higher restart_lsn > > > but one can mimic it by copying some older slot by using > > > pg_copy_logical_replication_slot(). > > > > > > I don't think as mentioned in comments even if hot_standby_feedback i= s > > > temporarily set to off, the above shouldn't happen. It can only lead > > > to invalidated slots on standby. > > I also think so. > > > > > > > To close the above race, I could think of the following ways: > > > 1. Drop and re-create the slot. > > > 2. Emit LOG/WARNING in this case and once remote_slot's LSN moves > > > ahead of local_slot's LSN then we can update it; but as mentioned in > > > your previous comment, we need to update all other fields as well. If > > > we follow this then we probably need to have a check for catalog_xmin > > > as well. > > IIUC, this would be a sync slot (so not usable until promotion) that coul= d > not be used anyway (invalidated), so I'll vote for drop / re-create then. > No, it can happen for non-sync slots as well. > > > Now, related to this the other case which needs some handling is what > > > if the remote_slot's restart_lsn is greater than local_slot's > > > restart_lsn but it is a re-created slot with the same name. In that > > > case, I think the other properties like 'two_phase', 'plugin' could b= e > > > different. So, is simply copying those sufficient or do we need to do > > > something else as well? > > > > > > > I'm not sure to follow here. If the remote slot is re-created then it wou= ld > be also dropped / re-created locally, or am I missing something? > As our slot-syncing mechanism is asynchronous (from time to time we check the slot information on primary), isn't it possible that the same name slot is dropped and recreated between slot-sync worker's checks? --=20 With Regards, Amit Kapila.