auxiliary processes in pg_stat_ssl

Started by Alvaro Herreraover 6 years ago8 messages
#1Alvaro Herrera
alvherre@2ndquadrant.com

I just noticed that we list auxiliary processes in pg_stat_ssl:

55432 13devel 28627=# select * from pg_stat_ssl ;
pid │ ssl │ version │ cipher │ bits │ compression │ client_dn │ client_serial │ issuer_dn
───────┼─────┼─────────┼────────────────────────┼──────┼─────────────┼───────────┼───────────────┼───────────
28618 │ f │ │ │ │ │ │ │
28620 │ f │ │ │ │ │ │ │
28627 │ t │ TLSv1.3 │ TLS_AES_256_GCM_SHA384 │ 256 │ f │ │ │
28616 │ f │ │ │ │ │ │ │
28615 │ f │ │ │ │ │ │ │
28617 │ f │ │ │ │ │ │ │
(6 filas)

55432 13devel 28627=# select pid, backend_type from pg_stat_activity ;
pid │ backend_type
───────┼──────────────────────────────
28618 │ autovacuum launcher
28620 │ logical replication launcher
28627 │ client backend
28616 │ background writer
28615 │ checkpointer
28617 │ walwriter
(6 filas)

But this seems pointless. Should we not hide those? Seems this only
happened as an unintended side-effect of fc70a4b0df38. It appears to me
that we should redefine that view to restrict backend_type that's
'client backend' (maybe include 'wal receiver'/'wal sender' also, not
sure.)

--
Álvaro Herrera http://www.twitter.com/alvherre

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#1)
Re: auxiliary processes in pg_stat_ssl

On 2019-Sep-04, Alvaro Herrera wrote:

I just noticed that we list auxiliary processes in pg_stat_ssl:

[...]

But this seems pointless. Should we not hide those? Seems this only
happened as an unintended side-effect of fc70a4b0df38. It appears to me
that we should redefine that view to restrict backend_type that's
'client backend' (maybe include 'wal receiver'/'wal sender' also, not
sure.)

[crickets]

