Thread: Is there a way to ask PostgreSQL for the name of the computer it's running on?

Is there a way to ask PostgreSQL for the name of the computer it's running on?

From
Rob Richardson
Date:

My customer has 3 computers.  The PostgreSQL service could be running on either of two of them.  There is currently no way in our system to determine which one it is running on.  The third computer sometimes needs to know which of the other two computers is active.  It would be enough to know which computer is running the PostgreSQL service.  Is the name of the server available in a PostgreSQL database, so that it could be retrieved using a query? 

 

The computers are running Windows Server 2003.

 

Thank you very much.

 

RobR

Rob Richardson wrote:
> My customer has 3 computers.  The PostgreSQL service could be running
on either of two of them.  There
> is currently no way in our system to determine which one it is running
on.  The third computer
> sometimes needs to know which of the other two computers is active.
It would be enough to know which
> computer is running the PostgreSQL service.  Is the name of the server
available in a PostgreSQL
> database, so that it could be retrieved using a query?

As far as I know, you'd have to write a function
in C, PL/PerlU or something similar that runs an OS
command for you.

Yours,
Laurenz Albe

On 06/13/2012 09:33 PM, Rob Richardson wrote:

My customer has 3 computers.  The PostgreSQL service could be running on either of two of them.  There is currently no way in our system to determine which one it is running on.  The third computer sometimes needs to know which of the other two computers is active.  It would be enough to know which computer is running the PostgreSQL service.  Is the name of the server available in a PostgreSQL database, so that it could be retrieved using a query? 

 

I am unaware of any such query. However "show listen_addresses;" might allow you to achieve your goal.

Cheers,
Steve

Re: Is there a way to ask PostgreSQL for the name of the computer it's running on?

From
Guillaume Lelarge
Date:
On Thu, 2012-06-14 at 04:33 +0000, Rob Richardson wrote:
> My customer has 3 computers.  The PostgreSQL service could be running on either of two of them.  There is currently
noway in our system to determine which one it is running on.  The third computer sometimes needs to know which of the
othertwo computers is active.  It would be enough to know which computer is running the PostgreSQL service.  Is the
nameof the server available in a PostgreSQL database, so that it could be retrieved using a query? 
>

You can have its IP address, but not its name, unless you write a C or
PL/perlU function.


--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com


Hi

SELECT inet_server_addr();

On Thu, Jun 14, 2012 at 4:43 PM, Guillaume Lelarge <guillaume@lelarge.info> wrote:
On Thu, 2012-06-14 at 04:33 +0000, Rob Richardson wrote:
> My customer has 3 computers.  The PostgreSQL service could be running on either of two of them.  There is currently no way in our system to determine which one it is running on.  The third computer sometimes needs to know which of the other two computers is active.  It would be enough to know which computer is running the PostgreSQL service.  Is the name of the server available in a PostgreSQL database, so that it could be retrieved using a query?
>

You can have its IP address, but not its name, unless you write a C or
PL/perlU function.


--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



--
Cordialmente,

Ing. Hellmuth I. Vargas S.
Esp. Telemática y Negocios por Internet
PostgreSQL DBA
CREATE OR REPLACE FUNCTION get_hostname()
  RETURNS text AS
$BODY$use Sys::Hostname;
return hostname;$BODY$
  LANGUAGE plperlu VOLATILE;


--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Is-there-a-way-to-ask-PostgreSQL-for-the-name-of-the-computer-it-s-running-on-tp5712539p5713452.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.