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 1rQnRr-003den-CE for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jan 2024 11:54:12 +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 1rQnRq-0094Ap-9g for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jan 2024 11:54:10 +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 1rQnRp-0094Ah-V9 for pgsql-hackers@lists.postgresql.org; Fri, 19 Jan 2024 11:54:09 +0000 Received: from mail-oa1-x29.google.com ([2001:4860:4864:20::29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rQnRn-002JM1-40 for pgsql-hackers@postgresql.org; Fri, 19 Jan 2024 11:54:08 +0000 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-2108e106947so450027fac.3 for ; Fri, 19 Jan 2024 03:54:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705665246; x=1706270046; 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=YpWj14l58xrUX6X13MTJfztRxabnknVMuzgNokl0/Uw=; b=PkMC1zML89ATEcRYa19X16MUHOrVjmF7iedmaEnrPJuuDoZU51rXId6u44BwRi4LOB ztS/agZQDV0HEARpPSWz09RlxKtRxPSqA+VFWCBMzFmNFJzA+EMhtixFuzqN/fTzxpW4 hXl32yxf56c6P5rpfzxf/fXELw6ToMde34Zffh6jJG3aueTtSkcE6JQVonJijzDf1TLT LtbO7AM79zYLxy3AtQHD1ss3CiYEQ1h0LWwCep6wc4NWJYFwy/eKLq5pGYFbxMuxYvMZ 6D/oz3hUYlsh+e0DGdKNBgRgcM0eLKMAg5qN2jjsCS7Oy3Id1np+slp6qe5Ays8fPayL DQhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705665246; x=1706270046; 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=YpWj14l58xrUX6X13MTJfztRxabnknVMuzgNokl0/Uw=; b=PYSTs2sS2nS1f5vnaBft1AJ1ASimaAhrM0y+rrx8JWJ6jHRODLm3p1Wnhx1qxvSIlt //p0Uov8e2GzXedjSBmlCJQVtZ/u8tKfZUbOfAI4a6DUmczEaZm1ruIEOlwqK9Awc85a k1wX2Vu9mTQoIOx38W6mNW/cFjIyA29JttaXF/AAlJj2E9xmp2g+Pb9QWH6c2uqR66E8 TEJ1oUXNg88I4Zfrbf/pOkAiqllwI973RVThbeYG83UlWsYqCXTNxh2SjQqORrUnomUv 7iJLIErMutflAHhwechdNSEXOKrPwPMVHN0sNxuPf6SSj4On5NTmtFo4j/KVFZWPymUK OTJQ== X-Gm-Message-State: AOJu0YzHhVS7K3R+vCe3QpK9jlbA/2dTqY/faqpFc9Lv9IOJJW1tnYh6 8wKNzopTf2UtZSHzegYy22gm3aEgryJARkmXeQgpzfNJmbN9ym22/uVEikV4Os5SnGSFvW5jAAI sJIlqQTf4uv7hHj9XSFoO1ciP5Pw= X-Google-Smtp-Source: AGHT+IGRIqflOu1CN7H0qCWGmrPzTsNalMTvyuNfcsbsCmZK+QwuX+2Ne3c23fo30l95fzLdD3z73u885WUCh4X+lPk= X-Received: by 2002:a05:6870:82aa:b0:210:cfd5:4d91 with SMTP id q42-20020a05687082aa00b00210cfd54d91mr1412549oae.38.1705665245997; Fri, 19 Jan 2024 03:54:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Fri, 19 Jan 2024 17:23:53 +0530 Message-ID: Subject: Re: Synchronizing slots from primary to standby To: shveta malik Cc: Bertrand Drouvot , Masahiko Sawada , "Zhijie Hou (Fujitsu)" , Dilip Kumar , 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 Wed, Jan 17, 2024 at 4:00=E2=80=AFPM shveta malik wrote: > I had some off-list discussions with Sawada-San, Hou-San, and Shveta on the topic of extending replication commands instead of using the current model where we fetch the required slot information via SQL using a database connection. I would like to summarize the discussion and would like to know the thoughts of others on this topic. In the current patch, we launch the slotsync worker on physical standby which connects to the specified database (currently we let users specify the required dbname in primary_conninfo) on the primary. It then fetches the required information for failover marked slots from the primary and also does some primitive checks on the upstream node via SQL (the additional checks are like whether the upstream node has a specified physical slot or whether the upstream node is a primary node or a standby node). To fetch the required information it uses a libpqwalreciever API which is mostly apt for this purpose as it supports SQL execution but for this patch, we don't need a replication connection, so we extend the libpqwalreciever connect API. Now, the concerns related to this could be that users would probably need to change existing mechanisms/tools to update priamry_conninfo and one of the alternatives proposed is to have an additional GUC like slot_sync_dbname. Users won't be able to drop the database this worker is connected to aka whatever is specified in slot_sync_dbname but as the user herself sets up the configuration it shouldn't be a big deal. Then we also discussed whether extending libpqwalreceiver's connect API is a good idea and whether we need to further extend it in the future. As far as I can see, slotsync worker's primary requirement is to execute SQL queries which the current API is sufficient, and don't see something that needs any drastic change in this API. Note that tablesync worker that executes SQL also uses these APIs, so we may need something in the future for either of those. Then finally we need a slotsync worker to also connect to a database to use SQL and fetch results. Now, let us consider if we extend the replication commands like READ_REPLICATION_SLOT and or introduce a new set of replication commands to fetch the required information then we don't need a DB connection with primary or a connection in slotsync worker. As per my current understanding, it is quite doable but I think we will slowly go in the direction of making replication commands something like SQL because today we need to extend it to fetch all slots info that have failover marked as true, the existence of a particular replication, etc. Then tomorrow, if we want to extend this work to have multiple slotsync workers say workers perdb then we have to extend the replication command to fetch per-database failover marked slots. To me, it sounds more like we are slowly adding SQL-like features to replication commands. Apart from this when we are reading per-db replication slots without connecting to a database, we probably need some additional protection mechanism so that the database won't get dropped. Considering all this it seems that for now probably extending replication commands can simplify a few things like mentioned above but using SQL's with db-connection is more extendable. Thoughts? --=20 With Regards, Amit Kapila.