pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Wienhold <ewie@ewie.name>
To: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: psql \conninfo in tabular form?
Date: Tue, 7 Mar 2023 20:07:25 +0100 (CET)
Message-ID: <1899112657.14571.1678216045978@office.mailbox.org> (raw)
In-Reply-To: <4eed5377-3603-85b9-965e-f2bcd507c045@gmail.com>
References: <4eed5377-3603-85b9-965e-f2bcd507c045@gmail.com>

> On 07/03/2023 18:58 CET Ron <ronljohnsonjr@gmail.com> wrote:
>
> v13.10
>
> Instead of a sentence like this:
> You are connected to database "postgres" as user "postgres" via socket in
> "/var/run/postgresql" at port "5433".
>
> I'd rather have something tabular like:
>     keyword  |   value
> ------------+-----------------------
>    database  | postgres
>    user      | postgres
>    host      | /var/run/postgresql
>    port      |  5433

Define variable conninfo with the query in ~/.psqlrc:

	\set conninfo 'select * from (values (''database'', current_database()), (''user'', session_user), (''host'', coalesce(inet_server_addr()::text, current_setting(''unix_socket_directories''))), (''port'', coalesce(inet_server_port()::text, current_setting(''port'')))) t(keyword, value);'

And run it like that:

	postgres=# :conninfo
	 keyword  |      value
	----------+-----------------
	 database | postgres
	 user     | ewie
	 host     | /run/postgresql
	 port     | 5432
	(4 rows)

--
Erik





view thread (2+ messages)

Message-ID: <1899112657.14571.1678216045978@office.mailbox.org>
Permalink:  ../1899112657.14571.1678216045978@office.mailbox.org/
Also on:    postgresql.org/message-id/1899112657.14571.1678216045978@office.mailbox.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ewie@ewie.name, ronljohnsonjr@gmail.com
  Subject: Re: psql \conninfo in tabular form?
  In-Reply-To: <1899112657.14571.1678216045978@office.mailbox.org>
  References: <4eed5377-3603-85b9-965e-f2bcd507c045@gmail.com> <1899112657.14571.1678216045978@office.mailbox.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox