Search Postgresql Archives

Re: Who am I? Where am I connected?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 18, 2022 at 12:07 PM Dominique Devienne <ddevienne@xxxxxxxxx> wrote:
> LibPQ has various defaults for the host, user, and DB name.
> There's also the password file, the service file and service name.
> In the example below, I can connect with a "naked" psql invocation.
>
> Once connected, can I find out all aspects of the connection string?

Thank you all for \conninfo.

I was more thinking at the time about the SQL-way to get that info,
not the psql way.
But thanks to https://www.postgresql.org/docs/current/functions-info.html
I managed
to emulate it, modulo resolving the server's IP into a hostname.

ddevienne=> \conninfo
You are connected to database "ddevienne" as user "ddevienne" on host
"localhost" (address "::1") at port "5432".

ddevienne=> select current_database() || ' ' || session_user || ' ' ||
inet_server_addr() || ':' || inet_server_port();
             ?column?
----------------------------------
 ddevienne ddevienne ::1/128:5432
(1 row)

> Or where they came from, like a pgpass.conf or service file?

OTOH, no one replied to that part of the question.

How to know if the user or database name was defaulted?
Or came from a service-file, using a given service name?
Is there no way, except by reverse-engineering the logic of the
env-vars and built-in defaults?





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux