pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Chris Hoover <revoohc@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Is there anyway to retrieve server name and/or ip from query
Date: Fri, 29 Jul 2005 08:15:31 -0600
Message-ID: <20050729141531.GA83745@winnie.fuhr.org> (raw)
In-Reply-To: <1d219a6f05072906482b1d37c4@mail.gmail.com>
References: <1d219a6f05072906482b1d37c4@mail.gmail.com>

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/



view thread (3+ messages)

Message-ID: <20050729141531.GA83745@winnie.fuhr.org>
Permalink:  ../20050729141531.GA83745@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050729141531.GA83745@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mike@fuhr.org, revoohc@gmail.com
  Subject: Re: Is there anyway to retrieve server name and/or ip from query
  In-Reply-To: <20050729141531.GA83745@winnie.fuhr.org>
  References: <1d219a6f05072906482b1d37c4@mail.gmail.com> <20050729141531.GA83745@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox