Issue
You are inspecting the pg_stat_activity
view on your database and you see one or several long-running processes showing START_REPLICATION
queries:
DATABASE=> select pid, usename, application_name, backend_type, query_start, state, query from pg_stat_activity;
pid | usename | application_name | backend_type | query_start | state | query
--------+----------+------------------+--------------+-------------------------------+--------+-----------------------------------------
444694 | postgres | follower | walsender | 2021-09-14 11:07:51.198651+00 | active | START_REPLICATION 0/DC000000 TIMELINE 1
424100 | postgres | standby | walsender | 2021-09-14 11:07:51.198651+00 | active | START_REPLICATION 0/DC000000 TIMELINE 1
(...)
Resolution
Replication processes can be present in your database if your database has a follower (or a hidden standby in the case of High Availability plans), or if you're using the Heroku Streaming Data Connectors feature, which is based on logical replication.
Since the PostgreSQL 13.4 release, as well as the patch releases for 12.8, 11.13 and 10.18, walsender
processes will show their latest replication commands in pg_stat_activity
.
In the context of Heroku Postgres, you will see these processes when your database has a follower or when it's using one of our High Availability plans that automatically maintains a standby replica for your database. The application_name
field of pg_stat_activity
will reflect if this replication activity comes from a follower
or a standby
. Heroku Postgres databases that are scheduled for maintenance will also show replication queries, as Heroku prepares a hidden follower that will replace the database once maintenance runs.
To see these processes specifically, you can filter the queries to the pg_stat_activity
view with: WHERE backend_type = 'walsender'
.
In previous PostgreSQL versions, these processes didn't show their replication queries in pg_stat_activity
and those were reflected with an empty query
field as follows:
DATABASE=> select pid, usename, application_name, backend_type, query_start, state, query from pg_stat_activity;
pid | usename | application_name | backend_type | query_start | state | query
-------+----------+------------------+--------------+-------------+--------+-------
29897 | postgres | follower | walsender | | active |
(...)
For logical replication slots created by Streaming Data Connectors, you will see the details of the connector in the query
field, as in:
pid | usename | application_name | backend_type | query_start | state | query
-------+-------------------+------------------------+--------------+-------------------------------+--------+-------------------------------------------------------------------------------------------------------------------------------------
59641 | default_user_name | PostgreSQL JDBC Driver | walsender | 2022-11-03 11:03:41.394532+00 | active | START_REPLICATION SLOT "connector_example_00" LOGICAL 2C70/100E6CB0 ("proto_version" '1', "publication_names" connector_example_00')