Re: Fetching Server configured port from C Module

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Mike Roest <mike(dot)roest(at)replicon(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Fetching Server configured port from C Module
Date: 2013-04-17 19:21:32
Message-ID: 20130417192132.GJ4602@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 17, 2013 at 01:08:18PM -0600, Mike Roest wrote:
> Hi There,
> I'm having a bit of an issue finding a C function to fetch the configured
> server port from a C module.
>
> We have written a C module to allow for remote clients to call a function to
> run pg_dump/pg_restore remotely but create files locally on the db server.
>
> Currently it works fine if the client connects through a network socket as
> we're using inet_server_port to get the port to pass onto pg_dump/restore. But
> if the client is connected through a unix socket (actually a remote client
> connecting to pgbouncer which is connecting to postgres though the unix socket)
> inet_server_port is null. I've looked for a function that we can use to get
> the configured server port but haven't had any luck.
>
> I could hard code the port in the module when we build it but it would be nice
> to be able to change the configured postgres port and not have to rebuild the
> module.

Well, there are technically no _ports_ in unix-domain sockets. However,
the TCP port number is used to construct the socket file; I think you
can use the simple "port" server-side variable for this; does this help
you?

test=> SELECT setting FROM pg_settings WHERE name = 'port';
setting
---------
5432
(1 row)

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2013-04-17 19:22:23 Re: Fetching Server configured port from C Module
Previous Message Mike Roest 2013-04-17 19:08:18 Fetching Server configured port from C Module