Robert, Kuntal, any opinion on this?

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#3Robert Haas
robertmhaas@gmail.com
In reply to: Alvaro Herrera (#2)
Re: auxiliary processes in pg_stat_ssl

On Mon, Nov 4, 2019 at 8:26 AM Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

On 2019-Sep-04, Alvaro Herrera wrote:

I just noticed that we list auxiliary processes in pg_stat_ssl:

[...]

But this seems pointless. Should we not hide those? Seems this only
happened as an unintended side-effect of fc70a4b0df38. It appears to me
that we should redefine that view to restrict backend_type that's
'client backend' (maybe include 'wal receiver'/'wal sender' also, not
sure.)

[crickets]

Robert, Kuntal, any opinion on this?

I think if I were doing something about it, I'd probably try to filter
on a field that directly represents whether there is a connection,
rather than checking the backend type. That way, if the list of
backend types that have client connections changes later, there's
nothing to update. Like "WHERE client_port IS NOT NULL," or something
of that sort.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#4Euler Taveira
euler@timbira.com.br
In reply to: Alvaro Herrera (#1)
1 attachment(s)
Re: auxiliary processes in pg_stat_ssl

Em qua., 4 de set. de 2019 às 12:15, Alvaro Herrera
<alvherre@2ndquadrant.com> escreveu:

I just noticed that we list auxiliary processes in pg_stat_ssl:

55432 13devel 28627=# select * from pg_stat_ssl ;
pid │ ssl │ version │ cipher │ bits │ compression │ client_dn │ client_serial │ issuer_dn
───────┼─────┼─────────┼────────────────────────┼──────┼─────────────┼───────────┼───────────────┼───────────
28618 │ f │ │ │ │ │ │ │
28620 │ f │ │ │ │ │ │ │
28627 │ t │ TLSv1.3 │ TLS_AES_256_GCM_SHA384 │ 256 │ f │ │ │
28616 │ f │ │ │ │ │ │ │
28615 │ f │ │ │ │ │ │ │
28617 │ f │ │ │ │ │ │ │
(6 filas)

55432 13devel 28627=# select pid, backend_type from pg_stat_activity ;
pid │ backend_type
───────┼──────────────────────────────
28618 │ autovacuum launcher
28620 │ logical replication launcher
28627 │ client backend
28616 │ background writer
28615 │ checkpointer
28617 │ walwriter
(6 filas)

But this seems pointless. Should we not hide those? Seems this only
happened as an unintended side-effect of fc70a4b0df38. It appears to me
that we should redefine that view to restrict backend_type that's
'client backend' (maybe include 'wal receiver'/'wal sender' also, not
sure.)

Yep, it is pointless. BackendType that open connections to server are:
autovacuum worker, client backend, background worker, wal sender. I
also notice that pg_stat_gssapi is in the same boat as pg_stat_ssl and
we should constraint the rows to backend types that open connections.
I'm attaching a patch to list only connections in those system views.

--
Euler Taveira Timbira -
http://www.timbira.com.br/
PostgreSQL: Consultoria, Desenvolvimento, Suporte 24x7 e Treinamento

Attachments:

0001-Show-only-rows-that-open-connections-in-some-system-.patchtext/x-patch; charset=US-ASCII; name=0001-Show-only-rows-that-open-connections-in-some-system-.patchDownload
From aca42a2a3dc95fa2b4a1e6a1960d5cc834850034 Mon Sep 17 00:00:00 2001
From: Euler Taveira <euler@timbira.com.br>
Date: Mon, 4 Nov 2019 14:45:38 +0000
Subject: [PATCH] Show only rows that open connections in some system views

It is pointless to show auxiliary processes that do not open connections
to Postgres in pg_stat_ssl and pg_stat_gssapi. This change affects
compatibility with previous versions.
---
 src/backend/catalog/system_views.sql | 6 ++++--
 src/test/regress/expected/rules.out  | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index 9fe4a47..ce39808 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -826,7 +826,8 @@ CREATE VIEW pg_stat_ssl AS
             S.ssl_client_dn AS client_dn,
             S.ssl_client_serial AS client_serial,
             S.ssl_issuer_dn AS issuer_dn
-    FROM pg_stat_get_activity(NULL) AS S;
+    FROM pg_stat_get_activity(NULL) AS S
+	WHERE S.client_port IS NOT NULL;
 
 CREATE VIEW pg_stat_gssapi AS
     SELECT
@@ -834,7 +835,8 @@ CREATE VIEW pg_stat_gssapi AS
             S.gss_auth AS gss_authenticated,
             S.gss_princ AS principal,
             S.gss_enc AS encrypted
-    FROM pg_stat_get_activity(NULL) AS S;
+    FROM pg_stat_get_activity(NULL) AS S
+	WHERE S.client_port IS NOT NULL;
 
 CREATE VIEW pg_replication_slots AS
     SELECT
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index 210e9cd..14e7214 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -1845,7 +1845,8 @@ pg_stat_gssapi| SELECT s.pid,
     s.gss_auth AS gss_authenticated,
     s.gss_princ AS principal,
     s.gss_enc AS encrypted
-   FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, sslcompression, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc);
+   FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, sslcompression, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc)
+  WHERE (s.client_port IS NOT NULL);
 pg_stat_progress_cluster| SELECT s.pid,
     s.datid,
     d.datname,
@@ -1964,7 +1965,8 @@ pg_stat_ssl| SELECT s.pid,
     s.ssl_client_dn AS client_dn,
     s.ssl_client_serial AS client_serial,
     s.ssl_issuer_dn AS issuer_dn
-   FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, sslcompression, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc);
+   FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, wait_event_type, wait_event, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port, backend_xid, backend_xmin, backend_type, ssl, sslversion, sslcipher, sslbits, sslcompression, ssl_client_dn, ssl_client_serial, ssl_issuer_dn, gss_auth, gss_princ, gss_enc)
+  WHERE (s.client_port IS NOT NULL);
 pg_stat_subscription| SELECT su.oid AS subid,
     su.subname,
     st.pid,
-- 
2.7.4

