HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

get postgreSQL client computer name

Submitted by: @import:stackexchange-dba··
0
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.

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.