[9.1] pg_stat_get_backend_server_addr

Lists: pgsql-hackers
From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [9.1] pg_stat_get_backend_server_addr
Date: 2010-05-27 19:32:25
Message-ID: 1274988745.18581.36.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

There are functions pg_stat_get_backend_client_addr and
pg_stat_get_backend_client_port, which are exposed through the
pg_stat_activity view, but there is no straightforward way to get the
server-side address and port of a connection. This is obviously much
less commonly needed than the client information, but it's still
sometimes useful on hosts with many IP addresses.

I suggest that we add the functions pg_stat_get_backend_server_addr and
pg_stat_get_backend_server_port, but don't expose them in
pg_stat_activity. (_server_port is really mostly for symmetry, because
you can't currently bind to multiple ports.)

Patch attached. Comments?

Attachment Content-Type Size
get-server-addr.patch text/x-patch 8.2 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-05-27 19:44:52
Message-ID: 6732.1274989492@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> There are functions pg_stat_get_backend_client_addr and
> pg_stat_get_backend_client_port, which are exposed through the
> pg_stat_activity view, but there is no straightforward way to get the
> server-side address and port of a connection. This is obviously much
> less commonly needed than the client information,

... indeed. Is it worth burdening the pg_stats mechanism with this?
The use case seems vanishingly thin.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-05-28 13:41:24
Message-ID: 201005281341.o4SDfOo04222@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > There are functions pg_stat_get_backend_client_addr and
> > pg_stat_get_backend_client_port, which are exposed through the
> > pg_stat_activity view, but there is no straightforward way to get the
> > server-side address and port of a connection. This is obviously much
> > less commonly needed than the client information,
>
> ... indeed. Is it worth burdening the pg_stats mechanism with this?
> The use case seems vanishingly thin.

I am confused how this is different from inet_server_addr() and
inet_server_port().

Also, these functions return nothing for unix domain connections.
Should they, particularly for the port number which we do use to map to
a socket name?

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-05-28 14:19:02
Message-ID: 24926.1275056342@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Tom Lane wrote:
>> ... indeed. Is it worth burdening the pg_stats mechanism with this?
>> The use case seems vanishingly thin.

> I am confused how this is different from inet_server_addr() and
> inet_server_port().

I think the point is to let someone find out *from another session*
which server port number a particular session is using. I fail to see
a significant use case for that, though.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-05-28 14:21:23
Message-ID: 201005281421.o4SELNq13210@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Tom Lane wrote:
> >> ... indeed. Is it worth burdening the pg_stats mechanism with this?
> >> The use case seems vanishingly thin.
>
> > I am confused how this is different from inet_server_addr() and
> > inet_server_port().
>
> I think the point is to let someone find out *from another session*
> which server port number a particular session is using. I fail to see
> a significant use case for that, though.

Uh, aren't they all using the same server port number, e.g. 5432? Is
the issue different IP addresses for the same server?

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


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-05-28 15:01:58
Message-ID: 1275058918.6851.8.camel@fsopti579.F-Secure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On fre, 2010-05-28 at 10:21 -0400, Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > Tom Lane wrote:
> > >> ... indeed. Is it worth burdening the pg_stats mechanism with this?
> > >> The use case seems vanishingly thin.
> >
> > > I am confused how this is different from inet_server_addr() and
> > > inet_server_port().
> >
> > I think the point is to let someone find out *from another session*
> > which server port number a particular session is using. I fail to see
> > a significant use case for that, though.
>
> Uh, aren't they all using the same server port number, e.g. 5432? Is
> the issue different IP addresses for the same server?

Yes, I would like to know who is connecting to what IP address. It's
useful if you have HA setups and you need to check which way your
connections are going.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-05-28 15:02:52
Message-ID: 201005281502.o4SF2q320124@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut wrote:
> On fre, 2010-05-28 at 10:21 -0400, Bruce Momjian wrote:
> > Tom Lane wrote:
> > > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > > Tom Lane wrote:
> > > >> ... indeed. Is it worth burdening the pg_stats mechanism with this?
> > > >> The use case seems vanishingly thin.
> > >
> > > > I am confused how this is different from inet_server_addr() and
> > > > inet_server_port().
> > >
> > > I think the point is to let someone find out *from another session*
> > > which server port number a particular session is using. I fail to see
> > > a significant use case for that, though.
> >
> > Uh, aren't they all using the same server port number, e.g. 5432? Is
> > the issue different IP addresses for the same server?
>
> Yes, I would like to know who is connecting to what IP address. It's
> useful if you have HA setups and you need to check which way your
> connections are going.

OK, at least now I understand the goal.

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


From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-07-22 05:12:29
Message-ID: 1279775549.23350.9.camel@jdavis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, 2010-05-28 at 18:01 +0300, Peter Eisentraut wrote:
> Yes, I would like to know who is connecting to what IP address. It's
> useful if you have HA setups and you need to check which way your
> connections are going.

A few comments on this patch:

The two functions aren't perfectly symmetric, because
pg_stat_get_backend_server_port() returns -1 if it's a unix socket, and
pg_stat_get_backend_server_addr() returns NULL (which is also overloaded
to mean that you don't have permissions). So, perhaps it's better to
just have pg_stat_get_backend_server_addr(), which is the one you want,
anyway.

Also, for the permission check I'm inclined to throw an error rather
than return NULL. If the function is being called from a view, it's
understandable that we don't want to throw an error; but this function
isn't being called from a view. Based on your use-case, I'm more worried
about the HA system getting confused with a NULL result, and then
failing mysteriously with no error message.

Regards,
Jeff Davis


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-07-22 20:01:26
Message-ID: 1279828886.16475.1.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On ons, 2010-07-21 at 22:12 -0700, Jeff Davis wrote:
> The two functions aren't perfectly symmetric, because
> pg_stat_get_backend_server_port() returns -1 if it's a unix socket,
> and
> pg_stat_get_backend_server_addr() returns NULL (which is also
> overloaded
> to mean that you don't have permissions). So, perhaps it's better to
> just have pg_stat_get_backend_server_addr(), which is the one you
> want,
> anyway.

This mirrors exactly the pg_stat_get_backend_client_* behaviors. I
don't much like them either, but I think it'd be worse to make it
inconsistent.


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [9.1] pg_stat_get_backend_server_addr
Date: 2010-08-23 19:16:42
Message-ID: 1282591002.3075.0.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2010-05-27 at 22:32 +0300, Peter Eisentraut wrote:
> I suggest that we add the functions pg_stat_get_backend_server_addr
> and pg_stat_get_backend_server_port, but don't expose them in
> pg_stat_activity. (_server_port is really mostly for symmetry,
> because you can't currently bind to multiple ports.)

I think I'm not going to pursue this patch anymore. There hasn't been
any enthusiasm from anyone else, and if necessary the information can be
carved out of netstat.