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 1sLGc5-00EA2D-Ts for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Jun 2024 06:22:10 +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 1sLGc4-005Vrw-20 for pgsql-hackers@arkaria.postgresql.org; Sun, 23 Jun 2024 06:22:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sLGc3-005Vrj-Ew for pgsql-hackers@lists.postgresql.org; Sun, 23 Jun 2024 06:22:08 +0000 Received: from mail-yb1-xb2b.google.com ([2607:f8b0:4864:20::b2b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sLGc0-003621-P7 for pgsql-hackers@lists.postgresql.org; Sun, 23 Jun 2024 06:22:07 +0000 Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-dfe1aa7cce2so3210598276.1 for ; Sat, 22 Jun 2024 23:22:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1719123722; x=1719728522; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=TCJ3yrcRCTn0u73bNdwHVe4hHf426clJbGsJfyTyJhs=; b=SXQTYzLQah4B4yRn5v4+nuplSbYjsWHHS5j7WKstYBcLqwhYFt5skY5pdVTtsrhDfA w7PJzjVT6N3M3xlRSeOuCE7TuaoOUGK1TOWXRNvKgBdz0P3BKTSITl6X99F5thQQiZqf dwdzvLNl4zHCYxpOwTrfq8+gmNzlNs3zyVpso= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719123722; x=1719728522; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TCJ3yrcRCTn0u73bNdwHVe4hHf426clJbGsJfyTyJhs=; b=cWCxz4pwXh5HrSO8WHos/6ep15nUxDxIM1RhraFcaK1N7u4drRtXaXmpuoHQYpyaB1 +xdsiYQOnDi73ZBQ7tc3GytdItI82gyxRIn53or3n4ZJk6Vga0CfO2r8Nyk4pDHEGTLG TMhK/XiQxWuyBkl8Lll6+xtJ3+yYuG7Tw0zw63/rjO/PxM8uGXjBqp5OSH2yzeHLe0rT JIt9O8rk179kXldpnr427YOnBQ9R1fuU1TRfvMd3CAFlaeB7hCyBwb9hbZPcVSNXoB+Z 43mOErlsZcWjll9OOHFETnXcWVR5XniOX/S2Lz4sP+PR7kS5QNXj9zip0HhFX+5Wt7oI iSUQ== X-Forwarded-Encrypted: i=1; AJvYcCWWfjAh6B3xU+lsYXvD9pWEGc/XpDOqbGDm2420QaJ5qaWJDl/h/TZgHAG1bKYGSob+i58HEFe4uze+t9glKHib3rL3D3YjWToBmeVAIf3Lptp2 X-Gm-Message-State: AOJu0Yw2/xWdnfMukDNj7ppqpn9uHQk2wgOnwTPsHyjnO+kQEkSumYib KMaHl3UJmSK1yOKBWFpNXPh574hvNuJDWFpbhM9SwQRbqyt/srW+wa/2Z7x7tw== X-Google-Smtp-Source: AGHT+IFPPzwWWiI/Cd3TiVIA+bl6jzemiOEMJVxwCe/xFU15q4VID2JgmFl3ON4lzT2DbOXpUDfhyw== X-Received: by 2002:a5b:7c3:0:b0:e02:9dd0:e637 with SMTP id 3f1490d57ef6-e0303f2c949mr1170823276.22.1719123721717; Sat, 22 Jun 2024 23:22:01 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e02e65dbb2asm2070879276.61.2024.06.22.23.21.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2024 23:22:01 -0700 (PDT) Date: Sat, 22 Jun 2024 23:21:57 -0700 From: Noah Misch To: Peter Eisentraut Cc: Euler Taveira , Amit Kapila , Shlok Kyal , "kuroda.hayato@fujitsu.com" , Tomas Vondra , "pgsql-hackers@lists.postgresql.org" , Michael Paquier , Andres Freund , Ashutosh Bapat , =?iso-8859-1?Q?Fabr=EDzio?= de Royes Mello , vignesh C Subject: Re: speed up a logical replica setup Message-ID: <20240623062157.97.nmisch@google.com> References: <2f0b73f3-e7c0-4e95-9712-1993442a6b64@app.fastmail.com> <34637e7f-0330-420d-8f45-1d022962d2fe@app.fastmail.com> <7a970912-0b77-4942-84f7-2c9ca0bc05a5@eisentraut.org> <44de4e04-db22-40ed-8ba9-46387dc8bf83@app.fastmail.com> <3fa9ef0f-b277-4c13-850a-8ccc04de1406@eisentraut.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3fa9ef0f-b277-4c13-850a-8ccc04de1406@eisentraut.org> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Mar 25, 2024 at 12:55:39PM +0100, Peter Eisentraut wrote: > I have committed your version v33. > commit d44032d > --- /dev/null > +++ b/src/bin/pg_basebackup/pg_createsubscriber.c > +static char * > +concat_conninfo_dbname(const char *conninfo, const char *dbname) > +{ > + PQExpBuffer buf = createPQExpBuffer(); > + char *ret; > + > + Assert(conninfo != NULL); > + > + appendPQExpBufferStr(buf, conninfo); > + appendPQExpBuffer(buf, " dbname=%s", dbname); pg_createsubscriber fails on a dbname containing a space. Use appendConnStrVal() here and for other params in get_sub_conninfo(). See the CVE-2016-5424 commits for more background. For one way to test this scenario, see generate_db() in the pg_upgrade test suite. > +static char * > +create_logical_replication_slot(PGconn *conn, struct LogicalRepInfo *dbinfo) > +{ > + PQExpBuffer str = createPQExpBuffer(); > + PGresult *res = NULL; > + const char *slot_name = dbinfo->replslotname; > + char *slot_name_esc; > + char *lsn = NULL; > + > + Assert(conn != NULL); > + > + pg_log_info("creating the replication slot \"%s\" on database \"%s\"", > + slot_name, dbinfo->dbname); > + > + slot_name_esc = PQescapeLiteral(conn, slot_name, strlen(slot_name)); > + > + appendPQExpBuffer(str, > + "SELECT lsn FROM pg_catalog.pg_create_logical_replication_slot(%s, 'pgoutput', false, false, false)", This is passing twophase=false, but the patch does not mention prepared transactions. Is the intent to not support workloads containing prepared transactions? If so, the documentation should say that, and the tool likely should warn on startup if max_prepared_transactions != 0. > +static void > +create_publication(PGconn *conn, struct LogicalRepInfo *dbinfo) > +{ > + appendPQExpBuffer(str, "CREATE PUBLICATION %s FOR ALL TABLES", > + ipubname_esc); This tool's documentation says it "guarantees that no transaction will be lost." I tried to determine whether achieving that will require something like the fix from https://postgr.es/m/flat/de52b282-1166-1180-45a2-8d8917ca74c6@enterprisedb.com. (Not exactly the fix from that thread, since that thread has not discussed the FOR ALL TABLES version of its race condition.) I don't know. On the one hand, pg_createsubscriber benefits from creating a logical slot after creating the publication. That snapbuild.c process will wait for running XIDs. On the other hand, an INSERT/UPDATE/DELETE acquires its RowExclusiveLock and builds its relcache entry before assigning an XID, so perhaps the snapbuild.c process isn't enough to prevent that thread's race condition. What do you think?