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

Started by Rob Richardsonalmost 14 years ago6 messagesgeneral
Jump to latest
#1Rob Richardson
RDRichardson@rad-con.com

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

#2Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Rob Richardson (#1)
Re: Is there a way to ask PostgreSQL for the name of the computer it's running on?

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

#3Steve Crawford
scrawford@pinpointresearch.com
In reply to: Rob Richardson (#1)
Re: Is there a way to ask PostgreSQL for the name of the computer it's running on?

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

#4Guillaume Lelarge
guillaume@lelarge.info
In reply to: Rob Richardson (#1)
Re: Is there a way to ask PostgreSQL for the name of the computer it's running on?

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

#5Hellmuth Vargas
hivs77@gmail.com
In reply to: Guillaume Lelarge (#4)
Re: Is there a way to ask PostgreSQL for the name of the computer it's running on?

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

#6aasat
satriani@veranet.pl
In reply to: Rob Richardson (#1)
Re: Is there a way to ask PostgreSQL for the name of the computer it's running on?

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.