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 1rVO7N-00Gc1p-LK for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 03:52:02 +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 1rVO7M-000voI-SD for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Feb 2024 03:52:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rVO7M-000voA-Ej for pgsql-hackers@lists.postgresql.org; Thu, 01 Feb 2024 03:52:00 +0000 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rVO7J-004R6W-PL for pgsql-hackers@postgresql.org; Thu, 01 Feb 2024 03:51:59 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-21433afcc53so299561fac.3 for ; Wed, 31 Jan 2024 19:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706759516; x=1707364316; 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=WjE4ZQ9Ia0d3HHdk1xYW6aHOHU0n3fGxM/BkYitYYNk=; b=WoIWwO45P0XELirjQSroDL0gpH6Q8khMkU6aPk3BVPNhJOvyzM6IuL+udPlIrE+n5Z 6ZurfWZZSJZGuwhsmLLbFqn9fQ99eFsgBvtQYRzagS4oBOgRq3b7W7OvWCT5QbLAxZN5 HW0meyH4g8QVmtLH7uMJWsgx9ulE06bj/iVKvCt0bXGbDup3jemcwKAAWoeKxylSXMZs oQeBbOFAbYtTc4md/vscNYfTYvK4qmbClcaBcGqZoqAH4NvwEb08L7QKwpC3ccci5FFZ 5CwAVGQyOwTQqvZjVofZ5ELSD1p2Djm1/7pbtfBVFNKrq4yzN9bQ3AZCQ5jGBgRzKMD2 hzHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706759516; x=1707364316; 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=WjE4ZQ9Ia0d3HHdk1xYW6aHOHU0n3fGxM/BkYitYYNk=; b=CHkRh8v4VInGklmhMmKJsCFgTyoeDDmqPLI1ZN3jWnLmurTvO4p93rBZ6CnBgCcKe9 m60rfm2vZNfP8KMKYJjArrHtYo/VvqUkQ2V63D1xG7nHD0qL7he1iRZbpAeAddUB4wyN DoKgltmX8Q3u/VQ68tcjW4tB8Obtb4UkgvrWACxjRzDRNp8MTEP9jXXdMvOJtl7KekY4 8cSCk5vVlKc9Rir5G6MEEqk72lZH4nzXYGOxyx3aEIULl9q3yQFyC+Drx1Y98r+/3V/c Zqh/XL9+PeNpj77n9hpfJNY4jmmIrs69dtwyG0aaa4ymEdhdSTrQpmwcatpRvogxotLk ZDUQ== X-Gm-Message-State: AOJu0YzGsicn3/NOAWTs/s47HsorYD6/+QSHHF0Cdbrm69KojTNnFoEh Cki/9EBpDN09RaERXS4jvy7qvAVP6JBSeCO7hE/3+ECQrmCbGjHKYkooXOTRH4GrUIUE1iI2Pza HiMR1AJeI/hGWw2jNYmeGXKaqPqCnit3eTXaITw== X-Google-Smtp-Source: AGHT+IGYfGJ/vlmf4yjZlQbweucuNeaamPXvKwVYO43m0cwgLs8WNCDsvBQYyCb6bfy5H52/3LPKEhFArn3Ev8YPvr8= X-Received: by 2002:a05:6870:4205:b0:218:dc16:1d0a with SMTP id u5-20020a056870420500b00218dc161d0amr2122995oac.13.1706759514975; Wed, 31 Jan 2024 19:51:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Thu, 1 Feb 2024 09:21:42 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: Masahiko Sawada Cc: shveta malik , "Zhijie Hou (Fujitsu)" , Peter Smith , Bertrand Drouvot , Ajin Cherian , Dilip Kumar , Nisha Moond , "Hayato Kuroda (Fujitsu)" , Bharath Rupireddy , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , 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 Wed, Jan 31, 2024 at 9:20=E2=80=AFPM Masahiko Sawada wrote: > > On Wed, Jan 31, 2024 at 7:42=E2=80=AFPM Amit Kapila wrote: > > > > > > Considering my previous where we don't want to restart for a required > > parameter change, isn't it better to avoid repeated restart (say when > > the user gave an invalid dbname)? BTW, I think this restart interval > > is added based on your previous complaint [1]. > > I think it's useful that the slotsync worker restarts immediately when > a required parameter is changed but waits to restart when it exits > with an error. IIUC the apply worker does so; if it restarts due to a > subscription parameter change, it resets the last-start time so that > the launcher will restart it without waiting. > Agreed, this idea sounds good to me. > > > > > > > > --- > > > When I dropped a database on the primary that has a failover slot, I > > > got the following logs on the standby: > > > > > > 2024-01-31 17:25:21.750 JST [1103933] FATAL: replication slot "s" is > > > active for PID 1103935 > > > 2024-01-31 17:25:21.750 JST [1103933] CONTEXT: WAL redo at 0/3020D20 > > > for Database/DROP: dir 1663/16384 > > > 2024-01-31 17:25:21.751 JST [1103930] LOG: startup process (PID > > > 1103933) exited with exit code 1 > > > > > > It seems that because the slotsync worker created the slot on the > > > standby, the slot's active_pid is still valid. > > > > > > > But we release the slot after sync. And we do take a shared lock on > > the database to make the startup process wait for slotsync. There is > > one gap which is that we don't reset active_pid for temp slots in > > ReplicationSlotRelease(), so for temp slots such an error can occur > > but OTOH, we immediately make the slot persistent after sync. As per > > my understanding, it is only possible to get this error if the initial > > sync doesn't happen and the slot remains temporary. Is that your case? > > How did reproduce this? > > I created a failover slot manually on the primary and dropped the > database where the failover slot is created. So this would not happen > in normal cases. > Right, it won't happen in normal cases (say for walsender). This can happen in some cases even without this patch as noted in comments just above active_pid check in ReplicationSlotsDropDBSlots(). Now, we need to think whether we should just update the comments above active_pid check to explain this case or try to engineer some solution for this not-so-common case. I guess if we want a solution we need to stop slotsync worker temporarily till the drop database WAL is applied or something like that. > BTW I've tested the following switch/fail-back scenario but it seems > not to work fine. Am I missing something? > > Setup: > node1 is the primary, node2 is the physical standby for node1, and > node3 is the subscriber connecting to node1. > > Steps: > 1. [node1]: create a table and a publication for the table. > 2. [node2]: set enable_syncslot =3D on and start (to receive WALs from no= de1). > 3. [node3]: create a subscription with failover =3D true for the publicat= ion. > 4. [node2]: promote to the new standby. > 5. [node3]: alter subscription to connect the new primary, node2. > 6. [node1]: stop, set enable_syncslot =3D on (and other required > parameters), then start as a new standby. > > Then I got the error "exiting from slot synchronization because same > name slot "test_sub" already exists on the standby". > > The logical replication slot that was created on the old primary > (node1) has been synchronized to the old standby (node2). Therefore on > node2, the slot's "synced" field is true. However, once node1 starts > as the new standby with slot synchronization, the slotsync worker > cannot synchronize the slot because the slot's "synced" field on the > primary is false. > Yeah, we avoided doing anything in this case because the user could have manually created another slot with the same name on standby. Unlike WAL slots can be modified on standby as we allow decoding on standby, so we can't allow to overwrite the existing slots. We won't be able to distinguish whether the existing slot was a slot that the user wants to sync with primary or a slot created on standby to perform decoding. I think in this case user first needs to drop the slot on new standby. We probably need to document it as well unless we decide to do something else. What do you think? --=20 With Regards, Amit Kapila.