X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DEE9C52840 for ; Fri, 29 Jul 2005 11:15:35 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 51805-05 for ; Fri, 29 Jul 2005 14:15:32 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 1FCDC52815 for ; Fri, 29 Jul 2005 11:15:31 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j6TEFVQT029621 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Jul 2005 08:15:34 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j6TEFVwU083849; Fri, 29 Jul 2005 08:15:31 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j6TEFVEe083848; Fri, 29 Jul 2005 08:15:31 -0600 (MDT) (envelope-from mfuhr) Date: Fri, 29 Jul 2005 08:15:31 -0600 From: Michael Fuhr To: Chris Hoover Cc: pgsql-admin@postgresql.org Subject: Re: Is there anyway to retrieve server name and/or ip from query Message-ID: <20050729141531.GA83745@winnie.fuhr.org> References: <1d219a6f05072906482b1d37c4@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1d219a6f05072906482b1d37c4@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/245 X-Sequence-Number: 18301 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/