Re: Current Connection Information

From: Aleksander Alekseev <aleksander(at)timescale(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Cc: Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br>
Subject: Re: Current Connection Information
Date: 2024-01-25 11:51:07
Message-ID: CAJ7c6TP2JV7ZBE7+DHu3aM6k-xOQdexOxSn=KOMfVwVnH9fTBA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

> It would be viable and appropriate to implement a unified function that provides important information about the current connection?
>
> Just an example: "Current Connection Informations".
>
> I implemented it in PL/pgSQL to demonstrate the idea, see on GitHub:
> https://github.com/maiquelgrassi/DBA-toolkit/blob/main/cluster/dba_whoami_function.sql

I believe one would typically do something like this:

```
select * from pg_stat_activity where pid = pg_backend_pid();
```

On top of that psql can be configured to display useful information, e.g.:

```
$ cat ~/.psqlrc
\timing on
select (case when pg_is_in_recovery() then 'replica' else 'master'
end) as master_or_replica
\gset
\set PROMPT1 '%p (%:master_or_replica:) =# '
```

Personally I somewhat doubt that there is a one-size-fits-all
equivalent of `whoami` for Postgres. E.g. one person would like to see
a list of extensions available in the current database while for
another this is redundant information.

Even if we do this I don't think this should be a PL/pgSQL function
but rather a \whoami command for psql. This solution however will
leave users of DataGrip and similar products unhappy.

--
Best regards,
Aleksander Alekseev

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2024-01-25 11:51:28 Re: Synchronizing slots from primary to standby
Previous Message shveta malik 2024-01-25 11:47:14 Re: Synchronizing slots from primary to standby