From: | Dominique Devienne <ddevienne(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Who am I? Where am I connected? |
Date: | 2022-05-18 15:31:19 |
Message-ID: | CAFCRh--WwvgCYmMetQ1ESRCKXWXg0WbdGjQZEXDKA2Y1fzWSeQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, May 18, 2022 at 12:07 PM Dominique Devienne <ddevienne(at)gmail(dot)com> 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?
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2022-05-18 15:43:03 | Re: Who am I? Where am I connected? |
Previous Message | Ian Lawrence Barwick | 2022-05-18 14:15:28 | Re: show primary_conninfo unchanged after promotion? |