Skip site navigation (1) Skip section navigation (2)

Re: Is there anyway to retrieve server name and/or ip from query

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Chris Hoover <revoohc(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Is there anyway to retrieve server name and/or ip from query
Date: 2005-07-29 14:15:31
Message-ID: 20050729141531.GA83745@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-admin
On Fri, Jul 29, 2005 at 09:48:28AM -0400, Chris Hoover wrote:
> Subject pretty much says it all.  Is there a way in a sql query to
> have it return the server name and/or the server ip address of the
> PostgreSQL server?

Depends on the version of PostgreSQL.  In 8.0 you can use
inet_server_addr():

http://www.postgresql.org/docs/8.0/static/functions-info.html

Note that inet_server_addr() returns the IP address that you connected
to, so it won't return all IP addresses of a multihomed host.  Also,
it will return NULL if you're connected via a local (Unix-domain) socket.

If you're using an earlier version of PostgreSQL, or if you want
more information that the standard functions provide, then you could
write a function in a language like PL/Perl, PL/Tcl, PL/Python, etc.
Example:

CREATE FUNCTION hostname() RETURNS text AS '
use Sys::Hostname;
return hostname;
' LANGUAGE plperlu;

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

pgsql-admin by date

Next:From: Guido BarosioDate: 2005-07-29 14:17:19
Subject: Re: start postgresql8 with -o "-i" option
Previous:From: Bruce MomjianDate: 2005-07-29 14:00:29
Subject: Re: Is there anyway to retrieve server name and/or ip from query

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group