Re: Introduce XID age and inactive timeout based replication slot invalidation
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add a test for commit ac0e33136a using the injection point.
- 8a695d7998be 18.0 landed
-
Invalidate inactive replication slots.
- ac0e33136abc 18.0 landed
-
Fix incorrect slot type in BuildTupleHashTableExt
- d96d1d5152f3 18.0 cited
-
Allow synced slots to have their inactive_since.
- 6f132ed693b6 17.0 landed
-
Change last_inactive_time to inactive_since in pg_replication_slots.
- 6d49c8d4b4f4 17.0 landed
-
Track last_inactive_time in pg_replication_slots.
- a11f330b5584 17.0 landed
-
Track invalidation_reason in pg_replication_slots.
- 6ae701b4378d 17.0 landed
-
Add option force_initdb to PostgreSQL::Test::Cluster:init()
- ff9e1e764fcc 17.0 cited
-
Add a failover option to subscriptions.
- 776621a5e479 17.0 cited
-
Allow setting failover property in the replication command.
- 73292404370c 17.0 cited
-
Allow to enable failover property for replication slots via SQL API.
- c393308b69d2 17.0 cited
-
Track conflict_reason in pg_replication_slots.
- 007693f2a3ac 17.0 cited
-
Log messages for replication slot acquisition and release.
- 7c3fb505b14e 17.0 cited
-
Remove vacuum_defer_cleanup_age
- 1118cd37eb61 16.0 cited
-
Fix corruption due to vacuum_defer_cleanup_age underflowing 64bit xids
- be504a3e974d 16.0 cited
-
meson: Add initial version of meson based build system
- e6927270cd18 16.0 cited
Attachments
- v11-0001-Track-invalidation_reason-in-pg_replication_slot.patch (application/octet-stream) patch v11-0001
- v11-0002-Add-XID-age-based-replication-slot-invalidation.patch (application/octet-stream) patch v11-0002
- v11-0003-Track-inactive-replication-slot-information.patch (application/octet-stream) patch v11-0003
- v11-0004-Add-inactive_timeout-based-replication-slot-inva.patch (application/octet-stream) patch v11-0004
On Fri, Mar 15, 2024 at 12:49 PM shveta malik <shveta.malik@gmail.com> wrote: > > patch002: > > 1) > I would like to understand the purpose of 'inactive_count'? Is it only > for users for monitoring purposes? We are not using it anywhere > internally. inactive_count metric helps detect unstable replication slots connections that have a lot of disconnections. It's not used for the inactive_timeout based slot invalidation mechanism. > I shutdown the instance 5 times and found that 'inactive_count' became > 5 for all the slots created on that instance. Is this intentional? Yes, it's incremented on shutdown (and for that matter upon every slot release) for all the slots that are tied to walsenders. > I mean we can not really use them if the instance is down. I felt it > should increment the inactive_count only if during the span of > instance, they were actually inactive i.e. no streaming or replication > happening through them. inactive_count is persisted to disk- upon clean shutdown, so, once the slots become active again, one gets to see the metric and deduce some info on disconnections. Having said that, I'm okay to hear from others on the inactive_count metric being added. > 2) > slot.c: > + case RS_INVAL_XID_AGE: > > Can we optimize this code? It has duplicate code for processing > s->data.catalog_xmin and s->data.xmin. Can we create a sub-function > for this purpose and call it twice here? Good idea. Done that way. > 2) > The msg for patch 3 says: > -------------- > a) when replication slots is lying inactive for a day or so using > last_inactive_at metric, > b) when a replication slot is becoming inactive too frequently using > last_inactive_at metric. > -------------- > I think in b, you want to refer to inactive_count instead of last_inactive_at? Right. Changed. > 3) > I do not see invalidation_reason updated for 2 new reasons in system-views.sgml Nice catch. Added them now. I've also responded to Bertrand's comments here. On Wed, Mar 6, 2024 at 3:56 PM Bertrand Drouvot <bertranddrouvot.pg@gmail.com> wrote: > > A few comments: > > 1 === > > + The reason for the slot's invalidation. <literal>NULL</literal> if the > + slot is currently actively being used. > > s/currently actively being used/not invalidated/ ? (I mean it could be valid > and not being used). Changed. > 3 === > > res = executeQueryOrDie(conn, "SELECT slot_name, plugin, two_phase, failover, " > - "%s as caught_up, conflict_reason IS NOT NULL as invalid " > + "%s as caught_up, invalidation_reason IS NOT NULL as invalid " > "FROM pg_catalog.pg_replication_slots " > - "(CASE WHEN conflict_reason IS NOT NULL THEN FALSE " > + "(CASE WHEN invalidation_reason IS NOT NULL THEN FALSE " > > Yeah that's fine because there is logical slot filtering here. Right. And, we really are looking for invalid slots there, so use of invalidation_reason is much more correct than conflicting. > 4 === > > -GetSlotInvalidationCause(const char *conflict_reason) > +GetSlotInvalidationCause(const char *invalidation_reason) > > Should we change the comment "Maps a conflict reason" above this function? Changed. > 5 === > > -# Check conflict_reason is NULL for physical slot > +# Check invalidation_reason is NULL for physical slot > $res = $node_primary->safe_psql( > 'postgres', qq[ > - SELECT conflict_reason is null FROM pg_replication_slots where slot_name = '$primary_slotname';] > + SELECT invalidation_reason is null FROM pg_replication_slots where slot_name = '$primary_slotname';] > ); > > > I don't think this test is needed anymore: it does not make that much sense since > it's done after the primary database initialization and startup. It is now turned into a test verifying 'conflicting boolean' is null for the physical slot. Isn't that okay? > 6 === > > 'Logical slots are reported as non conflicting'); > > What about? > > " > # Verify slots are reported as valid in pg_replication_slots > 'Logical slots are reported as valid'); > " Changed. Please see the attached v11 patch set with all the above review comments addressed. -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com