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 1rccvP-0017pr-7p for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Feb 2024 03:05:35 +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 1rccuO-002O0H-NK for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Feb 2024 03:04:33 +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 1rccuO-002Nzv-Dk for pgsql-hackers@lists.postgresql.org; Wed, 21 Feb 2024 03:04:32 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rccuJ-000C90-VF for pgsql-hackers@postgresql.org; Wed, 21 Feb 2024 03:04:31 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d746ce7d13so42197375ad.0 for ; Tue, 20 Feb 2024 19:04:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708484668; x=1709089468; darn=postgresql.org; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=5MsWlZXVt1td27dfMS9Bz5lPKcUOL8TmMTrxGBJZWog=; b=OUXyn4qnbjRSN85iErB1Xf/r/Tz5Y0ID05LR0ghtJn/JRlgsBmDO8jJ/LbX9+tD2C1 oWVAxAQkYfM1licRPJp6QtK0VkEmvHpPhECNqPTslYRMGjQ8OtiBveHk3NDycwA5XihU BS+EE6PtKnyCNq/9OQMt1y0szWY2lxUmak9ANsVajOAvS03hAZGW+dVpTSz1KIXN3xqQ hNOOcNC5BREXULAD9vn9BM+zDE6Sh3eBdInkL4ozMQfxauMNCsrb7/xgnfbWDMMjeu58 Q0mU4gqp7YMjYzy65F0ns88CE1NEkbx0cFtj0bR7hItPY8Kv9Zhm3pxrxXYkjG4giKaU LUOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708484668; x=1709089468; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5MsWlZXVt1td27dfMS9Bz5lPKcUOL8TmMTrxGBJZWog=; b=YxPgDcRofrO92YqJeXZR8Pfldf8YN9XA+4XDJPBcMDIT9EOowaWtH5pABhcOLP0QGK YZb8HLzVZ5e94BgsRvszQnb7e5fCy4i8QOn1W6CzCnOWI8WH7q90JGSwvNj07m91P0wL 1R6HLReKMZiAzhXOG6souiPh/+Y24edYBESMjmvLZj8eAXYxajaI2Ff9ejVBrOlX01ez 441OyfH0emOZTeVYaJ77UgDNdRu2x12AUfr0peHcUEzfAF6JHrf/QuTbV2TmSQIX/fXX k/o6bAw6HhtQYQrf3dbharNFCx8ESiIdGj9Kp1B5OOM3fCj7QhEoAso5qfcd4XpzNv5u eC2g== X-Forwarded-Encrypted: i=1; AJvYcCUnHt026dxVG/BLNO4AfOSXGQ4Ew/+L+fABUKOJ5SIWWu3IgyF8vzZKRCVE261y00Bg2pxEVYfV3qkuK5nYMNohNDLIk08SRzhmT0zt X-Gm-Message-State: AOJu0YxBEldjEGbDVjux2tqXk/HiXg5R+9p92z9+nT2dsPSjPk7P4+wQ dscxMTG0rDTiRp/raWeWLRpT4ld23RwlIHQljFPkjH0lM/kNqdVh X-Google-Smtp-Source: AGHT+IHVs4zTG4ywng44E/5brCPhll0oBJ84QhHBwrdQqTylA+DsatRLREVOSL5MoNFvmko0+6n25g== X-Received: by 2002:a17:903:234a:b0:1dc:1831:8ecc with SMTP id c10-20020a170903234a00b001dc18318eccmr3728675plh.53.1708484667879; Tue, 20 Feb 2024 19:04:27 -0800 (PST) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id q11-20020a170902c74b00b001dc11f90512sm2451371plq.126.2024.02.20.19.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 19:04:27 -0800 (PST) Date: Wed, 21 Feb 2024 12:04:24 +0900 (JST) Message-Id: <20240221.120424.79274783106518358.horikyota.ntt@gmail.com> To: robertmhaas@gmail.com Cc: kuroda.hayato@fujitsu.com, barwick@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Have pg_basebackup write "dbname" in "primary_conninfo"? From: Kyotaro Horiguchi In-Reply-To: References: User-Agent: Mew version 6.8 on Emacs 27.2 Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Wed_Feb_21_12_04_24_2024_487)--" Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ----Next_Part(Wed_Feb_21_12_04_24_2024_487)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit At Tue, 20 Feb 2024 19:56:10 +0530, Robert Haas wrote in > It seems like maybe somebody should look into why this is happening, > and perhaps fix it. GetConnection()@streamutil.c wants to ensure conninfo has a fallback database name ("replication"). However, the function seems to be ignoring the case where neither dbname nor connection string is given, which is the first case Kuroda-san raised. The second case is the intended behavior of the function. > /* pg_recvlogical uses dbname only; others use connection_string only. */ > Assert(dbname == NULL || connection_string == NULL); And the function incorrectly assumes that the connection string requires "dbname=replication". > * Merge the connection info inputs given in form of connection string, > * options and default values (dbname=replication, replication=true, etc.) But the name is a pseudo database name only used by pg_hba.conf (maybe) , which cannot be used as an actual database name (without quotation marks, or unless it is actually created). The function should not add the fallback database name because the connection string for physical replication connection doesn't require the dbname parameter. (attached patch) About the proposed patch, pg_basebackup cannot verify the validity of the dbname. It could be problematic. Although I haven't looked the original thread, it seems that the dbname is used only by pg_sync_replication_slots(). If it is true, couldn't we make the SQL function require a database name to make a connection, instead of requiring it in physical-replication conninfo? regards. -- Kyotaro Horiguchi NTT Open Source Software Center ----Next_Part(Wed_Feb_21_12_04_24_2024_487)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="do_not_set_fallback_dbname.txt" diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index 56d1b15951..da63a04de4 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -78,7 +78,7 @@ GetConnection(void) /* * Merge the connection info inputs given in form of connection string, - * options and default values (dbname=replication, replication=true, etc.) + * options and default values (replication=true, etc.) */ i = 0; if (connection_string) @@ -96,14 +96,6 @@ GetConnection(void) keywords = pg_malloc0((argcount + 1) * sizeof(*keywords)); values = pg_malloc0((argcount + 1) * sizeof(*values)); - /* - * Set dbname here already, so it can be overridden by a dbname in the - * connection string. - */ - keywords[i] = "dbname"; - values[i] = "replication"; - i++; - for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++) { if (conn_opt->val != NULL && conn_opt->val[0] != '\0') ----Next_Part(Wed_Feb_21_12_04_24_2024_487)----