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

Re: Querying the hostname of the server

From: Glyn Astill <glynastill(at)yahoo(dot)co(dot)uk>
To: pgsql-admin(at)postgresql(dot)org, "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
Subject: Re: Querying the hostname of the server
Date: 2010-04-30 14:43:49
Message-ID: 292551.66852.qm@web23604.mail.ird.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-admin
--- On Fri, 30/4/10, Ross J. Reedstrom <reedstrm(at)rice(dot)edu> wrote:

> > Hi,
> > 
> > I have a number of PostgreSQL servers which I often
> access through ssh
> > tunnel with Pgadmin3. I would like to double check
> which one I have landed
> > on (if the tunnel is really configured the way I
> want). Is there a way to
> > query the hostname from the catalogs?
> 
> Hmm, that's a bit tricky, since I assume you're using a
> local db
> connection inside the tunnel, so inet_server_addr()
> probably returns
> null. If you're talking unix/linux machines, then
> /etc/hostname _should_
> have the current hostname in it, so:
> 
> create temp table foo (t text);
> copy foo from '/etc/hostname';
> select * from foo;
> drop table foo;
> 
> Should work.
> 

Or you could do something like:

CREATE OR REPLACE FUNCTION hostname()
RETURNS text AS
$BODY$
	$host = `hostname`;
        return $host;
$BODY$
LANGUAGE 'plperlu';




      

In response to

Responses

pgsql-admin by date

Next:From: Achilleas MantziosDate: 2010-04-30 15:01:26
Subject: Re: Querying the hostname of the server
Previous:From: Péter KovácsDate: 2010-04-30 14:33:38
Subject: Re: Querying the hostname of the server

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