Why does logical replication launcher set application_name?

Started by Tom Lanealmost 9 years ago41 messages
#1Tom Lane
tgl@sss.pgh.pa.us

I notice looking at pg_stat_activity that the logical replication launcher
sets its application_name to "logical replication launcher". This seems
inconsistent (no other standard background process sets application_name),
redundant with other columns that already tell you what it is, and an
unreasonable consumption of horizontal space in the tabular output.
Can we drop that? If we do have to have something like that, what about
putting it in the "query" field where it's much less likely to be
substantially wider than any other entry in the column?

regards, tom lane

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

#2Michael Paquier
michael.paquier@gmail.com
In reply to: Tom Lane (#1)
Re: Why does logical replication launcher set application_name?

On Wed, Apr 12, 2017 at 3:40 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I notice looking at pg_stat_activity that the logical replication launcher
sets its application_name to "logical replication launcher". This seems
inconsistent (no other standard background process sets application_name),
redundant with other columns that already tell you what it is, and an
unreasonable consumption of horizontal space in the tabular output.
Can we drop that? If we do have to have something like that, what about
putting it in the "query" field where it's much less likely to be
substantially wider than any other entry in the column?

It seems to me that the logic behind that is to be able to identify
easily the logical replication launcher in pg_stat_activity, so using
the query field instead sounds fine for me as we need another way than
backend_type to guess what is this bgworker.
--
Michael

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

#3Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#2)
Re: Why does logical replication launcher set application_name?

On Tue, Apr 11, 2017 at 8:11 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Wed, Apr 12, 2017 at 3:40 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I notice looking at pg_stat_activity that the logical replication launcher
sets its application_name to "logical replication launcher". This seems
inconsistent (no other standard background process sets application_name),
redundant with other columns that already tell you what it is, and an
unreasonable consumption of horizontal space in the tabular output.
Can we drop that? If we do have to have something like that, what about
putting it in the "query" field where it's much less likely to be
substantially wider than any other entry in the column?

It seems to me that the logic behind that is to be able to identify
easily the logical replication launcher in pg_stat_activity, so using
the query field instead sounds fine for me as we need another way than
backend_type to guess what is this bgworker.

Wait, why do we need two ways?

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

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

#4Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Robert Haas (#3)
Re: Why does logical replication launcher set application_name?

On Wed, Apr 12, 2017 at 6:02 AM, Robert Haas <robertmhaas@gmail.com> wrote:

On Tue, Apr 11, 2017 at 8:11 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Wed, Apr 12, 2017 at 3:40 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I notice looking at pg_stat_activity that the logical replication launcher
sets its application_name to "logical replication launcher". This seems
inconsistent (no other standard background process sets application_name),
redundant with other columns that already tell you what it is, and an
unreasonable consumption of horizontal space in the tabular output.
Can we drop that? If we do have to have something like that, what about
putting it in the "query" field where it's much less likely to be
substantially wider than any other entry in the column?

It seems to me that the logic behind that is to be able to identify
easily the logical replication launcher in pg_stat_activity, so using
the query field instead sounds fine for me as we need another way than
backend_type to guess what is this bgworker.

Wait, why do we need two ways?

For backend_type=background worker, application_name shows the name of
the background worker (BackgroundWorker->bgw_name). I think we need
some way to distinguish among different background workers. But,
application_name may not be the correct field to show the information.

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

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

#5Craig Ringer
craig@2ndquadrant.com
In reply to: Kuntal Ghosh (#4)
Re: Why does logical replication launcher set application_name?

On 12 April 2017 at 13:34, Kuntal Ghosh <kuntalghosh.2007@gmail.com> wrote:

For backend_type=background worker, application_name shows the name of
the background worker (BackgroundWorker->bgw_name). I think we need
some way to distinguish among different background workers. But,
application_name may not be the correct field to show the information.

It's better than (ab)using 'query' IMO.

I'd rather an abbreviated entry to address Tom's concerns about
format. 'lrlaunch' or whatever.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#6Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Robert Haas (#3)
Re: Why does logical replication launcher set application_name?

On 12/04/17 02:32, Robert Haas wrote:

On Tue, Apr 11, 2017 at 8:11 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Wed, Apr 12, 2017 at 3:40 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

I notice looking at pg_stat_activity that the logical replication launcher
sets its application_name to "logical replication launcher". This seems
inconsistent (no other standard background process sets application_name),
redundant with other columns that already tell you what it is, and an
unreasonable consumption of horizontal space in the tabular output.
Can we drop that? If we do have to have something like that, what about
putting it in the "query" field where it's much less likely to be
substantially wider than any other entry in the column?

It seems to me that the logic behind that is to be able to identify
easily the logical replication launcher in pg_stat_activity, so using
the query field instead sounds fine for me as we need another way than
backend_type to guess what is this bgworker.

Wait, why do we need two ways?

What do you mean by two ways? There is no way if we don't set anything.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Craig Ringer (#5)
Re: Why does logical replication launcher set application_name?

Craig Ringer <craig@2ndquadrant.com> writes:

On 12 April 2017 at 13:34, Kuntal Ghosh <kuntalghosh.2007@gmail.com> wrote:

For backend_type=background worker, application_name shows the name of
the background worker (BackgroundWorker->bgw_name). I think we need
some way to distinguish among different background workers. But,
application_name may not be the correct field to show the information.

It's better than (ab)using 'query' IMO.

I'd rather an abbreviated entry to address Tom's concerns about
format. 'lrlaunch' or whatever.

Basically the problem I've got with the LR launcher is that it looks
utterly unlike any other background process in pg_stat_activity.
Leaving out all-null columns to make my point:

regression=# select pid,usesysid,usename,application_name,backend_start,wait_event_type,wait_event,backend_type from pg_stat_activity where application_name != 'psql';
pid | usesysid | usename | application_name | backend_start | wait_event_type | wait_event | backend_type
-------+----------+----------+------------------------------+-------------------------------+-----------------+---------------------+---------------------
25416 | | | | 2017-04-16 12:32:46.987076-04 | Activity | AutoVacuumMain | autovacuum launcher
25418 | 10 | postgres | logical replication launcher | 2017-04-16 12:32:46.988859-04 | Activity | LogicalLauncherMain | background worker
25414 | | | | 2017-04-16 12:32:46.986745-04 | Activity | BgWriterHibernate | background writer
25413 | | | | 2017-04-16 12:32:46.986885-04 | Activity | CheckpointerMain | checkpointer
25415 | | | | 2017-04-16 12:32:46.9871-04 | Activity | WalWriterMain | walwriter
(5 rows)

Why has it got non-null entries for usesysid and usename, never mind
application_name? Why does it not follow the well-established convention
that backend_type is what identifies background processes?

I'm sure the answer to those questions is "it's an implementation artifact
from using the generic bgworker infrastructure", but that does not make it
look any less like sloppy, half-finished work.

If it is a limitation of the bgworker infrastructure that we can't make
the LR processes look more like the other kinds of built-in processes,
then I think we need to fix that limitation. And I further assert that
we need to do it for v10, because once we ship v10 people will adjust
their tools for this bogus output, and we'll face complaints about
backwards compatibility if we fix it later.

regards, tom lane

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

#8Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Tom Lane (#7)
Re: Why does logical replication launcher set application_name?

On 16/04/17 18:47, Tom Lane wrote:

Craig Ringer <craig@2ndquadrant.com> writes:

On 12 April 2017 at 13:34, Kuntal Ghosh <kuntalghosh.2007@gmail.com> wrote:

For backend_type=background worker, application_name shows the name of
the background worker (BackgroundWorker->bgw_name). I think we need
some way to distinguish among different background workers. But,
application_name may not be the correct field to show the information.

It's better than (ab)using 'query' IMO.

I'd rather an abbreviated entry to address Tom's concerns about
format. 'lrlaunch' or whatever.

Basically the problem I've got with the LR launcher is that it looks
utterly unlike any other background process in pg_stat_activity.
Leaving out all-null columns to make my point:

regression=# select pid,usesysid,usename,application_name,backend_start,wait_event_type,wait_event,backend_type from pg_stat_activity where application_name != 'psql';
pid | usesysid | usename | application_name | backend_start | wait_event_type | wait_event | backend_type
-------+----------+----------+------------------------------+-------------------------------+-----------------+---------------------+---------------------
25416 | | | | 2017-04-16 12:32:46.987076-04 | Activity | AutoVacuumMain | autovacuum launcher
25418 | 10 | postgres | logical replication launcher | 2017-04-16 12:32:46.988859-04 | Activity | LogicalLauncherMain | background worker
25414 | | | | 2017-04-16 12:32:46.986745-04 | Activity | BgWriterHibernate | background writer
25413 | | | | 2017-04-16 12:32:46.986885-04 | Activity | CheckpointerMain | checkpointer
25415 | | | | 2017-04-16 12:32:46.9871-04 | Activity | WalWriterMain | walwriter
(5 rows)

Why has it got non-null entries for usesysid and usename, never mind
application_name? Why does it not follow the well-established convention
that backend_type is what identifies background processes?

I'm sure the answer to those questions is "it's an implementation artifact
from using the generic bgworker infrastructure", but that does not make it
look any less like sloppy, half-finished work.

If it is a limitation of the bgworker infrastructure that we can't make
the LR processes look more like the other kinds of built-in processes,
then I think we need to fix that limitation. And I further assert that
we need to do it for v10, because once we ship v10 people will adjust
their tools for this bogus output, and we'll face complaints about
backwards compatibility if we fix it later.

It's indeed how bgworker infrastructure is reporting it. That being
said, since LR processes are in-core, we can add exception for them in
pgstat_bestart() so that they are reported more like other builtin
processes. We could also try to add api for bgworker processes to change
how they are reported so that any future workers (and all the external
workers) can be reported properly as well, but that seems better fit for
v11 at this point since it would be good if we had some discussion for
how that should look like.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#9Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Petr Jelinek (#8)
Re: Why does logical replication launcher set application_name?

On 16/04/17 22:27, Petr Jelinek wrote:

On 16/04/17 18:47, Tom Lane wrote:

Craig Ringer <craig@2ndquadrant.com> writes:

On 12 April 2017 at 13:34, Kuntal Ghosh <kuntalghosh.2007@gmail.com> wrote:

For backend_type=background worker, application_name shows the name of
the background worker (BackgroundWorker->bgw_name). I think we need
some way to distinguish among different background workers. But,
application_name may not be the correct field to show the information.

It's better than (ab)using 'query' IMO.

I'd rather an abbreviated entry to address Tom's concerns about
format. 'lrlaunch' or whatever.

Basically the problem I've got with the LR launcher is that it looks
utterly unlike any other background process in pg_stat_activity.
Leaving out all-null columns to make my point:

regression=# select pid,usesysid,usename,application_name,backend_start,wait_event_type,wait_event,backend_type from pg_stat_activity where application_name != 'psql';
pid | usesysid | usename | application_name | backend_start | wait_event_type | wait_event | backend_type
-------+----------+----------+------------------------------+-------------------------------+-----------------+---------------------+---------------------
25416 | | | | 2017-04-16 12:32:46.987076-04 | Activity | AutoVacuumMain | autovacuum launcher
25418 | 10 | postgres | logical replication launcher | 2017-04-16 12:32:46.988859-04 | Activity | LogicalLauncherMain | background worker
25414 | | | | 2017-04-16 12:32:46.986745-04 | Activity | BgWriterHibernate | background writer
25413 | | | | 2017-04-16 12:32:46.986885-04 | Activity | CheckpointerMain | checkpointer
25415 | | | | 2017-04-16 12:32:46.9871-04 | Activity | WalWriterMain | walwriter
(5 rows)

Why has it got non-null entries for usesysid and usename, never mind
application_name? Why does it not follow the well-established convention
that backend_type is what identifies background processes?

I'm sure the answer to those questions is "it's an implementation artifact
from using the generic bgworker infrastructure", but that does not make it
look any less like sloppy, half-finished work.

If it is a limitation of the bgworker infrastructure that we can't make
the LR processes look more like the other kinds of built-in processes,
then I think we need to fix that limitation. And I further assert that
we need to do it for v10, because once we ship v10 people will adjust
their tools for this bogus output, and we'll face complaints about
backwards compatibility if we fix it later.

It's indeed how bgworker infrastructure is reporting it. That being
said, since LR processes are in-core, we can add exception for them in
pgstat_bestart() so that they are reported more like other builtin
processes. We could also try to add api for bgworker processes to change
how they are reported so that any future workers (and all the external
workers) can be reported properly as well, but that seems better fit for
v11 at this point since it would be good if we had some discussion for
how that should look like.

Hmm so I took a look at code today with intention to implement this, but
it does not seem as straightforward as I'd hoped due to pgstat_bestart()
being called quite early in startup.

We can definitely easily detect that the bgworker is internal one by
library_name equals 'postgres' so we can easily remove the usesysid and
usename based on that. But that does not solve the issue of identifying
the processes in pg_stat_activity as logical replication laucher/worker.
I wonder if it would be okay to set backend_type to bgw_name for
internal workers and just leave the external ones as it is (or solve
them in v11 with some proper API) as we can control the length of name
there (it will still be longer than the values for other things but
maybe not too much).

Does that sound reasonable enough for v10?

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#10Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Petr Jelinek (#9)
Re: Why does logical replication launcher set application_name?

On 4/18/17 12:13, Petr Jelinek wrote:

We can definitely easily detect that the bgworker is internal one by
library_name equals 'postgres' so we can easily remove the usesysid and
usename based on that.

I don't see why we need to do that. It is showing the correct
information, isn't it?

But that does not solve the issue of identifying
the processes in pg_stat_activity as logical replication laucher/worker.
I wonder if it would be okay to set backend_type to bgw_name for
internal workers and just leave the external ones as it is (or solve
them in v11 with some proper API) as we can control the length of name
there (it will still be longer than the values for other things but
maybe not too much).

I think showing bgw_name as backend_type always sounds reasonable. No
need to treat external implementations differently.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#11Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#10)
Re: Why does logical replication launcher set application_name?

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

I think showing bgw_name as backend_type always sounds reasonable. No
need to treat external implementations differently.

That's definitely an approach we could use. It would encourage people
to use short bgw_names, which is a constraint that wasn't especially
apparent before, but I don't think that's a bad thing.

regards, tom lane

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

#12Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Peter Eisentraut (#10)
Re: Why does logical replication launcher set application_name?

On 18/04/17 18:24, Peter Eisentraut wrote:

On 4/18/17 12:13, Petr Jelinek wrote:

We can definitely easily detect that the bgworker is internal one by
library_name equals 'postgres' so we can easily remove the usesysid and
usename based on that.

I don't see why we need to do that. It is showing the correct
information, isn't it?

It does, but it's also one of the things Tom complained about and I
think he is right in that at least values for launcher should be
filtered out there as there is not much meaning in what is shown for
launcher. The ugly part is that we can't tell it's launcher in any other
way than comparing bgw_library_name and bgw_function_name to specific
values.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#13Tom Lane
tgl@sss.pgh.pa.us
In reply to: Petr Jelinek (#12)
Re: Why does logical replication launcher set application_name?

Petr Jelinek <petr.jelinek@2ndquadrant.com> writes:

On 18/04/17 18:24, Peter Eisentraut wrote:

I don't see why we need to do that. It is showing the correct
information, isn't it?

It does, but it's also one of the things Tom complained about and I
think he is right in that at least values for launcher should be
filtered out there as there is not much meaning in what is shown for
launcher. The ugly part is that we can't tell it's launcher in any other
way than comparing bgw_library_name and bgw_function_name to specific
values.

I think you're thinking about it wrong. To my mind the issue is that
there should be some generic way to determine that a bgworker process
is or is not laboring on behalf of an identifiable user. It's great
that we can tell which user it is when there is one, but clearly some
bgworkers will be providing general services that aren't associated with
a single user. So it should be possible to set the userID to zero or
some such when the bgworker is one that isn't associated with a
particular user. Maybe the owning user needs to become an additional
parameter passed in struct BackgroundWorker.

regards, tom lane

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

#14Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Tom Lane (#13)
Re: Why does logical replication launcher set application_name?

On 18/04/17 19:18, Tom Lane wrote:

Petr Jelinek <petr.jelinek@2ndquadrant.com> writes:

On 18/04/17 18:24, Peter Eisentraut wrote:

I don't see why we need to do that. It is showing the correct
information, isn't it?

It does, but it's also one of the things Tom complained about and I
think he is right in that at least values for launcher should be
filtered out there as there is not much meaning in what is shown for
launcher. The ugly part is that we can't tell it's launcher in any other
way than comparing bgw_library_name and bgw_function_name to specific
values.

I think you're thinking about it wrong. To my mind the issue is that
there should be some generic way to determine that a bgworker process
is or is not laboring on behalf of an identifiable user. It's great
that we can tell which user it is when there is one, but clearly some
bgworkers will be providing general services that aren't associated with
a single user. So it should be possible to set the userID to zero or
some such when the bgworker is one that isn't associated with a
particular user. Maybe the owning user needs to become an additional
parameter passed in struct BackgroundWorker.

We can already do that. In fact after I wrote the above I thought we
could add some kind of boolean in the style of am_bootstrap_superuser as
BOOTSTRAP_SUPERUSER is what those bgworkers get assigned. I don't like
the name much though (am_bootstrap_superuser) as this should not be
associated with bootstrap IMHO.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#15Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#11)
Re: Why does logical replication launcher set application_name?

On 4/18/17 12:37, Tom Lane wrote:

Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:

I think showing bgw_name as backend_type always sounds reasonable. No
need to treat external implementations differently.

That's definitely an approach we could use. It would encourage people
to use short bgw_names, which is a constraint that wasn't especially
apparent before, but I don't think that's a bad thing.

Actually, bgw_name is probably not food for
pg_stat_activity.backend_type, since it's often not the same for all
background workers of the same kind. For example, it might be "parallel
worker for PID %d". Ideally, a background worker would have a bgw_type
field and perhaps a bgw_name_extra field. However, a background worker
might also want to update some part of that dynamically, to change the
process title. Many details depend on the particular background workers.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#16Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#13)
Re: Why does logical replication launcher set application_name?

On 4/18/17 13:18, Tom Lane wrote:

I think you're thinking about it wrong. To my mind the issue is that
there should be some generic way to determine that a bgworker process
is or is not laboring on behalf of an identifiable user. It's great
that we can tell which user it is when there is one, but clearly some
bgworkers will be providing general services that aren't associated with
a single user. So it should be possible to set the userID to zero or
some such when the bgworker is one that isn't associated with a
particular user. Maybe the owning user needs to become an additional
parameter passed in struct BackgroundWorker.

I think this is probably a problem particular to the logical replication
launcher. Other background workers either do work as a particular user,
as you say, or don't touch the database at all. So a localized hack or
a simple hide-the-user flag might suffice for now.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#17Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Peter Eisentraut (#16)
Re: Why does logical replication launcher set application_name?

On 20/04/17 21:33, Peter Eisentraut wrote:

On 4/18/17 13:18, Tom Lane wrote:

I think you're thinking about it wrong. To my mind the issue is that
there should be some generic way to determine that a bgworker process
is or is not laboring on behalf of an identifiable user. It's great
that we can tell which user it is when there is one, but clearly some
bgworkers will be providing general services that aren't associated with
a single user. So it should be possible to set the userID to zero or
some such when the bgworker is one that isn't associated with a
particular user. Maybe the owning user needs to become an additional
parameter passed in struct BackgroundWorker.

I think this is probably a problem particular to the logical replication
launcher. Other background workers either do work as a particular user,
as you say, or don't touch the database at all. So a localized hack or
a simple hide-the-user flag might suffice for now.

But that still leaves the application_name issue. My proposal in general
would be to add boolean that indicates that the worker is not using
specific user (this can be easily set in
InitializeSessionUserIdStandalone()) and will work for multiple things.

About application_name, perhaps we should just add bgw_type or bgw_group
and show it as worker_type in activity and that's it?

I think this should be open item btw so I'll add it.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#18Noah Misch
noah@leadboat.com
In reply to: Petr Jelinek (#17)
Re: Why does logical replication launcher set application_name?

On Tue, May 23, 2017 at 07:50:34PM +0200, Petr Jelinek wrote:

On 20/04/17 21:33, Peter Eisentraut wrote:

On 4/18/17 13:18, Tom Lane wrote:

I think you're thinking about it wrong. To my mind the issue is that
there should be some generic way to determine that a bgworker process
is or is not laboring on behalf of an identifiable user. It's great
that we can tell which user it is when there is one, but clearly some
bgworkers will be providing general services that aren't associated with
a single user. So it should be possible to set the userID to zero or
some such when the bgworker is one that isn't associated with a
particular user. Maybe the owning user needs to become an additional
parameter passed in struct BackgroundWorker.

I think this is probably a problem particular to the logical replication
launcher. Other background workers either do work as a particular user,
as you say, or don't touch the database at all. So a localized hack or
a simple hide-the-user flag might suffice for now.

But that still leaves the application_name issue. My proposal in general
would be to add boolean that indicates that the worker is not using
specific user (this can be easily set in
InitializeSessionUserIdStandalone()) and will work for multiple things.

About application_name, perhaps we should just add bgw_type or bgw_group
and show it as worker_type in activity and that's it?

I think this should be open item btw so I'll add it.

[Action required within three days. This is a generic notification.]

The above-described topic is currently a PostgreSQL 10 open item. Peter,
since you committed the patch believed to have created it, you own this open
item. If some other commit is more relevant or if this does not belong as a
v10 open item, please let us know. Otherwise, please observe the policy on
open item ownership[1]/messages/by-id/20170404140717.GA2675809@tornado.leadboat.com and send a status update within three calendar days of
this message. Include a date for your subsequent status update. Testers may
discover new open items at any time, and I want to plan to get them all fixed
well in advance of shipping v10. Consequently, I will appreciate your efforts
toward speedy resolution. Thanks.

[1]: /messages/by-id/20170404140717.GA2675809@tornado.leadboat.com

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

#19Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Noah Misch (#18)
1 attachment(s)
Re: Why does logical replication launcher set application_name?

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

This code appears to be buggy because I sometimes get NULL results of
the backend_type lookup, implying that it couldn't find the background
worker slot. This needs another look.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

0001-Split-background-worker-name-into-type-and-name.patchtext/plain; charset=UTF-8; name=0001-Split-background-worker-name-into-type-and-name.patch; x-mac-creator=0; x-mac-type=0Download
From 45444b3362e8d00e998fae195023b8a55d96a005 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Tue, 30 May 2017 22:59:19 -0400
Subject: [PATCH] Split background worker name into type and name

Remove background worker structure field bgw_name and add two new fields
bgw_type and bgw_name_extra.  The bgw_type field is intended to be set
to the same value for all workers of the same type, so they can be
grouped in pg_stat_activity, for example.  The bgw_name_extra field can
be any suffix that is specific to the individual worker.  So bgw_type +
bgw_name_extra is the old bgw_name.

The backend_type column in pg_stat_activity now shows bgw_type for a
background worker.  The ps listing and some log messages no longer call
out that a process is a "background worker" but just show the bgw_type.
That way, being a background worker is effectively an implementation
detail now that is not shown to the user.

Don't set application_name in logical replication launcher or worker
anymore.  Those processes can now be identified using the mechanisms
described above instead.
---
 doc/src/sgml/bgworker.sgml                 | 17 +++++++++---
 src/backend/access/transam/parallel.c      |  3 ++-
 src/backend/postmaster/bgworker.c          | 42 ++++++++++++++++--------------
 src/backend/postmaster/postmaster.c        | 16 +++++-------
 src/backend/replication/logical/launcher.c | 15 +++++------
 src/backend/replication/logical/worker.c   |  4 ---
 src/backend/utils/adt/pgstatfuncs.c        | 29 +++++++++++++++++++--
 src/include/postmaster/bgworker.h          |  3 ++-
 src/test/modules/test_shm_mq/setup.c       |  2 +-
 src/test/modules/worker_spi/worker_spi.c   | 17 +++++++-----
 10 files changed, 92 insertions(+), 56 deletions(-)

diff --git a/doc/src/sgml/bgworker.sgml b/doc/src/sgml/bgworker.sgml
index b422323081..0a89a5044b 100644
--- a/doc/src/sgml/bgworker.sgml
+++ b/doc/src/sgml/bgworker.sgml
@@ -50,7 +50,8 @@ <title>Background Worker Processes</title>
 typedef void (*bgworker_main_type)(Datum main_arg);
 typedef struct BackgroundWorker
 {
-    char        bgw_name[BGW_MAXLEN];
+    char        bgw_type[BGW_MAXLEN];
+    char        bgw_name_extra[BGW_MAXLEN];
     int         bgw_flags;
     BgWorkerStartTime bgw_start_time;
     int         bgw_restart_time;       /* in seconds, or BGW_NEVER_RESTART */
@@ -64,8 +65,18 @@ <title>Background Worker Processes</title>
   </para>
 
   <para>
-   <structfield>bgw_name</> is a string to be used in log messages, process
-   listings and similar contexts.
+   <structfield>bgw_type</> is a string to be used in log messages, process
+   listings and similar contexts.  It should be the same for all background
+   workers of the same type, so that it is possible to group such workers in a
+   process listing, for example.
+  </para>
+
+  <para>
+   <structfield>bgw_name_extra</> is a string that is appended
+   to <structfield>bgw_type</structfield> in some contexts such as process
+   listings.  Unlike <structfield>bgw_type</structfield>, it can contain
+   information that is particular to this process.  The string, if not empty,
+   should normally start with a space or other separator.
   </para>
 
   <para>
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 2dad3e8a65..fbdcf2da31 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -436,7 +436,8 @@ LaunchParallelWorkers(ParallelContext *pcxt)
 
 	/* Configure a worker. */
 	memset(&worker, 0, sizeof(worker));
-	snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
+	snprintf(worker.bgw_type, BGW_MAXLEN, "parallel worker");
+	snprintf(worker.bgw_name_extra, BGW_MAXLEN, " for PID %d",
 			 MyProcPid);
 	worker.bgw_flags =
 		BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index c3454276bf..65318a5fb8 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -342,8 +342,10 @@ BackgroundWorkerStateChange(void)
 		 * Copy strings in a paranoid way.  If shared memory is corrupted, the
 		 * source data might not even be NUL-terminated.
 		 */
-		ascii_safe_strlcpy(rw->rw_worker.bgw_name,
-						   slot->worker.bgw_name, BGW_MAXLEN);
+		ascii_safe_strlcpy(rw->rw_worker.bgw_type,
+						   slot->worker.bgw_type, BGW_MAXLEN);
+		ascii_safe_strlcpy(rw->rw_worker.bgw_name_extra,
+						   slot->worker.bgw_name_extra, BGW_MAXLEN);
 		ascii_safe_strlcpy(rw->rw_worker.bgw_library_name,
 						   slot->worker.bgw_library_name, BGW_MAXLEN);
 		ascii_safe_strlcpy(rw->rw_worker.bgw_function_name,
@@ -389,9 +391,10 @@ BackgroundWorkerStateChange(void)
 		rw->rw_terminate = false;
 
 		/* Log it! */
-		ereport(DEBUG1,
-				(errmsg("registering background worker \"%s\"",
-						rw->rw_worker.bgw_name)));
+		elog(DEBUG1,
+			 "registering background worker \"%s%s\"",
+			 rw->rw_worker.bgw_type,
+			 rw->rw_worker.bgw_name_extra);
 
 		slist_push_head(&BackgroundWorkerList, &rw->rw_lnode);
 	}
@@ -421,9 +424,10 @@ ForgetBackgroundWorker(slist_mutable_iter *cur)
 
 	slot->in_use = false;
 
-	ereport(DEBUG1,
-			(errmsg("unregistering background worker \"%s\"",
-					rw->rw_worker.bgw_name)));
+	elog(DEBUG1,
+		 "unregistering background worker \"%s%s\"",
+		 rw->rw_worker.bgw_type,
+		 rw->rw_worker.bgw_name_extra);
 
 	slist_delete_current(cur);
 	free(rw);
@@ -588,7 +592,7 @@ SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
 			ereport(elevel,
 					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 					 errmsg("background worker \"%s\": must attach to shared memory in order to request a database connection",
-							worker->bgw_name)));
+							worker->bgw_type)));
 			return false;
 		}
 