#5Stephen Frost
sfrost@snowman.net
In reply to: Robert Haas (#3)
Re: auxiliary processes in pg_stat_ssl

Greetings,

* Robert Haas (robertmhaas@gmail.com) wrote:

On Mon, Nov 4, 2019 at 8:26 AM Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

On 2019-Sep-04, Alvaro Herrera wrote:

I just noticed that we list auxiliary processes in pg_stat_ssl:

[...]

But this seems pointless. Should we not hide those? Seems this only
happened as an unintended side-effect of fc70a4b0df38. It appears to me
that we should redefine that view to restrict backend_type that's
'client backend' (maybe include 'wal receiver'/'wal sender' also, not
sure.)

[crickets]

Robert, Kuntal, any opinion on this?

I think if I were doing something about it, I'd probably try to filter
on a field that directly represents whether there is a connection,
rather than checking the backend type. That way, if the list of
backend types that have client connections changes later, there's
nothing to update. Like "WHERE client_port IS NOT NULL," or something
of that sort.

Yeah, using a "this has a connection" would be better and, as also noted
on this thread, pg_stat_gssapi should get similar treatment.

Based on what we claim in our docs, it does look like 'client_port IS
NOT NULL' should work. I do think we might want to update the docs to
make it a bit more explicit, what we say now is:

TCP port number that the client is using for communication with this
backend, or -1 if a Unix socket is used

We don't explain there that NULL means the backend doesn't have an
external connection even though plenty of those entries show up in every
instance of PG. Perhaps we should add this:

If this field is null, it indicates that this is an internal process
such as autovacuum.

Which is what we say for 'client_addr'.

I have to admit that while it's handy that we just shove '-1' into
client_port when it's a unix socket, it's kind of ugly from a data
perspective- in a green field it'd probably be better to have a
"connection type" field that then indicates which other fields are valid
instead of having a special constant, but that ship sailed long ago and
it's not like we have a lot of people complaining about it, so I suppose
just using it here as suggested is fine.

Thanks,

Stephen

#6Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Euler Taveira (#4)
Re: auxiliary processes in pg_stat_ssl

On Mon, Nov 4, 2019 at 9:09 PM Euler Taveira <euler@timbira.com.br> wrote:

But this seems pointless. Should we not hide those? Seems this only
happened as an unintended side-effect of fc70a4b0df38. It appears to me
that we should redefine that view to restrict backend_type that's
'client backend' (maybe include 'wal receiver'/'wal sender' also, not
sure.)

Yep, it is pointless. BackendType that open connections to server are:
autovacuum worker, client backend, background worker, wal sender. I
also notice that pg_stat_gssapi is in the same boat as pg_stat_ssl and
we should constraint the rows to backend types that open connections.
I'm attaching a patch to list only connections in those system views.

Yeah, We should hide those. As Robert mentioned, I think checking
whether 'client_port IS NOT NULL' is a better approach than checking
the backend_type. The patch looks good to me.

--
Thanks & Regards,
Kuntal Ghosh
EnterpriseDB: http://www.enterprisedb.com

#7Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira (#4)
Re: auxiliary processes in pg_stat_ssl

On 2019-Nov-04, Euler Taveira wrote:

Yep, it is pointless. BackendType that open connections to server are:
autovacuum worker, client backend, background worker, wal sender. I
also notice that pg_stat_gssapi is in the same boat as pg_stat_ssl and
we should constraint the rows to backend types that open connections.
I'm attaching a patch to list only connections in those system views.

Thanks! I pushed this.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#8Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Stephen Frost (#5)
Re: auxiliary processes in pg_stat_ssl

On 2019-Nov-04, Stephen Frost wrote:

Based on what we claim in our docs, it does look like 'client_port IS
NOT NULL' should work. I do think we might want to update the docs to
make it a bit more explicit, what we say now is:

TCP port number that the client is using for communication with this
backend, or -1 if a Unix socket is used

We don't explain there that NULL means the backend doesn't have an
external connection even though plenty of those entries show up in every
instance of PG. Perhaps we should add this:

If this field is null, it indicates that this is an internal process
such as autovacuum.

Which is what we say for 'client_addr'.

Seems sensible. Done. Thanks

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services