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 1rPuVH-00F7Dp-TB for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jan 2024 01:14:04 +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 1rPuVH-009cgG-2C for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jan 2024 01:14:03 +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 1rPuVG-009cg8-L1 for pgsql-hackers@lists.postgresql.org; Wed, 17 Jan 2024 01:14:02 +0000 Received: from mail-lj1-x230.google.com ([2a00:1450:4864:20::230]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rPuVC-001uBo-QQ for pgsql-hackers@postgresql.org; Wed, 17 Jan 2024 01:14:01 +0000 Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2ccbefe570bso31644691fa.0 for ; Tue, 16 Jan 2024 17:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705454037; x=1706058837; 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=wfcJB/n7tOL4d7il/zY9VmOqBD5N19tOTXYrpz+5wqg=; b=L4xoTRQ3sAwe6XkNvUbkS2UCKeMX9GgfEnQQAxKvRMVTatSxYzrWsd9vC/I1Z2P7Yz DrXn/Y2+L9AjFp/e/obCzgg3QI4RdB3cXtBuT+BSZyhkdbUhcEULskB2oMTlR+vpjrom TJRqKVDq803j2MBLafKvMg7us6SwhTkKS7bvG2d9tFBs/K5kFFvJ0NbjxcU7D5Cee9/o 0xjNbKyHwUcs8Y7g+aUsoBm1U174A9tcWPMPpRUNHFkNvo+o4FOV5AaQTxs+hHqHZOIl 6zDDAwpmZVAFZmNFeJfOr/FpmMPO3Eblqz6dlAhPYBDP0lAHosHpWnWQ1hoNi5JCgT7V Uo4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705454037; x=1706058837; 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=wfcJB/n7tOL4d7il/zY9VmOqBD5N19tOTXYrpz+5wqg=; b=Ea35CPSnbJIdGUz3NX67QLTxtbcW7rjQbU8jeRWRo4i7OcIDRWdpEscrKeWHfT5Dtn Ox+Q9oAESDFb8CLVAKMZN+j1Tq+00Gho0jIg3FGo8Fd7g1y68tdckJVlqIONdClD3BY8 OB18ufAFXidxxIohZ6TQecBC8GXE7wJERKLILRXwV6CZOuNXRnTOjioE9jHM7NW1Nn5l 3rdlibBM0hLXKjq/LIm50l0pIPX/jyIiw98UcBTn4dLBpCfqBLvbi4J3vNbDVv1ZiWcn Ri9awqmszGZD5nz+NgpHy4x/LyavRkx3tjBJ742sC+JdIjGWtnSa9zFXroxkVpciE5/W lKGA== X-Gm-Message-State: AOJu0Yw266koLTIOKDQMCc/IulbH+85WKGXvElstosquOr5sHkJC5UFA PPYqIlF849a3lBTN8PzLpRa2kl0L0BApp72r+9w= X-Google-Smtp-Source: AGHT+IFjitybzYz/1bwvrxNEgI3At/HfZkGdUwjLIScQ46IBPItgbdjqk3guDzop8airMC9itUuIzRTCOBGJyEpyi5g= X-Received: by 2002:a2e:742:0:b0:2cc:9882:4ca2 with SMTP id i2-20020a2e0742000000b002cc98824ca2mr7816008ljd.5.1705454036845; Tue, 16 Jan 2024 17:13:56 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Wed, 17 Jan 2024 10:13:19 +0900 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: shveta malik 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 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 6:40=E2=80=AFPM shveta malik wrote: > > 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= to > > > > > > starting a slot-sync worker. I am summarizing all here: > > > > > > > > > > > > 1) Make slotsync worker as an Auxiliary Process (like checkpoi= nter, > > > > > > walwriter, walreceiver etc). The benefit this approach provides= is, it > > > > > > can control begin and stop in a more flexible way as each auxil= iary > > > > > > process could have different checks before starting and can hav= e > > > > > > different stop conditions. But it needs code duplication for pr= ocess > > > > > > management(start, stop, crash handling, signals etc) and curren= tly it > > > > > > does not support db-connection smoothly (none of the auxiliary = process > > > > > > has one so far) > > > > > > > > > > > > > > > > As slotsync worker needs to perform transactions and access sysca= che, > > > > > we can't make it an auxiliary process as that doesn't initialize = the > > > > > required stuff like syscache. Also, see the comment "Auxiliary > > > > > processes don't run transactions ..." in AuxiliaryProcessMain() w= hich > > > > > means this is not an option. > > > > > > > > > > > > > > > > > 2) Make slotsync worker as a 'special' process like AutoVacLaun= cher > > > > > > which is neither an Auxiliary process nor a bgworker one. It al= lows > > > > > > db-connection and also provides flexibility to have start and s= top > > > > > > conditions for a process. > > > > > > > > > > > > > > > > Yeah, due to these reasons, I think this option is worth consider= ing > > > > > and another plus point is that this allows us to make enable_sync= slot > > > > > a PGC_SIGHUP GUC rather than a PGC_POSTMASTER. > > > > > > > > > > > > > > > > > 3) Make slotysnc worker a bgworker. Here we just need to regist= er our > > > > > > process as a bgworker (RegisterBackgroundWorker()) by providing= a > > > > > > relevant start_time and restart_time and then the process manag= ement > > > > > > is well taken care of. It does not need any code-duplication an= d > > > > > > allows db-connection smoothly in registered process. The only t= hing it > > > > > > lacks is that it does not provide flexibility of having > > > > > > start-condition which then makes us to have 'enable_syncslot' a= s > > > > > > PGC_POSTMASTER parameter rather than PGC_SIGHUP. Having said th= is, I > > > > > > feel enable_syncslot is something which will not be changed fre= quently > > > > > > 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 = new > > > > > > process) to launch slot-sync worker. But going by the current d= esign > > > > > > where we have only 1 slotsync worker, it may be an overhead to = have an > > > > > > additional manager process maintained. > > > > > > > > > > > > > > > > I don't see any good reason to have an additional launcher proces= s here. > > > > > > > > > > > > > > > > > Thus weighing pros and cons of all these options, we have curre= ntly > > > > > > implemented the bgworker approach (approach 3). Any feedback i= s > > > > > > 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 w= e > > > > 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 mino= r > > > 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. Understood. Another idea would be that the startup process dynamically registers the slotsync worker if hot_standby is enabled. But it doesn't seem like the right approach. > > > 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 for the explanation. It sounds like it's not impossible but would require some work. If allowing bgworkers to start also on SIGUP is a general improvement, we can implement it later while having enable_syncslot PGC_POSTMASTER at this time. Then, we will be able to make the enable_syncslot PGC_SIGUP later. BTW I think I found a race condition in the v61 patch to cause that the slotsync worker continues working even after promotion (I've not tested with v62 patch though). At the time when the startup shutdown the slotsync worker in FinishWalRecovery(), the postmaster's pmState is still PM_HOT_STANDBY. And if the slotsync worker is not running when the startup process attempts to shutdown it, ShutDownSlotSync() does nothing. Therefore, after the startup process doesn't shutdown the slotsync worker, the postmaster could relaunch the slotsync worker before its state transition to PM_RUN. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com