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 1qOtV1-009KqL-2l for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 05:25:19 +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 1qOtUy-0088lV-2T for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Jul 2023 05:25:16 +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 1qOtUx-0088lJ-OG for pgsql-hackers@lists.postgresql.org; Thu, 27 Jul 2023 05:25:15 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qOtUr-001nj1-Lz for pgsql-hackers@postgresql.org; Thu, 27 Jul 2023 05:25:14 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-565f3881cbeso440814eaf.2 for ; Wed, 26 Jul 2023 22:25:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690435509; x=1691040309; 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=zwcS62ep+2DZ7l7ECpS8IfSW8Qb7o90iO51ISeQE6xc=; b=ncPebeoe2n31DtD9NJZB7w1HAALlXTwxr+6NBFW2oUzU1RxOaoRA1cD/drFOutzeDO su3bOzvyYEGjTdID+yRabYrHROYCHoguwEQ3q5Vw/DkVUNcSL9MN7HbQE71Ss8yFUqZA 0NcXVz9XvaP6xl3nihtDAYaW7RTYZokt51RDbxLxYZodWvWeMMlwvvEZkT7p10Yrk4kn axjoTmVSoaAboEyLhzFovMAjQ49y/YdWUOlJydRPb/rl0MbcmsT6KSofg0x6BJ9oOydH XSIk15hORsLotIVVLQS4s+dmqkAk8PII0NNvWC5+3PMeccVSXI4Kk0+EHdPM4PF0Ex3f ggsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690435509; x=1691040309; 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=zwcS62ep+2DZ7l7ECpS8IfSW8Qb7o90iO51ISeQE6xc=; b=RO9ReLE2831PUuO+d7+orNpN9hGxVY2YE31Xv8q7ki0txDCeTucjbeT+nCO+0vuMvB uF6OL/aObA2K2FmCZa8yb84Nyj2UNu7t4wKB+OwOuqnMrHKmRZDNB68uD4M3vYhOrujD hKK53BQ7Na2e5fVPI6ulrTlkj7MRltEiF5E28F6ntsrVjIh4JTY4QeWwnMBn/4yaNVL/ TFwbCoxBkvteI/Mkyd/H7IbJS2yOKn/v0uNJ+/PeueguQ9MvDtEEApDPMXKKQkOKmI/e kVgGx7P2Dlhq/qLnYHYjs7NG/L83cEzhkrot9ZOaJ8gX+nM0GnEjGnUGhhew4TBGDSYQ s3jg== X-Gm-Message-State: ABy/qLZa5IpWWP5+bghn+HzbUFIdqBUpeJ5uu5woe0B+Hso9C/+cpGEr nPHmji2KG9lq7FYAf74MEo8a9bmNog38Tlt+rw2il5+KEO34Bg== X-Google-Smtp-Source: APBJJlEtWkZlC3/O7OlRmQigZ+PNSMP4SDWch3BhaJFwg35RsOFD3WdGsthdjuYQQo3Mi5PIHW5MCNU69oo+nSihov8= X-Received: by 2002:a4a:3c07:0:b0:560:ac0f:b87c with SMTP id d7-20020a4a3c07000000b00560ac0fb87cmr3319585ooa.8.1690435508823; Wed, 26 Jul 2023 22:25:08 -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: Amit Kapila Date: Thu, 27 Jul 2023 10:54:57 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: shveta malik Cc: Bharath Rupireddy , "Drouvot, Bertrand" , Peter Eisentraut , Bruce Momjian , Ashutosh Sharma , Andres Freund , pgsql-hackers 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, Jul 26, 2023 at 10:31=E2=80=AFAM shveta malik wrote: > > On Mon, Jul 24, 2023 at 9:00=E2=80=AFAM Amit Kapila wrote: > > > > On Mon, Jul 24, 2023 at 8:03=E2=80=AFAM Bharath Rupireddy > > wrote: > > > > > > Is having one (or a few more - not > > > necessarily one for each logical slot) worker for all logical slots > > > enough? > > > > > > > I guess for a large number of slots the is a possibility of a large > > gap in syncing the slots which probably means we need to retain > > corresponding WAL for a much longer time on the primary. If we can > > prove that the gap won't be large enough to matter then this would be > > probably worth considering otherwise, I think we should find a way to > > scale the number of workers to avoid the large gap. > > > > How about this: > > 1) On standby, spawn 1 worker per database in the start (as it is > doing currently). > > 2) Maintain statistics on activity against each primary's database on > standby by any means. Could be by maintaining 'last_synced_time' and > 'last_activity_seen time'. The last_synced_time is updated every time > we sync/recheck slots for that particular database. The > 'last_activity_seen_time' changes only if we get any slot on that > database where actually confirmed_flush or say restart_lsn has changed > from what was maintained already. > > 3) If at any moment, we find that 'last_synced_time' - > 'last_activity_seen' goes beyond a threshold, that means that DB is > not active currently. Add it to list of inactive DB > I think we should also increase the next_sync_time if in current sync, there is no update. > 4) Launcher on the other hand is always checking if it needs to spawn > any other extra worker for any new DB. It will additionally check if > number of inactive databases (maintained on standby) has gone higher > (> some threshold), then it brings down the workers for those and > starts a common worker which takes care of all such inactive databases > (or merge all in 1), while workers for active databases remain as such > (i.e. one per db). Each worker maintains the list of DBs which it is > responsible for. > > 5) If in the list of these inactive databases, we again find any > active database using the above logic, then the launcher will spawn a > separate worker for that. > I wonder if we anyway some sort of design like this because we shouldn't allow to spawn as many workers as the number of databases. There has to be some existing or new GUC like max_sync_slot_workers which decided the number of workers. Overall, this sounds to be a more workload-adaptive approach as compared to the current one. --=20 With Regards, Amit Kapila.