@@ -597,7 +601,7 @@ SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
 			ereport(elevel,
 					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 					 errmsg("background worker \"%s\": cannot request database access if starting at postmaster start",
-							worker->bgw_name)));
+							worker->bgw_type)));
 			return false;
 		}
 
@@ -611,7 +615,7 @@ SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
 		ereport(elevel,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("background worker \"%s\": invalid restart interval",
-						worker->bgw_name)));
+						worker->bgw_type)));
 		return false;
 	}
 
@@ -626,7 +630,7 @@ SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
 		ereport(elevel,
 				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("background worker \"%s\": parallel workers may not be configured for restart",
-						worker->bgw_name)));
+						worker->bgw_type)));
 		return false;
 	}
 
@@ -670,8 +674,8 @@ bgworker_die(SIGNAL_ARGS)
 
 	ereport(FATAL,
 			(errcode(ERRCODE_ADMIN_SHUTDOWN),
-			 errmsg("terminating background worker \"%s\" due to administrator command",
-					MyBgworkerEntry->bgw_name)));
+			 errmsg("terminating %s due to administrator command",
+					MyBgworkerEntry->bgw_type)));
 }
 
 /*
@@ -710,7 +714,7 @@ StartBackgroundWorker(void)
 	IsBackgroundWorker = true;
 
 	/* Identify myself via ps */
