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 1rABwV-005I26-By for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2023 16:37:11 +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 1rABwU-000Nq9-1G for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2023 16:37:10 +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 1rABwT-000Nq1-Mr for pgsql-hackers@lists.postgresql.org; Mon, 04 Dec 2023 16:37:09 +0000 Received: from mail-qt1-x82c.google.com ([2607:f8b0:4864:20::82c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rABwM-00A4w4-9O for pgsql-hackers@postgresql.org; Mon, 04 Dec 2023 16:37:08 +0000 Received: by mail-qt1-x82c.google.com with SMTP id d75a77b69052e-423dccefb68so48061581cf.0 for ; Mon, 04 Dec 2023 08:37:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701707820; x=1702312620; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=T1lJ6/nGLgHB48dUXCULHEMpY6UAjrS0d8OJDzM4Vrk=; b=Zelf8ixnZwbhn2cD1t3Id79Ik58NSnbikW6jKPh+wKfAefLt6zgMlA77U4OTFXBb84 wDddXtT7EraOCGZdZgQXYbjJQFfVeEEy+8IgIPHykYkpLjMNgqlfCsSxriK3xKdidKh6 XHSLwkQ0PfeTPSS6Ke4mDTLDC73VbAZEXE5aRfXe8GQ7vvQx3ZQr2xRY5mbJUbB2RN+c 52SGkl3S9NyvWmVN/LUMRkshwJ+UnT7zyeO72re3f936Q7Tnyx1lFKgtNtQIQUI/8AN1 3ngX4WcCg3sGvI1XxvxJE/hWaqBUk5kWUg6PZOv9j5/GvWqSedyABt+P6oPdUhMLE5UR E/MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701707820; x=1702312620; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T1lJ6/nGLgHB48dUXCULHEMpY6UAjrS0d8OJDzM4Vrk=; b=fO3eZvnGaWL4HcD8QFUqHdCs78p+sK8YLd7gHewlYSjPEAqOf1bwAt0uonEZgj1u4K +zQ4mmuBERf1mSM6KzH2OtjHGVg3NaMxkKfR7DUx06/6KIiuVPj/JIKH9J5e/A2QkSz2 fXN7WNOLc0u0bnHakizArHFC14b3BBvSCsRJ2DwuB0HuxMddmZ09BofeiACMIVJTAWuM sy3GQru+fvXxM+06VTRtRB+ev4xru3fsc/ZsP9jQi41fY91VgV4yaKc4w64lo3qYQxRi ttLy/LABWedfY8GZZc9fJbkOq2xnAJt2LwaYqhUPQ/5o6LMfq2op4BqQLy4SYL1aOh7Z LZ+Q== X-Gm-Message-State: AOJu0YzK92f8Dp9RmK9LgH0xMQ4D6bDIy8Y6+TOT2XNPw95hOKN7ntVM KtcKk2XfEMXv/QYURFEO9BQ= X-Google-Smtp-Source: AGHT+IE4v3iPRCjd62/1E8/1GE98oA8LLS5dAp08HRHe940KIjuVJ7MGutlLrQZrW+qrCt5ZBRu69g== X-Received: by 2002:ac8:5c13:0:b0:423:a9a5:da99 with SMTP id i19-20020ac85c13000000b00423a9a5da99mr1103qti.13.1701707820378; Mon, 04 Dec 2023 08:37:00 -0800 (PST) Received: from ?IPV6:2a01:cb11:192:7000:d942:dced:9078:6b4e? ([2a01:cb11:192:7000:d942:dced:9078:6b4e]) by smtp.gmail.com with ESMTPSA id ks24-20020ac86218000000b004238a0bca27sm4397805qtb.4.2023.12.04.08.36.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Dec 2023 08:36:59 -0800 (PST) Message-ID: <2fdc471d-2eee-4c29-9f26-d7f5dcc8cd53@gmail.com> Date: Mon, 4 Dec 2023 17:36:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Synchronizing slots from primary to standby Content-Language: en-US To: shveta malik , Nisha Moond Cc: Amit Kapila , "Zhijie Hou (Fujitsu)" , Peter Smith , "Hayato Kuroda (Fujitsu)" , Bharath Rupireddy , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , Ajin Cherian , Alvaro Herrera References: <65326908-f1ef-40ce-acc6-414801c30946@gmail.com> <1789e94e-8266-44d1-95e4-7f41abc27d0d@gmail.com> <828dcda4-50c2-4069-bdc3-9e8c90c943d7@gmail.com> <6694284d-c847-42df-8f76-6efa8eeeb0df@gmail.com> From: "Drouvot, Bertrand" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 12/4/23 6:10 AM, shveta malik wrote: > On Fri, Dec 1, 2023 at 5:40 PM Nisha Moond wrote: >> >> Review for v41 patch. > > Thanks for the feedback. > >> ~~~ >> 2. >> IIUC, the slotsyncworker's connection to the primary is to execute a >> query. Its aim is not walsender type connection, but at primary when >> queried, the 'backend_type' is set to 'walsender'. >> Snippet from primary db- >> >> datname | usename | application_name | wait_event_type | backend_type >> ---------+-------------+------------------+-----------------+-------------- >> postgres | replication | slotsyncworker | Client | walsender >> >> Is it okay? >> > > Slot sync worker uses 'libpqrcv_connect' for connection which sends > 'replication'-'database' key-value pair as one of the connection > options. And on the primary side, 'ProcessStartupPacket' on the basis > of this key-value pair sets the process as walsender one (am_walsender > = true). > And thus this reflects as backend_type='walsender' in > pg_stat_activity. I do not see any harm in this backend_type for > slot-sync worker currently. This is on a similar line of connections > used for logical-replications. And since a slot-sync worker also deals > with wals-positions (lsns), it is okay to maintain backend_type as > walsender unless you (or others) see any potential issue in doing > that. So let me know. I don't see any issue as well (though I understand it might seems weird to see a walsender process being spawned doing non replication stuff) > >> ~~~ >> 4. primary_slot_name GUC value test: >> >> When standby is started with a non-existing primary_slot_name, the >> wal-receiver gives an error but the slot-sync worker does not raise >> any error/warning. It is no-op though as it has a check 'if >> (XLogRecPtrIsInvalid(WalRcv->latestWalEnd)) do nothing'. Is this >> okay or shall the slot-sync worker too raise an error and exit? >> >> In another case, when standby is started with valid primary_slot_name, >> but it is changed to some invalid value in runtime, then walreceiver >> starts giving error but the slot-sync worker keeps on running. In this >> case, unlike the previous case, it even did not go to no-op mode (as >> it sees valid WalRcv->latestWalEnd from the earlier run) and keep >> pinging primary repeatedly for slots. Shall here it should error out >> or at least be no-op until we give a valid primary_slot_name? >> > Nice catch, thanks! > I reviewed it. There is no way to test the existence/validity of > 'primary_slot_name' on standby without making a connection to primary. > If primary_slot_name is invalid from the start, slot-sync worker will > be no-op (as you tested) as WalRecv->latestWalENd will be invalid, and > if 'primary_slot_name' is changed to invalid on runtime, slot-sync > worker will still keep on pinging primary. But that should be okay (in > fact needed) as it needs to sync at-least the previous slot's > positions (in case it is delayed in doing so for some reason earlier). > And once the slots are up-to-date on standby, even if worker pings > primary, it will not see any change in slots lsns and thus go for > longer nap. I think, it is not worth the effort to introduce the > complexity of checking validity of 'primary_slot_name' on primary from > standby for this rare scenario. > Maybe another option could be to have the walreceiver a way to let the slot sync worker knows that it (the walreceiver) was not able to start due to non existing replication slot on the primary? (that way we'd avoid the slot sync worker having to talk to the primary). Not sure about the extra effort to make it works though. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com