postgresql add tag
PeterVandivier
The [docs on `pg_stat_activity`][1] tell us that `datname` is the...

> Name of the database this backend is connected to

I can currently see a number of records where `datname` is NULL. How have these mischievous workers connected to my database service without the virtue of a database context?

<>https://dbfiddle.uk/?rdbms=postgres_12&fiddle=9e522a7e869f5dae785249dc76698ccc

If I had superuser permissions, I might be able to see that these workers have a `backend_type` something like...

- autovacuum launcher
- logical replication launcher
- background writer
- checkpointer
- walwriter

![Screenshot 2020-07-30 at 15.22.00.png](/image?hash=f72def8e737c87c7249f07ebd51916e883e8dd30a17f8209a6c32ae1fa41b2a6)

From the [source code][2], I can hazard a guess that [`pgstat_fetch_stat_local_beentry`][3] is bailing trying to define the backend context for these workers. But the fact that I'm trying to read C code means I've probably failed at more elementary googling.

Halp me, TA; you're my only hope...

[1]: https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW
[2]: https://github.com/postgres/postgres/blob/11a68e4b53ffccf336a2faf5fa380acda28e880b/src/backend/utils/adt/pgstatfuncs.c#L568
[3]: https://github.com/postgres/postgres/blob/e7591fd3cae6c64236ef29d3c87e69b96608a19b/src/backend/postmaster/pgstat.c#L2608

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.