Thread: Current Connection Information

Current Connection Information

From
Maiquel Grassi
Date:

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

Regards,
Maiquel.

Re: Current Connection Information

From
Aleksander Alekseev
Date:
Hi,

> It would be viable and appropriate to implement a unified function that provides important information about the
currentconnection?
 
>
> 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



Re: Current Connection Information

From
Aleksander Alekseev
Date:
Hi Maiquel,

I assume you wanted to reply to the mailing list and add me to cc:
(aka "Reply to All") but sent the e-mail off-list by mistake, so
quoting it here:

> Hi Aleksander,
>
> Why do you think DataGrip users would be unhappy?
>
> I liked your suggestion of creating something like \whoami for psql. Wouldn't it be worth trying that?
>
> The output doesn't necessarily need to include all the fields I added in my PL/pgSQL function; it can be reduced or
haveother fields added.
 
>
>
> What do you think?

Answering the questions:

> Why do you think DataGrip users would be unhappy?

I must admit I'm not well familiar with such products. My humble
understanding is that in most cases they use JDBC, libpq or other
drivers and thus can't benefit from something implemented in psql.

> I liked your suggestion of creating something like \whoami for psql. Wouldn't it be worth trying that?

IMO it's worth trying submitting the patch, if your time permits it of course.

-- 
Best regards,
Aleksander Alekseev



RE: Current Connection Information

From
Maiquel Grassi
Date:
Hi Aleksander,

>>I assume you wanted to reply to the mailing list and add me to cc:

>>(aka "Reply to All") but sent the e-mail off-list by mistake, so
>>quoting it here:

Yes, tks for that.

>>IMO it's worth trying submitting the patch, if your time permits it of course.

I've been spending a little time thinking about this.

Regards,
Maiquel.