-	snprintf(buf, MAXPGPATH, "bgworker: %s", worker->bgw_name);
+	snprintf(buf, MAXPGPATH, "%s%s", worker->bgw_type, worker->bgw_name_extra);
 	init_ps_display(buf, "", "", "");
 
 	/*
@@ -852,8 +856,8 @@ RegisterBackgroundWorker(BackgroundWorker *worker)
 	static int	numworkers = 0;
 
 	if (!IsUnderPostmaster)
-		ereport(DEBUG1,
-		 (errmsg("registering background worker \"%s\"", worker->bgw_name)));
+		elog(DEBUG1,
+			 "registering background worker \"%s%s\"", worker->bgw_type, worker->bgw_name_extra);
 
 	if (!process_shared_preload_libraries_in_progress &&
 		strcmp(worker->bgw_library_name, "postgres") != 0)
@@ -862,7 +866,7 @@ RegisterBackgroundWorker(BackgroundWorker *worker)
 			ereport(LOG,
 					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 					 errmsg("background worker \"%s\": must be registered in shared_preload_libraries",
-							worker->bgw_name)));
+							worker->bgw_type)));
 		return;
 	}
 
@@ -874,7 +878,7 @@ RegisterBackgroundWorker(BackgroundWorker *worker)
 		ereport(LOG,
 				(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 				 errmsg("background worker \"%s\": only dynamic background workers can request notification",
-						worker->bgw_name)));
+						worker->bgw_type)));
 		return;
 	}
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 35b4ec88d3..991caeace7 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -3070,7 +3070,6 @@ static bool
 CleanupBackgroundWorker(int pid,
 						int exitstatus) /* child's exit status */
 {
-	char		namebuf[MAXPGPATH];
 	slist_mutable_iter iter;
 
 	slist_foreach_modify(iter, &BackgroundWorkerList)
@@ -3088,9 +3087,6 @@ CleanupBackgroundWorker(int pid,
 			exitstatus = 0;
 #endif
 
-		snprintf(namebuf, MAXPGPATH, "%s: %s", _("worker process"),
-				 rw->rw_worker.bgw_name);
-
 		if (!EXIT_STATUS_0(exitstatus))
 		{
 			/* Record timestamp, so we know when to restart the worker. */
@@ -3112,7 +3108,7 @@ CleanupBackgroundWorker(int pid,
 		{
 			if (!EXIT_STATUS_0(exitstatus) && !EXIT_STATUS_1(exitstatus))
 			{
-				HandleChildCrash(pid, exitstatus, namebuf);
+				HandleChildCrash(pid, exitstatus, rw->rw_worker.bgw_type);
 				return true;
 			}
 		}
@@ -3125,7 +3121,7 @@ CleanupBackgroundWorker(int pid,
 		if (!ReleasePostmasterChildSlot(rw->rw_child_slot) &&
 			(rw->rw_worker.bgw_flags & BGWORKER_SHMEM_ACCESS) != 0)
 		{
-			HandleChildCrash(pid, exitstatus, namebuf);
+			HandleChildCrash(pid, exitstatus, rw->rw_worker.bgw_type);
 			return true;
 		}
 
@@ -3150,7 +3146,7 @@ CleanupBackgroundWorker(int pid,
 		ReportBackgroundWorkerExit(&iter);		/* report child death */
 
 		LogChildExit(EXIT_STATUS_0(exitstatus) ? DEBUG1 : LOG,
-					 namebuf, pid, exitstatus);
+					 rw->rw_worker.bgw_type, pid, exitstatus);
 
 		return true;
 	}
@@ -5576,9 +5572,9 @@ do_start_bgworker(RegisteredBgWorker *rw)
 		return false;
 	}
 
-	ereport(DEBUG1,
-			(errmsg("starting background worker process \"%s\"",
-					rw->rw_worker.bgw_name)));
+	elog(DEBUG1,
+		 "starting background worker process \"%s%s\"",
+		 rw->rw_worker.bgw_type, rw->rw_worker.bgw_name_extra);
 
 #ifdef EXEC_BACKEND
 	switch ((worker_pid = bgworker_forkexec(rw->rw_shmem_slot)))
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index b956052014..624d8e9ca7 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -379,12 +379,13 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
 	bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
 	snprintf(bgw.bgw_library_name, BGW_MAXLEN, "postgres");
 	snprintf(bgw.bgw_function_name, BGW_MAXLEN, "ApplyWorkerMain");
+	snprintf(bgw.bgw_type, BGW_MAXLEN, "logical replication worker");
 	if (OidIsValid(relid))
-		snprintf(bgw.bgw_name, BGW_MAXLEN,
-				 "logical replication worker for subscription %u sync %u", subid, relid);
+		snprintf(bgw.bgw_name_extra, BGW_MAXLEN,
+				 " for subscription %u sync %u", subid, relid);
 	else
-		snprintf(bgw.bgw_name, BGW_MAXLEN,
-				 "logical replication worker for subscription %u", subid);
+		snprintf(bgw.bgw_name_extra, BGW_MAXLEN,
+				 " for subscription %u", subid);
 
 	bgw.bgw_restart_time = BGW_NEVER_RESTART;
 	bgw.bgw_notify_pid = MyProcPid;
@@ -706,7 +707,7 @@ ApplyLauncherRegister(void)
 	bgw.bgw_start_time = BgWorkerStart_RecoveryFinished;
 	snprintf(bgw.bgw_library_name, BGW_MAXLEN, "postgres");
 	snprintf(bgw.bgw_function_name, BGW_MAXLEN, "ApplyLauncherMain");
-	snprintf(bgw.bgw_name, BGW_MAXLEN,
+	snprintf(bgw.bgw_type, BGW_MAXLEN,
 			 "logical replication launcher");
 	bgw.bgw_restart_time = 5;
 	bgw.bgw_notify_pid = 0;
@@ -797,10 +798,6 @@ ApplyLauncherMain(Datum main_arg)
 	pqsignal(SIGTERM, logicalrep_worker_sigterm);
 	BackgroundWorkerUnblockSignals();
 
-	/* Make it easy to identify our processes. */
-	SetConfigOption("application_name", MyBgworkerEntry->bgw_name,
-					PGC_USERSET, PGC_S_SESSION);
-
 	LogicalRepCtx->launcher_pid = MyProcPid;
 
 	/*
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index c67720bd2f..e59b9db407 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -1467,10 +1467,6 @@ ApplyWorkerMain(Datum main_arg)
 	MyLogicalRepWorker->last_send_time = MyLogicalRepWorker->last_recv_time =
 		MyLogicalRepWorker->reply_time = GetCurrentTimestamp();
 
-	/* Make it easy to identify our processes. */
-	SetConfigOption("application_name", MyBgworkerEntry->bgw_name,
-					PGC_USERSET, PGC_S_SESSION);
-
 	/* Load the libpq-specific functions */
 	load_file("libpqwalreceiver", false);
 
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index e0cae1ba1e..9d779491b5 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -21,6 +21,7 @@
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "pgstat.h"
+#include "postmaster/bgworker_internals.h"
 #include "postmaster/postmaster.h"
 #include "storage/proc.h"
 #include "storage/procarray.h"
@@ -820,8 +821,32 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
 				}
 			}
 			/* Add backend type */
-			values[17] =
-				CStringGetTextDatum(pgstat_get_backend_desc(beentry->st_backendType));
+			if (beentry->st_backendType == B_BG_WORKER)
+			{
+				slist_iter	siter;
+				bool		found = false;
+
+				slist_foreach(siter, &BackgroundWorkerList)
+				{
+					RegisteredBgWorker *rw;
+
+					rw = slist_container(RegisteredBgWorker, rw_lnode, siter.cur);
+
+					if (rw->rw_pid == beentry->st_procpid)
+					{
+						values[17] =
+							CStringGetTextDatum(rw->rw_worker.bgw_type);
+						found = true;
+						break;
+					}
+				}
+
+				if (!found)
+					nulls[17] = true;
+			}
+			else
+				values[17] =
+					CStringGetTextDatum(pgstat_get_backend_desc(beentry->st_backendType));
 		}
 		else
 		{
diff --git a/src/include/postmaster/bgworker.h b/src/include/postmaster/bgworker.h
index 51a5978ea8..daf7a3f7fe 100644
--- a/src/include/postmaster/bgworker.h
+++ b/src/include/postmaster/bgworker.h
@@ -87,7 +87,8 @@ typedef enum
 
 typedef struct BackgroundWorker
 {
-	char		bgw_name[BGW_MAXLEN];
+	char		bgw_type[BGW_MAXLEN];
+	char		bgw_name_extra[BGW_MAXLEN];
 	int			bgw_flags;
 	BgWorkerStartTime bgw_start_time;
 	int			bgw_restart_time;		/* in seconds, or BGW_NEVER_RESTART */
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 06c49bdb40..54c8dea4ed 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -219,7 +219,7 @@ setup_background_workers(int nworkers, dsm_segment *seg)
 	worker.bgw_restart_time = BGW_NEVER_RESTART;
 	sprintf(worker.bgw_library_name, "test_shm_mq");
 	sprintf(worker.bgw_function_name, "test_shm_mq_main");
-	snprintf(worker.bgw_name, BGW_MAXLEN, "test_shm_mq");
+	snprintf(worker.bgw_type, BGW_MAXLEN, "test_shm_mq");
 	worker.bgw_main_arg = UInt32GetDatum(dsm_segment_handle(seg));
 	/* set bgw_notify_pid, so we can detect if the worker stops */
 	worker.bgw_notify_pid = MyProcPid;
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index 9abfc714a9..9c217b69c8 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -181,8 +181,10 @@ worker_spi_main(Datum main_arg)
 	/* Connect to our database */
 	BackgroundWorkerInitializeConnection("postgres", NULL);
 
-	elog(LOG, "%s initialized with %s.%s",
-		 MyBgworkerEntry->bgw_name, table->schema, table->name);
+	elog(LOG, "%s%s initialized with %s.%s",
+		 MyBgworkerEntry->bgw_type,
+		 MyBgworkerEntry->bgw_name_extra,
+		 table->schema, table->name);
 	initialize_worker_spi(table);
 
 	/*
@@ -282,8 +284,9 @@ worker_spi_main(Datum main_arg)
 											  SPI_tuptable->tupdesc,
 											  1, &isnull));
 			if (!isnull)
-				elog(LOG, "%s: count in %s.%s is now %d",
-					 MyBgworkerEntry->bgw_name,
+				elog(LOG, "%s%s: count in %s.%s is now %d",
+					 MyBgworkerEntry->bgw_type,
+					 MyBgworkerEntry->bgw_name_extra,
 					 table->schema, table->name, val);
 		}
 
@@ -357,7 +360,8 @@ _PG_init(void)
 	 */
 	for (i = 1; i <= worker_spi_total_workers; i++)
 	{
-		snprintf(worker.bgw_name, BGW_MAXLEN, "worker %d", i);
+		snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi worker");
+		snprintf(worker.bgw_name_extra, BGW_MAXLEN, " %d", i);
 		worker.bgw_main_arg = Int32GetDatum(i);
 
 		RegisterBackgroundWorker(&worker);
@@ -383,7 +387,8 @@ worker_spi_launch(PG_FUNCTION_ARGS)
 	worker.bgw_restart_time = BGW_NEVER_RESTART;
 	sprintf(worker.bgw_library_name, "worker_spi");
 	sprintf(worker.bgw_function_name, "worker_spi_main");
-	snprintf(worker.bgw_name, BGW_MAXLEN, "worker %d", i);
+	snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi worker");
+	snprintf(worker.bgw_name_extra, BGW_MAXLEN, " %d", i);
 	worker.bgw_main_arg = Int32GetDatum(i);
 	/* set bgw_notify_pid so that we can use WaitForBackgroundWorkerStartup */
 	worker.bgw_notify_pid = MyProcPid;
-- 
2.13.0

#20Masahiko Sawada
sawada.mshk@gmail.com
In reply to: Peter Eisentraut (#19)
Re: Why does logical replication launcher set application_name?

On Wed, May 31, 2017 at 12:10 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

Hmm, is there any reasons why bgw_name_extra string doesn't appear in
pg_stat_activity? I'd say current patch makes the user difficult to
distinguish between apply worker and table sync worker.

Regards,

--
Masahiko Sawada
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

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

#21Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Masahiko Sawada (#20)
Re: Why does logical replication launcher set application_name?

On 6/2/17 02:31, Masahiko Sawada wrote:

On Wed, May 31, 2017 at 12:10 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

Hmm, is there any reasons why bgw_name_extra string doesn't appear in
pg_stat_activity?

That's the whole point: We want to be able to group similar process
types. The _extra part is particular to a single process, so it might
contain a specific OID or PID it is working on. The bgw_type is common
for all workers of that kind.

I'd say current patch makes the user difficult to
distinguish between apply worker and table sync worker.

We could arguably make apply workers and sync workers have different
bgw_type values. But if you are interested in that level of detail, you
should perhaps look at pg_stat_subscription. pg_stat_activity only
contains the "common" data, and the process-specific data is in other views.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#22Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#19)
Re: Why does logical replication launcher set application_name?

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

This code appears to be buggy because I sometimes get NULL results of
the backend_type lookup, implying that it couldn't find the background
worker slot. This needs another look.

I would like some more input on this proposal, especially from those
have have engineered the extended pg_stat_activity content.

If we don't come to a quick conclusion on this, I'd be content to leave
PG10 as is and put this patch into the next commit fest.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#23Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Peter Eisentraut (#21)
Re: Why does logical replication launcher set application_name?

On 02/06/17 21:05, Peter Eisentraut wrote:

On 6/2/17 02:31, Masahiko Sawada wrote:

I'd say current patch makes the user difficult to
distinguish between apply worker and table sync worker.

We could arguably make apply workers and sync workers have different
bgw_type values. But if you are interested in that level of detail, you
should perhaps look at pg_stat_subscription. pg_stat_activity only
contains the "common" data, and the process-specific data is in other views.

Agreed with this.

However, I am not sure about the bgw_name_extra. I think I would have
preferred keeping full bgw_name field which would be used where full
name is needed and bgw_type where only the worker type is used. The
concatenation just doesn't sit well with me, especially if it requires
the bgw_name_extra to start with space.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#24Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Petr Jelinek (#23)
Re: Why does logical replication launcher set application_name?

On 6/2/17 16:44, Petr Jelinek wrote:

However, I am not sure about the bgw_name_extra. I think I would have
preferred keeping full bgw_name field which would be used where full
name is needed and bgw_type where only the worker type is used. The
concatenation just doesn't sit well with me, especially if it requires
the bgw_name_extra to start with space.

I see your point. There are also some i18n considerations to think through.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#25Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#22)
Re: Why does logical replication launcher set application_name?

On 6/2/17 15:08, Peter Eisentraut wrote:

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

This code appears to be buggy because I sometimes get NULL results of
the backend_type lookup, implying that it couldn't find the background
worker slot. This needs another look.

I would like some more input on this proposal, especially from those
have have engineered the extended pg_stat_activity content.

If we don't come to a quick conclusion on this, I'd be content to leave
PG10 as is and put this patch into the next commit fest.

If there are no new insights into this by Monday, I will commit patches
that remove the setting of application_name, which was originally
complained about, and postpone the rest of this patch.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#26Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Peter Eisentraut (#25)
Re: Why does logical replication launcher set application_name?

On Sat, Jun 3, 2017 at 8:53 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 6/2/17 15:08, Peter Eisentraut wrote:

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

This code appears to be buggy because I sometimes get NULL results of
the backend_type lookup, implying that it couldn't find the background
worker slot. This needs another look.

AFAICU, when we register a background worker using
RegisterDynamicBackgroundWorker, it's not included in
BackgroundWorkerList(which is postmaster's list of registered
background workers, in private memory). Instead, we use only
BackgroundWorkerSlots. Perhaps, this is the reason that backend_type
is NULL for parallel workers.

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

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

#27Kuntal Ghosh
kuntalghosh.2007@gmail.com
In reply to: Petr Jelinek (#23)
Re: Why does logical replication launcher set application_name?

On Sat, Jun 3, 2017 at 2:14 AM, Petr Jelinek
<petr.jelinek@2ndquadrant.com> wrote:

On 02/06/17 21:05, Peter Eisentraut wrote:

On 6/2/17 02:31, Masahiko Sawada wrote:

I'd say current patch makes the user difficult to
distinguish between apply worker and table sync worker.

We could arguably make apply workers and sync workers have different
bgw_type values. But if you are interested in that level of detail, you
should perhaps look at pg_stat_subscription. pg_stat_activity only
contains the "common" data, and the process-specific data is in other views.

Agreed with this.

However, I am not sure about the bgw_name_extra. I think I would have
preferred keeping full bgw_name field which would be used where full
name is needed and bgw_type where only the worker type is used. The
concatenation just doesn't sit well with me, especially if it requires
the bgw_name_extra to start with space.

+1.

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

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

#28Michael Paquier
michael.paquier@gmail.com
In reply to: Kuntal Ghosh (#27)
Re: Why does logical replication launcher set application_name?

On Sat, Jun 3, 2017 at 4:33 PM, Kuntal Ghosh <kuntalghosh.2007@gmail.com> wrote:

On Sat, Jun 3, 2017 at 2:14 AM, Petr Jelinek
<petr.jelinek@2ndquadrant.com> wrote:

However, I am not sure about the bgw_name_extra. I think I would have
preferred keeping full bgw_name field which would be used where full
name is needed and bgw_type where only the worker type is used.

Yes, I don't thnk as well that this has any types of gain. With only
bgw_name, it is still possible to append the same prefix to all the
bgworkers of the same type, and do a search on pg_stat_activity using
'~' for example to fetch all the workers with the same string.

The concatenation just doesn't sit well with me, especially if it requires
the bgw_name_extra to start with space.

+1.

That's not friendly.
--
Michael

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

#29Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Peter Eisentraut (#24)
Re: Why does logical replication launcher set application_name?

On 03/06/17 05:18, Peter Eisentraut wrote:

On 6/2/17 16:44, Petr Jelinek wrote:

However, I am not sure about the bgw_name_extra. I think I would have
preferred keeping full bgw_name field which would be used where full
name is needed and bgw_type where only the worker type is used. The
concatenation just doesn't sit well with me, especially if it requires
the bgw_name_extra to start with space.

I see your point. There are also some i18n considerations to think through.

So thinking a bit more, I wonder if we could simply do following:
- remove the application_name from logical workers
- add bgw_type and use it for worker type (if empty, use 'bgworker' like
now), would be probably nice if parallel workers added something to
indicate they are parallel workers there as well
- remove the 'bgworker:' prefix for ps display and just use the bgw_name

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#30Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#25)
Re: Why does logical replication launcher set application_name?

On 6/2/17 23:23, Peter Eisentraut wrote:

On 6/2/17 15:08, Peter Eisentraut wrote:

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

This code appears to be buggy because I sometimes get NULL results of
the backend_type lookup, implying that it couldn't find the background
worker slot. This needs another look.

I would like some more input on this proposal, especially from those
have have engineered the extended pg_stat_activity content.

If we don't come to a quick conclusion on this, I'd be content to leave
PG10 as is and put this patch into the next commit fest.

If there are no new insights into this by Monday, I will commit patches
that remove the setting of application_name, which was originally
complained about, and postpone the rest of this patch.

Done, and added the rest of the patch to the next commit fest:
https://commitfest.postgresql.org/14/1165/

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#31Robert Haas
robertmhaas@gmail.com
In reply to: Kuntal Ghosh (#27)
Re: Why does logical replication launcher set application_name?

On Sat, Jun 3, 2017 at 3:33 AM, Kuntal Ghosh <kuntalghosh.2007@gmail.com> wrote:

Agreed with this.

However, I am not sure about the bgw_name_extra. I think I would have
preferred keeping full bgw_name field which would be used where full
name is needed and bgw_type where only the worker type is used. The
concatenation just doesn't sit well with me, especially if it requires
the bgw_name_extra to start with space.

+1.

+1 from me, too.

The problem with the status quo (after Peter's commit) is that there's
now nothing at all to identify the logical replication launcher, apart
from the wait_event field, which is likely to be LogicalLauncherMain
fairly often if you've got the launcher. I don't personally see why
we can't simply adopt Tom's original proposal of setting the query
string to something like "<logical replication launcher>" which, while
maybe not as elegant as providing some way to override the
backend_type field, would be almost no work and substantially better
for v10 than what we've got now.

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

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

#32Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Robert Haas (#31)
Re: Why does logical replication launcher set application_name?

On 6/6/17 15:58, Robert Haas wrote:

The problem with the status quo (after Peter's commit) is that there's
now nothing at all to identify the logical replication launcher, apart
from the wait_event field, which is likely to be LogicalLauncherMain
fairly often if you've got the launcher. I don't personally see why
we can't simply adopt Tom's original proposal of setting the query
string to something like "<logical replication launcher>" which, while
maybe not as elegant as providing some way to override the
backend_type field, would be almost no work and substantially better
for v10 than what we've got now.

The decision was made to add background workers to pg_stat_activity, but
no facility was provided to tell the background workers apart. Is it
now the job of every background worker to invent a hack to populate some
other pg_stat_activity field with some ad hoc information? What about
other logical replication worker types, parallel workers, external
background workers, auto-prewarm?

I think the bgw_type addition that I proposed nearby would solve this
quite well, but it needs a bit of work. And arguably, it's too late for
PG10, but one could also argue that this is a design fault in the
pg_stat_activity extension that is valid to fix in PG10.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#33Magnus Hagander
magnus@hagander.net
In reply to: Peter Eisentraut (#32)
Re: Why does logical replication launcher set application_name?

On Wed, Jun 7, 2017 at 4:58 AM, Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> wrote:

On 6/6/17 15:58, Robert Haas wrote:

The problem with the status quo (after Peter's commit) is that there's
now nothing at all to identify the logical replication launcher, apart
from the wait_event field, which is likely to be LogicalLauncherMain
fairly often if you've got the launcher. I don't personally see why
we can't simply adopt Tom's original proposal of setting the query
string to something like "<logical replication launcher>" which, while
maybe not as elegant as providing some way to override the
backend_type field, would be almost no work and substantially better
for v10 than what we've got now.

The decision was made to add background workers to pg_stat_activity, but
no facility was provided to tell the background workers apart. Is it
now the job of every background worker to invent a hack to populate some
other pg_stat_activity field with some ad hoc information? What about
other logical replication worker types, parallel workers, external
background workers, auto-prewarm?

I think the bgw_type addition that I proposed nearby would solve this
quite well, but it needs a bit of work. And arguably, it's too late for
PG10, but one could also argue that this is a design fault in the
pg_stat_activity extension that is valid to fix in PG10.

+1. I definitely think it would be a bad idea to put in what basically
looks like a workaround into 10, since the new feature was added there. I'd
rather have the fix for pg_stat_activity.

We used to keep our query state as a text field and that was a bad idea for
many reasons. So we moved it to a separate field. Let's not repeat that
mistake here.

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/&gt;
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/&gt;

#34Robert Haas
robertmhaas@gmail.com
In reply to: Peter Eisentraut (#32)
Re: Why does logical replication launcher set application_name?

On Tue, Jun 6, 2017 at 10:58 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

The decision was made to add background workers to pg_stat_activity, but
no facility was provided to tell the background workers apart. Is it
now the job of every background worker to invent a hack to populate some
other pg_stat_activity field with some ad hoc information? What about
other logical replication worker types, parallel workers, external
background workers, auto-prewarm?

To be fair, some background workers were already shown in
pg_stat_activity; others were not. Parallel workers, for example,
always showed up in pg_stat_activity, but before v10 they didn't show
the query string, so you had to match them up with the process that
started them using the other fields. I think it's only workers not
connected to a database that weren't previously displayed. You might
be right that not enough that was given to how those could identify
themselves, but you would have had the problem anyway with logical
replication workers that connect to a database.

I think the bgw_type addition that I proposed nearby would solve this
quite well, but it needs a bit of work. And arguably, it's too late for
PG10, but one could also argue that this is a design fault in the
pg_stat_activity extension that is valid to fix in PG10.

I don't mind inventing a way for a background worker to display its
own text in place of the generic "background worker", but like others,
I didn't like splitting up the name field into two parts. I think you
could do the former without doing the latter.

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

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

#35Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Peter Eisentraut (#19)
1 attachment(s)
bgw_type (was Re: Why does logical replication launcher set application_name?)

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

Updated patch incorporating the feedback. I have kept bgw_name as it
was and just added bgw_type completely independently.

One open question is how to treat a missing (empty) bgw_type. I
currently fill in bgw_name as a fallback. We could also treat it as an
error or a warning as a transition measure.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachments:

v2-0001-Add-background-worker-type.patchtext/plain; charset=UTF-8; name=v2-0001-Add-background-worker-type.patch; x-mac-creator=0; x-mac-type=0Download
From 73142adf6e56e44d97bd9f855072cba17ef5ea4c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Thu, 31 Aug 2017 12:24:47 -0400
Subject: [PATCH v2] Add background worker type

Add bgw_type field to background worker structure.  It is intended to be
set to the same value for all workers of the same type, so they can be
grouped in pg_stat_activity, for example.

The backend_type column in pg_stat_activity now shows bgw_type for a
background worker.  The ps listing and some log messages no longer call
out that a process is a "background worker" but just show the bgw_type.
That way, being a background worker is effectively an implementation
detail now that is not shown to the user.
---
 contrib/pg_prewarm/autoprewarm.c           |  6 ++--
 doc/src/sgml/bgworker.sgml                 | 12 +++++--
 src/backend/access/transam/parallel.c      |  1 +
 src/backend/postmaster/bgworker.c          | 53 +++++++++++++++++++++++++++---
 src/backend/postmaster/postmaster.c        | 10 ++----
 src/backend/replication/logical/launcher.c |  3 ++
 src/backend/utils/adt/pgstatfuncs.c        | 16 +++++++--
 src/include/postmaster/bgworker.h          |  2 ++
 src/test/modules/test_shm_mq/setup.c       |  2 +-
 src/test/modules/worker_spi/worker_spi.c   |  8 +++--
 10 files changed, 91 insertions(+), 22 deletions(-)

diff --git a/contrib/pg_prewarm/autoprewarm.c b/contrib/pg_prewarm/autoprewarm.c
index cc0350e6d6..006c3153db 100644
--- a/contrib/pg_prewarm/autoprewarm.c
+++ b/contrib/pg_prewarm/autoprewarm.c
@@ -800,7 +800,8 @@ apw_start_master_worker(void)
 	worker.bgw_start_time = BgWorkerStart_ConsistentState;
 	strcpy(worker.bgw_library_name, "pg_prewarm");
 	strcpy(worker.bgw_function_name, "autoprewarm_main");
-	strcpy(worker.bgw_name, "autoprewarm");
+	strcpy(worker.bgw_name, "autoprewarm master");
+	strcpy(worker.bgw_type, "autoprewarm master");
 
 	if (process_shared_preload_libraries_in_progress)
 	{
@@ -840,7 +841,8 @@ apw_start_database_worker(void)
 	worker.bgw_start_time = BgWorkerStart_ConsistentState;
 	strcpy(worker.bgw_library_name, "pg_prewarm");
 	strcpy(worker.bgw_function_name, "autoprewarm_database_main");
-	strcpy(worker.bgw_name, "autoprewarm");
+	strcpy(worker.bgw_name, "autoprewarm worker");
+	strcpy(worker.bgw_type, "autoprewarm worker");
 
 	/* must set notify PID to wait for shutdown */
 	worker.bgw_notify_pid = MyProcPid;
diff --git a/doc/src/sgml/bgworker.sgml b/doc/src/sgml/bgworker.sgml
index b422323081..822632bf02 100644
--- a/doc/src/sgml/bgworker.sgml
+++ b/doc/src/sgml/bgworker.sgml
@@ -51,6 +51,7 @@ <title>Background Worker Processes</title>
 typedef struct BackgroundWorker
 {
     char        bgw_name[BGW_MAXLEN];
+    char        bgw_type[BGW_MAXLEN];
     int         bgw_flags;
     BgWorkerStartTime bgw_start_time;
     int         bgw_restart_time;       /* in seconds, or BGW_NEVER_RESTART */
@@ -64,8 +65,15 @@ <title>Background Worker Processes</title>
   </para>
 
   <para>
-   <structfield>bgw_name</> is a string to be used in log messages, process
-   listings and similar contexts.
+   <structfield>bgw_name</> and <structfield>bgw_type</structfield> are
+   strings to be used in log messages, process listings and similar contexts.
+   <structfield>bgw_type</structfield> should be the same for all background
+   workers of the same type, so that it is possible to group such workers in a
+   process listing, for example.  <structfield>bgw_name</structfield> on the
+   other hand can contain additional information about the specific process.
+   (Typically, the string for <structfield>bgw_name</structfield> will contain
+   the string for <structfield>bgw_type</structfield> somehow, but that is not
+   strictly required.)
   </para>
 
   <para>
diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c
index 17b10383e4..9828259e6d 100644
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -438,6 +438,7 @@ LaunchParallelWorkers(ParallelContext *pcxt)
 	memset(&worker, 0, sizeof(worker));
 	snprintf(worker.bgw_name, BGW_MAXLEN, "parallel worker for PID %d",
 			 MyProcPid);
+	snprintf(worker.bgw_type, BGW_MAXLEN, "parallel worker");
 	worker.bgw_flags =
 		BGWORKER_SHMEM_ACCESS | BGWORKER_BACKEND_DATABASE_CONNECTION
 		| BGWORKER_CLASS_PARALLEL;
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 28af6f0f07..da7d12d91a 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -344,6 +344,8 @@ BackgroundWorkerStateChange(void)
 		 */
 		ascii_safe_strlcpy(rw->rw_worker.bgw_name,
 						   slot->worker.bgw_name, BGW_MAXLEN);
+		ascii_safe_strlcpy(rw->rw_worker.bgw_type,
+						   slot->worker.bgw_type, BGW_MAXLEN);
 		ascii_safe_strlcpy(rw->rw_worker.bgw_library_name,
 						   slot->worker.bgw_library_name, BGW_MAXLEN);
 		ascii_safe_strlcpy(rw->rw_worker.bgw_function_name,
@@ -630,6 +632,12 @@ SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
 		return false;
 	}
 
+	/*
+	 * If bgw_type is not filled in, use bgw_name.
+	 */
+	if (strcmp(worker->bgw_type, "") == 0)
+		strcpy(worker->bgw_type, worker->bgw_name);
+
 	return true;
 }
 
@@ -670,8 +678,8 @@ bgworker_die(SIGNAL_ARGS)
 
 	ereport(FATAL,
 			(errcode(ERRCODE_ADMIN_SHUTDOWN),
-			 errmsg("terminating background worker \"%s\" due to administrator command",
-					MyBgworkerEntry->bgw_name)));
+			 errmsg("terminating %s due to administrator command",
+					MyBgworkerEntry->bgw_type)));
 }
 
 /*
@@ -700,7 +708,6 @@ void
 StartBackgroundWorker(void)
 {
 	sigjmp_buf	local_sigjmp_buf;
-	char		buf[MAXPGPATH];
 	BackgroundWorker *worker = MyBgworkerEntry;
 	bgworker_main_type entrypt;
 
@@ -710,8 +717,7 @@ StartBackgroundWorker(void)
 	IsBackgroundWorker = true;
 
 	/* Identify myself via ps */
-	snprintf(buf, MAXPGPATH, "bgworker: %s", worker->bgw_name);
-	init_ps_display(buf, "", "", "");
+	init_ps_display(worker->bgw_name, "", "", "");
 
 	/*
 	 * If we're not supposed to have shared memory access, then detach from
@@ -1233,3 +1239,40 @@ LookupBackgroundWorkerFunction(const char *libraryname, const char *funcname)
 	return (bgworker_main_type)
 		load_external_function(libraryname, funcname, true, NULL);
 }
+
+/*
+ * Given a PID, get the bgw_type of the background worker.  Returns NULL if
+ * not a valid background worker.
+ *
+ * The return value is in static memory belonging to this function, so it has
+ * to be used before calling this function again.  This is so that the caller
+ * doesn't have to worry about the background worker locking protocol.
+ */
+const char *
+GetBackgroundWorkerTypeByPid(pid_t pid)
+{
+	int			slotno;
+	bool		found = false;
+	static char	result[BGW_MAXLEN];
+
+	LWLockAcquire(BackgroundWorkerLock, LW_SHARED);
+
+	for (slotno = 0; slotno < BackgroundWorkerData->total_slots; slotno++)
+	{
+		BackgroundWorkerSlot *slot = &BackgroundWorkerData->slot[slotno];
+
+		if (slot->pid > 0 && slot->pid == pid)
+		{
+			strcpy(result, slot->worker.bgw_type);
+			found = true;
+			break;
+		}
+	}
+
+	LWLockRelease(BackgroundWorkerLock);
+
+	if (!found)
+		return NULL;
+
+	return result;
+}
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 95180b2ef5..cf4bffa8b3 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -3096,7 +3096,6 @@ static bool
 CleanupBackgroundWorker(int pid,
 						int exitstatus) /* child's exit status */
 {
-	char		namebuf[MAXPGPATH];
 	slist_mutable_iter iter;
 
 	slist_foreach_modify(iter, &BackgroundWorkerList)
@@ -3114,9 +3113,6 @@ CleanupBackgroundWorker(int pid,
 			exitstatus = 0;
 #endif
 
-		snprintf(namebuf, MAXPGPATH, "%s: %s", _("worker process"),
-				 rw->rw_worker.bgw_name);
-
 		if (!EXIT_STATUS_0(exitstatus))
 		{
 			/* Record timestamp, so we know when to restart the worker. */
@@ -3138,7 +3134,7 @@ CleanupBackgroundWorker(int pid,
 		{
 			if (!EXIT_STATUS_0(exitstatus) && !EXIT_STATUS_1(exitstatus))
 			{
-				HandleChildCrash(pid, exitstatus, namebuf);
+				HandleChildCrash(pid, exitstatus, rw->rw_worker.bgw_name);
 				return true;
 			}
 		}
@@ -3151,7 +3147,7 @@ CleanupBackgroundWorker(int pid,
 		if (!ReleasePostmasterChildSlot(rw->rw_child_slot) &&
 			(rw->rw_worker.bgw_flags & BGWORKER_SHMEM_ACCESS) != 0)
 		{
-			HandleChildCrash(pid, exitstatus, namebuf);
+			HandleChildCrash(pid, exitstatus, rw->rw_worker.bgw_name);
 			return true;
 		}
 
@@ -3176,7 +3172,7 @@ CleanupBackgroundWorker(int pid,
 		ReportBackgroundWorkerExit(&iter);	/* report child death */
 
 		LogChildExit(EXIT_STATUS_0(exitstatus) ? DEBUG1 : LOG,
-					 namebuf, pid, exitstatus);
+					 rw->rw_worker.bgw_name, pid, exitstatus);
 
 		return true;
 	}
diff --git a/src/backend/replication/logical/launcher.c b/src/backend/replication/logical/launcher.c
index 6c894421a3..cf5f02aef8 100644
--- a/src/backend/replication/logical/launcher.c
+++ b/src/backend/replication/logical/launcher.c
@@ -421,6 +421,7 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
 	else
 		snprintf(bgw.bgw_name, BGW_MAXLEN,
 				 "logical replication worker for subscription %u", subid);
+	snprintf(bgw.bgw_type, BGW_MAXLEN, "logical replication worker");
 
 	bgw.bgw_restart_time = BGW_NEVER_RESTART;
 	bgw.bgw_notify_pid = MyProcPid;
@@ -768,6 +769,8 @@ ApplyLauncherRegister(void)
 	snprintf(bgw.bgw_function_name, BGW_MAXLEN, "ApplyLauncherMain");
 	snprintf(bgw.bgw_name, BGW_MAXLEN,
 			 "logical replication launcher");
+	snprintf(bgw.bgw_type, BGW_MAXLEN,
+			 "logical replication launcher");
 	bgw.bgw_restart_time = 5;
 	bgw.bgw_notify_pid = 0;
 	bgw.bgw_main_arg = (Datum) 0;
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 20ce48b2d8..dd5898ec0a 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -21,6 +21,7 @@
 #include "funcapi.h"
 #include "miscadmin.h"
 #include "pgstat.h"
+#include "postmaster/bgworker_internals.h"
 #include "postmaster/postmaster.h"
 #include "storage/proc.h"
 #include "storage/procarray.h"
@@ -820,8 +821,19 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
 				}
 			}
 			/* Add backend type */
-			values[17] =
-				CStringGetTextDatum(pgstat_get_backend_desc(beentry->st_backendType));
+			if (beentry->st_backendType == B_BG_WORKER)
+			{
+				const char *bgw_type;
+
+				bgw_type = GetBackgroundWorkerTypeByPid(beentry->st_procpid);
+				if (bgw_type)
+					values[17] = CStringGetTextDatum(bgw_type);
+				else
+					nulls[17] = true;
+			}
+			else
+				values[17] =
+					CStringGetTextDatum(pgstat_get_backend_desc(beentry->st_backendType));
 		}
 		else
 		{
diff --git a/src/include/postmaster/bgworker.h b/src/include/postmaster/bgworker.h
index e2ecd3c9eb..6b4e631880 100644
--- a/src/include/postmaster/bgworker.h
+++ b/src/include/postmaster/bgworker.h
@@ -88,6 +88,7 @@ typedef enum
 typedef struct BackgroundWorker
 {
 	char		bgw_name[BGW_MAXLEN];
+	char		bgw_type[BGW_MAXLEN];
 	int			bgw_flags;
 	BgWorkerStartTime bgw_start_time;
 	int			bgw_restart_time;	/* in seconds, or BGW_NEVER_RESTART */
@@ -122,6 +123,7 @@ extern BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle,
 extern BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pid);
 extern BgwHandleStatus
 			WaitForBackgroundWorkerShutdown(BackgroundWorkerHandle *);
+extern const char *GetBackgroundWorkerTypeByPid(pid_t pid);
 
 /* Terminate a bgworker */
 extern void TerminateBackgroundWorker(BackgroundWorkerHandle *handle);
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index 3ae9018360..561f6f9bac 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -219,7 +219,7 @@ setup_background_workers(int nworkers, dsm_segment *seg)
 	worker.bgw_restart_time = BGW_NEVER_RESTART;
 	sprintf(worker.bgw_library_name, "test_shm_mq");
 	sprintf(worker.bgw_function_name, "test_shm_mq_main");
-	snprintf(worker.bgw_name, BGW_MAXLEN, "test_shm_mq");
+	snprintf(worker.bgw_type, BGW_MAXLEN, "test_shm_mq");
 	worker.bgw_main_arg = UInt32GetDatum(dsm_segment_handle(seg));
 	/* set bgw_notify_pid, so we can detect if the worker stops */
 	worker.bgw_notify_pid = MyProcPid;
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index 12c8cd5774..4c6ab6d575 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -111,7 +111,7 @@ initialize_worker_spi(worktable *table)
 	StartTransactionCommand();
 	SPI_connect();
 	PushActiveSnapshot(GetTransactionSnapshot());
-	pgstat_report_activity(STATE_RUNNING, "initializing spi_worker schema");
+	pgstat_report_activity(STATE_RUNNING, "initializing worker_spi schema");
 
 	/* XXX could we use CREATE SCHEMA IF NOT EXISTS? */
 	initStringInfo(&buf);
@@ -359,7 +359,8 @@ _PG_init(void)
 	 */
 	for (i = 1; i <= worker_spi_total_workers; i++)
 	{
-		snprintf(worker.bgw_name, BGW_MAXLEN, "worker %d", i);
+		snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi worker %d", i);
+		snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi");
 		worker.bgw_main_arg = Int32GetDatum(i);
 
 		RegisterBackgroundWorker(&worker);
@@ -385,7 +386,8 @@ worker_spi_launch(PG_FUNCTION_ARGS)
 	worker.bgw_restart_time = BGW_NEVER_RESTART;
 	sprintf(worker.bgw_library_name, "worker_spi");
 	sprintf(worker.bgw_function_name, "worker_spi_main");
-	snprintf(worker.bgw_name, BGW_MAXLEN, "worker %d", i);
+	snprintf(worker.bgw_name, BGW_MAXLEN, "worker_spi worker %d", i);
+	snprintf(worker.bgw_type, BGW_MAXLEN, "worker_spi");
 	worker.bgw_main_arg = Int32GetDatum(i);
 	/* set bgw_notify_pid so that we can use WaitForBackgroundWorkerStartup */
 	worker.bgw_notify_pid = MyProcPid;

base-commit: b5c75feca7ffb2667c42b86286e262d6cb709b76
-- 
2.14.1

#36Michael Paquier
michael.paquier@gmail.com
In reply to: Peter Eisentraut (#35)
Re: bgw_type (was Re: Why does logical replication launcher set application_name?)

On Fri, Sep 1, 2017 at 4:49 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

Updated patch incorporating the feedback. I have kept bgw_name as it
was and just added bgw_type completely independently.

-             errmsg("terminating background worker \"%s\" due to
administrator command",
-                    MyBgworkerEntry->bgw_name)));
+             errmsg("terminating %s due to administrator command",
+                    MyBgworkerEntry->bgw_type)));
"terminating background worker %s of type %s due to administrator
command", bgw_name, bgw_type?

One open question is how to treat a missing (empty) bgw_type. I
currently fill in bgw_name as a fallback. We could also treat it as an
error or a warning as a transition measure.

Hm. Why not reporting an empty type string as NULL at SQL level and
just let it empty them? I tend to like more interfaces that report
exactly what is exactly registered at memory-level, because that's
easier to explain to users and in the documentation, as well as easier
to interpret and easier for module developers.
--
Michael

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

#37Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#36)
Re: bgw_type (was Re: Why does logical replication launcher set application_name?)

On 8/31/17 23:22, Michael Paquier wrote:

One open question is how to treat a missing (empty) bgw_type. I
currently fill in bgw_name as a fallback. We could also treat it as an
error or a warning as a transition measure.

Hm. Why not reporting an empty type string as NULL at SQL level and
just let it empty them? I tend to like more interfaces that report
exactly what is exactly registered at memory-level, because that's
easier to explain to users and in the documentation, as well as easier
to interpret and easier for module developers.

But then background workers that are not updated for, say, PG11 will not
show anything useful in pg_stat_activity. We should have some amount of
backward compatibility here.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#38Petr Jelinek
petr.jelinek@2ndquadrant.com
In reply to: Peter Eisentraut (#37)
Re: bgw_type (was Re: Why does logical replication launcher set application_name?)

On 25/09/17 16:45, Peter Eisentraut wrote:

On 8/31/17 23:22, Michael Paquier wrote:

One open question is how to treat a missing (empty) bgw_type. I
currently fill in bgw_name as a fallback. We could also treat it as an
error or a warning as a transition measure.

Hm. Why not reporting an empty type string as NULL at SQL level and
just let it empty them? I tend to like more interfaces that report
exactly what is exactly registered at memory-level, because that's
easier to explain to users and in the documentation, as well as easier
to interpret and easier for module developers.

But then background workers that are not updated for, say, PG11 will not
show anything useful in pg_stat_activity. We should have some amount of
backward compatibility here.

Maybe the empty bgw_type could mean just "bgworker"?

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

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

#39Daniel Gustafsson
daniel@yesql.se
In reply to: Peter Eisentraut (#35)
Re: bgw_type (was Re: Why does logical replication launcher set application_name?)

On 31 Aug 2017, at 21:49, Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

Updated patch incorporating the feedback. I have kept bgw_name as it
was and just added bgw_type completely independently.

The patch applies with minor fuzz, compiles without introduced warnings and
work the way it says on the tin. The utility of the proposed functionality is
a clear win so +1 on getting that in.

One open question is how to treat a missing (empty) bgw_type. I
currently fill in bgw_name as a fallback. We could also treat it as an
error or a warning as a transition measure.

Warnings tend to stick around forever in my experience. An error would work as
a transition measure, but it seems a hammer too far.

Falling back on bgw_name solves there being data with the risk that some
workers will have a wonky type displayed, and those are the ones that of course
will never get updated. Either going with NULL as Michael suggested elsewhere
in this thread (my preference as well) or a default string along the lines of
“Unknown type” would probably carry more incentive to update.

A few random comments on the patch:

Regarding the following hunk:

+   process listing, for example.  <structfield>bgw_name</structfield> on the
+   other hand can contain additional information about the specific process.
+   (Typically, the string for <structfield>bgw_name</structfield> will contain
+   the string for <structfield>bgw_type</structfield> somehow, but that is not
+   strictly required.)

This reads a bit too (oddly) detailed to me, I would’ve phrased it as something
along the lines of:

"Typically, the string for bgw_name will contain the type somehow, but that
is not strictly required.”

I find omitting “background worker” in the following hunk is leaving out
valuable information for bgworkers with badly configured types, but it’s
definitely a matter of taste rather than a straight-up patch critique:

-	 errmsg("terminating background worker \"%s\" due to administrator command",
-			MyBgworkerEntry->bgw_name)));
+	 errmsg("terminating %s due to administrator command",
+			MyBgworkerEntry->bgw_type)));

Updating the status to “Ready for committer” with the discussion around missing
bgw_type left as a decision point for a committer.

cheers ./daniel

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

#40Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Michael Paquier (#36)
Re: bgw_type (was Re: Why does logical replication launcher set application_name?)

On 8/31/17 23:22, Michael Paquier wrote:

On Fri, Sep 1, 2017 at 4:49 AM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:

On 5/30/17 23:10, Peter Eisentraut wrote:

Here is a proposed solution that splits bgw_name into bgw_type and
bgw_name_extra. bgw_type shows up in pg_stat_activity.backend_type.
Uses of application_name are removed, because they are no longer
necessary to identity the process type.

Updated patch incorporating the feedback. I have kept bgw_name as it
was and just added bgw_type completely independently.

-             errmsg("terminating background worker \"%s\" due to
administrator command",
-                    MyBgworkerEntry->bgw_name)));
+             errmsg("terminating %s due to administrator command",
+                    MyBgworkerEntry->bgw_type)));
"terminating background worker %s of type %s due to administrator
command", bgw_name, bgw_type?

OK.

One open question is how to treat a missing (empty) bgw_type. I
currently fill in bgw_name as a fallback. We could also treat it as an
error or a warning as a transition measure.

Hm. Why not reporting an empty type string as NULL at SQL level and
just let it empty them? I tend to like more interfaces that report
exactly what is exactly registered at memory-level, because that's
easier to explain to users and in the documentation, as well as easier
to interpret and easier for module developers.

The problem here is that we refer to bgw_type in a bunch of places now,
and adding a suitable fallback in all of these places would be a lot of
code and it would create a regression in behavior. In practice, I think
that would be a lot of trouble for no gain.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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

#41Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Daniel Gustafsson (#39)
Re: bgw_type (was Re: Why does logical replication launcher set application_name?)

On 9/27/17 18:59, Daniel Gustafsson wrote:

The patch applies with minor fuzz, compiles without introduced warnings and
work the way it says on the tin. The utility of the proposed functionality is
a clear win so +1 on getting that in.

I have committed this patch incorporating the feedback in this thread.

Regarding the following hunk:

+   process listing, for example.  <structfield>bgw_name</structfield> on the
+   other hand can contain additional information about the specific process.
+   (Typically, the string for <structfield>bgw_name</structfield> will contain
+   the string for <structfield>bgw_type</structfield> somehow, but that is not
+   strictly required.)

This reads a bit too (oddly) detailed to me, I would’ve phrased it as something
along the lines of:

"Typically, the string for bgw_name will contain the type somehow, but that
is not strictly required.”

Yes, that's better.

I find omitting “background worker” in the following hunk is leaving out
valuable information for bgworkers with badly configured types, but it’s
definitely a matter of taste rather than a straight-up patch critique:

-	 errmsg("terminating background worker \"%s\" due to administrator command",
-			MyBgworkerEntry->bgw_name)));
+	 errmsg("terminating %s due to administrator command",
+			MyBgworkerEntry->bgw_type)));

Also changed.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

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