patternsqlMinor
get postgreSQL client computer name
Viewed 0 times
postgresqlclientgetnamecomputer
Problem
Is there a way in postgres to
SELECT the current clients name? I wish to create an audit field using the clients computer name.Solution
Yes.
By default, connection log messages only show the IP address of the
connecting host. Turning this parameter on causes logging of the host
name as well. Note that depending on your host name resolution setup
this might impose a non-negligible performance penalty. This parameter
can only be set in the postgresql.conf file or on the server command
line.
select *
from pg_stat_activity
where pid = pg_backend_pid();client_hostname And client_addr are relevant.log_hostname needs enabling in order for the name to be resolved correctly. See this link:By default, connection log messages only show the IP address of the
connecting host. Turning this parameter on causes logging of the host
name as well. Note that depending on your host name resolution setup
this might impose a non-negligible performance penalty. This parameter
can only be set in the postgresql.conf file or on the server command
line.
Code Snippets
select *
from pg_stat_activity
where pid = pg_backend_pid();Context
StackExchange Database Administrators Q#237670, answer score: 4
Revisions (0)
No revisions yet.