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 1rPfwA-00DIyW-0J for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jan 2024 09:40:50 +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 1rPfw9-002hL1-3N for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Jan 2024 09:40:49 +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 1rPfw8-002hKr-Lv for pgsql-hackers@lists.postgresql.org; Tue, 16 Jan 2024 09:40:48 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rPfw5-001n9v-Qg for pgsql-hackers@postgresql.org; Tue, 16 Jan 2024 09:40:47 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-336746c7b6dso8210471f8f.0 for ; Tue, 16 Jan 2024 01:40:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705398044; x=1706002844; 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=aBE2kaOaHnKl8LPaumkM0FakzpiKUWmWdrh4U+dEU70=; b=JSV8dYjCymSh2EFlZ6hDMX/l3Un1udQG/4nsK/OhYKDK2K4bD9BEULEQBMtLq/WIaB bJ6URuoFE4DexRi7R4a8CBU383EDWMkdGy/xB9r3oERu8RPLyMy0Mgtx0/1AqdTdYyoW XzfqBPw6ih4XL/+xdDbKsfw4HAVeUihFDVjjS+exMQmkxUUwaRqWfg07hIgZJRkT/SM0 0WK0bVygoGFzspBdsreVK3SHBFQNi4XQTciDW9pkjX8Xg7KNPC0X/xl6ZB+laXlekYKD Dd0P4BziZd0jJ6UxilEXX5wpnwOXlXq2Mc2FZD8mJbMjSZ3OI7NlgqjdF7RBFifVZ3p1 KLZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705398044; x=1706002844; 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=aBE2kaOaHnKl8LPaumkM0FakzpiKUWmWdrh4U+dEU70=; b=K8QwmHfuUhd9GPWjPeoQFxV0FvOCyRqa2V/la8df1dTeAsevfWLHMgh3fLdCvjBtIL 1+RFJ5tDztIfc/ZzgQYOoHY15k/kQQEB/8FeKTwptYh6CbupPXIdL6Lt4dgHonaUDM1P 5uBZDoUxuauqmeCk1CDmbrhW56/YldE2rlbjDhE3cY+jsc5LPY7bOEJbtWHVmbBG/QXT Rcmkrx6rYdoGo4v6jtaWWzLnbRlEwR5BtVJvGA9W7rsSQpY1jKL+FJ2Nj4EXrEyhtxb3 +2LwheZqkKA9Atbevwbeh0m9vXHI6bQ0ms68V1DVB1Dx3PpKmiRlO3ODMW2eo/YeZHHE KKDg== X-Gm-Message-State: AOJu0YwiF2nJW9Od8voDPXZxD6LOoOKdnIDVJN08VyRuLLTG+kV1gV1M ZakHfF/Ua0KfCuWbicDcEAzm+2fuCifA1zoXCGQ= X-Google-Smtp-Source: AGHT+IFEQkBvw+HvBPVQKOFG00YkAViXTgbQ1qGIthNErz5LC7MLgBjxH+YMmdp1EEDl7J4cUb0PH5vC8q7f3sPzA0o= X-Received: by 2002:a5d:66ca:0:b0:337:7096:f54c with SMTP id k10-20020a5d66ca000000b003377096f54cmr3702599wrw.125.1705398043618; Tue, 16 Jan 2024 01:40:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: shveta malik Date: Tue, 16 Jan 2024 15:10:31 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: Masahiko Sawada Cc: Amit Kapila , "Zhijie Hou (Fujitsu)" , Dilip Kumar , Bertrand Drouvot , Peter Smith , Nisha Moond , "Hayato Kuroda (Fujitsu)" , Bharath Rupireddy , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , Ajin Cherian , Alvaro Herrera , shveta malik 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 Tue, Jan 16, 2024 at 12:59=E2=80=AFPM Masahiko Sawada wrote: > > On Tue, Jan 16, 2024 at 1:07=E2=80=AFPM Amit Kapila wrote: > > > > On Tue, Jan 16, 2024 at 9:03=E2=80=AFAM shveta malik wrote: > > > > > > On Sat, Jan 13, 2024 at 12:54=E2=80=AFPM Amit Kapila wrote: > > > > > > > > On Fri, Jan 12, 2024 at 5:50=E2=80=AFPM shveta malik wrote: > > > > > > > > > > There are multiple approaches discussed and tried when it comes t= o > > > > > starting a slot-sync worker. I am summarizing all here: > > > > > > > > > > 1) Make slotsync worker as an Auxiliary Process (like checkpoint= er, > > > > > walwriter, walreceiver etc). The benefit this approach provides i= s, it > > > > > can control begin and stop in a more flexible way as each auxilia= ry > > > > > process could have different checks before starting and can have > > > > > different stop conditions. But it needs code duplication for proc= ess > > > > > management(start, stop, crash handling, signals etc) and currentl= y it > > > > > does not support db-connection smoothly (none of the auxiliary pr= ocess > > > > > has one so far) > > > > > > > > > > > > > As slotsync worker needs to perform transactions and access syscach= e, > > > > we can't make it an auxiliary process as that doesn't initialize th= e > > > > required stuff like syscache. Also, see the comment "Auxiliary > > > > processes don't run transactions ..." in AuxiliaryProcessMain() whi= ch > > > > means this is not an option. > > > > > > > > > > > > > > 2) Make slotsync worker as a 'special' process like AutoVacLaunch= er > > > > > which is neither an Auxiliary process nor a bgworker one. It allo= ws > > > > > db-connection and also provides flexibility to have start and sto= p > > > > > conditions for a process. > > > > > > > > > > > > > Yeah, due to these reasons, I think this option is worth considerin= g > > > > and another plus point is that this allows us to make enable_syncsl= ot > > > > a PGC_SIGHUP GUC rather than a PGC_POSTMASTER. > > > > > > > > > > > > > > 3) Make slotysnc worker a bgworker. Here we just need to register= our > > > > > process as a bgworker (RegisterBackgroundWorker()) by providing a > > > > > relevant start_time and restart_time and then the process managem= ent > > > > > is well taken care of. It does not need any code-duplication and > > > > > allows db-connection smoothly in registered process. The only thi= ng it > > > > > lacks is that it does not provide flexibility of having > > > > > start-condition which then makes us to have 'enable_syncslot' as > > > > > PGC_POSTMASTER parameter rather than PGC_SIGHUP. Having said this= , I > > > > > feel enable_syncslot is something which will not be changed frequ= ently > > > > > and with the benefits provided by bgworker infra, it seems a > > > > > reasonably good option to choose this approach. > > > > > > > > > > > > > I agree but it may be better to make it a PGC_SIGHUP parameter. > > > > > > > > > 4) Another option is to have Logical Replication Launcher(or a ne= w > > > > > process) to launch slot-sync worker. But going by the current des= ign > > > > > where we have only 1 slotsync worker, it may be an overhead to ha= ve an > > > > > additional manager process maintained. > > > > > > > > > > > > > I don't see any good reason to have an additional launcher process = here. > > > > > > > > > > > > > > Thus weighing pros and cons of all these options, we have current= ly > > > > > implemented the bgworker approach (approach 3). Any feedback is > > > > > welcome. > > > > > > > > > > > > > I vote to go for (2) unless we face difficulties in doing so but (3= ) > > > > is also okay especially if others also think so. > > > > > > I am not against any of the approaches but I still feel that when we > > > have a standard way of doing things (bgworker) we should not keep > > > adding code to do things in a special way unless there is a strong > > > reason to do so. Now we need to decide if 'enable_syncslot' being > > > PGC_POSTMASTER is a strong reason to go the non-standard way? > > > > > > > Agreed and as said earlier I think it is better to make it a > > PGC_SIGHUP. Also, not sure we can say it is a non-standard way as > > already autovacuum launcher is handled in the same way. One more minor > > thing is it will save us for having a new bgworker state > > BgWorkerStart_ConsistentState_HotStandby as introduced by this patch. > > Why do we need to add a new BgWorkerStart_ConsistentState_HotStandby > for the slotsync worker? Isn't it sufficient that the slotsync worker > exits if not in hot standby mode? It is doable, but that will mean starting slot-sync worker even on primary on every server restart which does not seem like a good idea. We wanted to have a way where-in it does not start itself in non-standby mode. > Is there any technical difficulty or obstacle to make the slotsync > worker start using bgworker after reloading the config file? When we register slotsync worker as bgworker, we can only register the bgworker before initializing shared memory, we cannot register dynamically in the cycle of ServerLoop and thus we do not have flexibility of registering/deregistering the bgworker (or controlling the bgworker start) based on config parameters each time they change. We can always start slot-sync worker and let it check if enable_syncslot is ON. If not, exit and retry the next time when postmaster will restart it after restart_time(60sec). The downside of this approach is, even if any user does not want slot-sync functionality and thus has permanently disabled 'enable_syncslot', it will keep on restarting and exiting there. thanks Shveta