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


Reply via email to