What are the long-running processes running START_REPLICATION queries on my Heroku Postgres database?

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

This is part of new behavior introduced with the PostgreSQL 13.4 release, as well as the patch releases for 12.8, 11.13 and 10.18, that makes walsender processes to 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.

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 |
(...)

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support