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 1qMobt-003M4x-A1 for pgsql-hackers@arkaria.postgresql.org; Fri, 21 Jul 2023 11:47:49 +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 1qMoas-000O8O-5h for pgsql-hackers@arkaria.postgresql.org; Fri, 21 Jul 2023 11:46:46 +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 1qMoar-000O8G-ID for pgsql-hackers@lists.postgresql.org; Fri, 21 Jul 2023 11:46:45 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qMoak-000gB8-BL for pgsql-hackers@postgresql.org; Fri, 21 Jul 2023 11:46:44 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3110ab7110aso1553708f8f.3 for ; Fri, 21 Jul 2023 04:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689939996; x=1690544796; 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=6veNxHk37J+srN5cotFjubGI67fG42ayWxg/gWt5IgQ=; b=cE/c6tFbVQog+lGY1g1N1LJ+AE5h6TBAy81W6RST1AzmcgQ4NNOG8XDchT/4P8CbMx 8OqC37vwMmLT/Z/PbnIlvwqHosr8mqzOQQ5ayL/39926C/iGWXOsnDmm3TMEfVRIdtmv rRHUcCQgGUESm72VgXSkdEfkQh3pLTb2DWfNeGMBvF/HpGopfW0l2ZZ3UW0zMxbiTUuM CFEp4M4VlHACinCzWh6jYpNPfoi7yaCUJU/3/sfl+quSS6tTc1QJTbGXs9nJ1axbs+7d Cov36tAVrFzHr2XEuq2Ll/U2QIRpnUKLUSzsb1+v6cZBRsjJGYLxwIby8jeGVb/+dtuP D+0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689939996; x=1690544796; 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=6veNxHk37J+srN5cotFjubGI67fG42ayWxg/gWt5IgQ=; b=bU94u4fj+vx6qGB93dRkyilzmKUie2Eii49g8EVw5OuVZEvrCVLEEl/WjvVDcaXkiu qD6/vO0bzByQxrT5c3MRrDOc8qrgzsXyQFv6j95oE5bqydRoyKYHouTCsyDMULrZK73e upSCwb98EfZl1xVxBkKCeCcavE4FCJ8g43CbU9sVL0k8TVVoBNwr4m+fLAZwV6XEi15n rXpyZ53DZr6/wEge6lh/Qsnm84hHGDaw+P+Woa/Y99Hx0P0XeUEXEhez83ij1ddl0zZ+ juEDMnytg6qfteIopiZBdtXb1EG/jakOhzTyS6KAYpr/I5U3cFyrJL2enreW+DlQcuXB 4E/g== X-Gm-Message-State: ABy/qLaAPObjSG5xJ3emGjBxvf66AxESbCC4RmELg4B25z0W8tsERAbV l2aYhkMC4UsL8jAelK1l66Zq+brUB0wxUbVfrY4= X-Google-Smtp-Source: APBJJlFppJJy0a+cgRIWxwovpDMDMhEqf5srLIbl0qsyaboLLVNo9o6k4TH4ZPtYY7QHBJSq0x0988PFdy12r+DCtKE= X-Received: by 2002:adf:f1c9:0:b0:315:ac1b:91e with SMTP id z9-20020adff1c9000000b00315ac1b091emr1256850wro.53.1689939996196; Fri, 21 Jul 2023 04:46:36 -0700 (PDT) MIME-Version: 1.0 References: <514f6f2f-6833-4539-39f1-96cd1e011f23@enterprisedb.com> <18dbc929-a281-8552-4f1d-7e4d0e4eedba@enterprisedb.com> <646acd8d-9896-ed8d-2ab4-0bf11b3285d4@enterprisedb.com> <20220205195944.drwc3psrb5udt2cw@alap3.anarazel.de> <20220207203222.22aktwxrt3fcllru@alap3.anarazel.de> In-Reply-To: From: shveta malik Date: Fri, 21 Jul 2023 17:16:24 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: Bharath Rupireddy Cc: Amit Kapila , "Drouvot, Bertrand" , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers , 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 Fri, Jul 21, 2023 at 11:36=E2=80=AFAM Bharath Rupireddy wrote: > > On Thu, Jul 20, 2023 at 5:05=E2=80=AFPM shveta malik wrote: > > > > On Fri, Jun 16, 2023 at 3:26=E2=80=AFPM Amit Kapila wrote: > > > > > > On Mon, Apr 17, 2023 at 7:37=E2=80=AFPM Drouvot, Bertrand > > > wrote: > > > > > > > > > 3. As mentioned in the initial email, I think it would be better to > > > replace LIST_SLOTS command with a SELECT query. > > > > > > > I had a look at this thread. I am interested to work on this and can > > spend some time addressing the comments given here. > > Thanks for your interest. Coincidentally, I started to split the patch > into 2 recently - 0001 making the specified logical wal senders wait > for specified standbys to ack, 0002 synchronize logical slots. I think > I'll have these patches ready by early next week. For 0002, I'll > consider your latest changes having LIST_SLOTS removed. > Thanks Bharat for letting us know. It is okay to split the patch, it may definitely help to understand the modules better but shall we take a step back and try to reevaluate the design first before moving to other tasks? I analyzed more on the issues stated in [1] for replacing LIST_SLOTS with SELECT query. On rethinking, it might not be a good idea to replace this cmd with SELECT in Launcher code-path, because we do not have any database-connection in launcher and 'select' query needs one and thus we need to supply dbname to it. We may take the primary-dbname info in a new GUC from users, but I feel retaining LIST cmd is a better idea over adding a new GUC. But I do not see a reason why we should get complete replication-slots info in LIST command. The logic in Launcher is to get distinct database-ids info out of all the slots and start worker per database-id. Since we are only interested in database-id, I think we should change LIST_SLOTS to something like LIST_DBID_FOR_LOGICAL_SLOTS. This new command may get only unique database-ids for all the logical-slots (or the ones mentioned in synchronize_slot_names) from primary. By doing so, we can avoid huge network traffic in cases where the number of replication slots is quite high considering that max_replication_slots can go upto MAX_BACKENDS:2^18-1. So I plan to make this change where we retain LIST cmd over SELECT query but make this cmd's output restricted to only database-Ids. Thoughts? Secondly, I was thinking if the design proposed in the patch is the best one. No doubt, it is the most simplistic design and thus may prove very efficient for scenarios where we have a reasonable number of workers starting and each one actively busy in slots-synchronisation, handling almost equivalent load. But since we are starting one worker per database id, it may not be most efficient for cases where not all the databases are actively being used. We may have some workers (started for databases not in use) just waking up and sending queries to primary and then going back to sleep and in the process generating network traffic, while others may be heavily loaded to deal with large numbers of active slots for a heavily loaded database. I feel the design should be adaptable to load conditions i.e. if we have more number of actively used slots, then we should have more workers spawned to handle it and when the work is less then the number of spawned workers should be less. I have not thought it thoroughly yet and also not sure whether it will actually come out as a better one, but it or more such designs should be considered before we start fixing bugs in this patch. Kindly let me know if there are already discussions around it which I might have missed. Any feedback is appreciated. [1] : https://www.postgresql.org/message-id/CAJpy0uCMNz3XERP-Vzp-7rHFztJgc6= d%2BxsmUVCqsxWPkZvQz0Q%40mail.gmail.com thanks Shveta