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 1rXedW-00BqVL-AO for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 09:54:34 +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 1rXedU-009U8L-Ui for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Feb 2024 09:54:32 +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 1rXedU-009U5q-JG for pgsql-hackers@lists.postgresql.org; Wed, 07 Feb 2024 09:54:32 +0000 Received: from mout-u-204.mailbox.org ([2001:67c:2050:101:465::204]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rXedR-005W4f-8m for pgsql-hackers@postgresql.org; Wed, 07 Feb 2024 09:54:31 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4TVFnr3Jlrz9sV6; Wed, 7 Feb 2024 10:54:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ewie.name; s=MBO0001; t=1707299664; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=0bRffE0WyCLhbl5EDVNbhSqgov9BuHKgCp8wGS/323E=; b=RhVZMfebaka11YbkmQ3oRkqG9uS2pbqOJBP6jMiKR47diQLxNNT4fay5qk+/87ltu1rpzq dNkYqDLuozxGrAt2BE5FLS9S4eDNstoDOkIDmgDjiZooUKMnddNx/PTorK4cjelPHK7D2R KTh6WWvc+STGUSu1YsleqZrQ9UOncV71ofjadSz55Pyh5fAmQTPf2n+v0urH0Wc73ovaCh qPQuWM3Z4BEMBe+GmDkQ4O7YkFB0FnePTLfQjj8MQoeja1Tj715NKpRFcIccvIVZpJqL5H USRARuv1QW+PYLiyCAs1RVvngfLJ6YCF/tdiIf9IkIRDDobhpYS0sbbdtzanfA== Date: Wed, 7 Feb 2024 10:54:21 +0100 From: Erik Wienhold To: Maiquel Grassi Cc: Nathan Bossart , "pgsql-hackers@postgresql.org" Subject: Re: Psql meta-command conninfo+ Message-ID: <2quadime4klthrjwamiqmwqizfptoabi74dfjzzs3cjba4j6tp@lqzijrwi6i2o> References: <20240206181919.GA3853632@nathanxps13> <20240206210605.GA3903769@nathanxps13> <20240206211205.GA3903996@nathanxps13> <20240206215022.GA3452@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-02-07 05:13 +0100, Maiquel Grassi wrote: > On Tue, Feb 06, 2024 at 09:45:54PM +0000, Maiquel Grassi wrote: > > My initial idea has always been that they should continue to appear > > because \conninfo+ should show all the things that \conninfo shows and > > add more information. I think that's the purpose of the 'plus.' Now we're > > on a better path than the initial one. We can still add the socket > > directory and the host. > > Agreed. > > --//-- > > I believe it's resolved reasonably well this way: > > SELECT > pg_catalog.current_database() AS "Database", > current_user AS "User", > pg_catalog.current_setting('server_version') AS "Server Version", > CASE > WHEN pg_catalog.inet_server_addr() IS NULL > THEN 'NULL' > ELSE pg_catalog.inet_server_addr()::text > END AS "Server Address", Should be NULL instead of string 'NULL'. So the entire CASE expression is redundant and you can just return pg_catalog.inet_server_addr(). > pg_catalog.current_setting('port') AS "Port", > CASE > WHEN pg_catalog.inet_client_addr() IS NULL > THEN 'NULL' > ELSE pg_catalog.inet_client_addr()::text > END AS "Client Address", > CASE > WHEN pg_catalog.inet_client_port() IS NULL > THEN 'NULL' > ELSE pg_catalog.inet_client_port()::text > END AS "Client Port", Same here. > pg_catalog.pg_backend_pid() AS "Session PID", > CASE > WHEN pg_catalog.current_setting('unix_socket_directories') = '' > THEN 'NULL' > ELSE pg_catalog.current_setting('unix_socket_directories') > END AS "Socket Directory", The CASE expression can be simplified to: nullif(pg_catalog.current_setting('unix_socket_directories'), '') > CASE > WHEN > pg_catalog.inet_server_addr() IS NULL > AND pg_catalog.inet_client_addr() IS NULL > THEN 'NULL' > WHEN > pg_catalog.inet_server_addr() = pg_catalog.inet_client_addr() > THEN 'localhost' Is it safe to assume localhost here? \conninfo prints localhost only when I connect with psql -hlocalhost: $ psql -hlocalhost postgres psql (16.1) postgres=# \conninfo You are connected to database "postgres" as user "ewie" on host "localhost" (address "::1") at port "5432". postgres=# \q $ psql -h127.0.0.1 postgres psql (16.1) postgres=# \conninfo You are connected to database "postgres" as user "ewie" on host "127.0.0.1" at port "5432". > ELSE pg_catalog.inet_server_addr()::text > END AS "Host"; -- Erik