postgresql/src/include/catalog/pg_subscription_rel.h
Amit Kapila a850be2fe6 Add max_retention_duration option to subscriptions.
This commit introduces a new subscription parameter,
max_retention_duration, aimed at mitigating excessive accumulation of dead
tuples when retain_dead_tuples is enabled and the apply worker lags behind
the publisher.

When the time spent advancing a non-removable transaction ID exceeds the
max_retention_duration threshold, the apply worker will stop retaining
conflict detection information. In such cases, the conflict slot's xmin
will be set to InvalidTransactionId, provided that all apply workers
associated with the subscription (with retain_dead_tuples enabled) confirm
the retention duration has been exceeded.

To ensure retention status persists across server restarts, a new column
subretentionactive has been added to the pg_subscription catalog. This
prevents unnecessary reactivation of retention logic after a restart.

The conflict detection slot will not be automatically re-initialized
unless a new subscription is created with retain_dead_tuples = true, or
the user manually re-enables retain_dead_tuples.

A future patch will introduce support for automatic slot re-initialization
once at least one apply worker confirms that the retention duration is
within the configured max_retention_duration.

Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Nisha Moond <nisha.moond412@gmail.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/OS0PR01MB5716BE80DAEB0EE2A6A5D1F5949D2@OS0PR01MB5716.jpnprd01.prod.outlook.com
2025-09-02 03:20:18 +00:00

97 lines
3.4 KiB
C

/* -------------------------------------------------------------------------
*
* pg_subscription_rel.h
* definition of the system catalog containing the state for each
* replicated table in each subscription (pg_subscription_rel)
*
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/catalog/pg_subscription_rel.h
*
* NOTES
* The Catalog.pm module reads this file and derives schema
* information.
*
* -------------------------------------------------------------------------
*/
#ifndef PG_SUBSCRIPTION_REL_H
#define PG_SUBSCRIPTION_REL_H
#include "access/xlogdefs.h"
#include "catalog/genbki.h"
#include "catalog/pg_subscription_rel_d.h" /* IWYU pragma: export */
#include "nodes/pg_list.h"
/* ----------------
* pg_subscription_rel definition. cpp turns this into
* typedef struct FormData_pg_subscription_rel
* ----------------
*/
CATALOG(pg_subscription_rel,6102,SubscriptionRelRelationId)
{
Oid srsubid BKI_LOOKUP(pg_subscription); /* Oid of subscription */
Oid srrelid BKI_LOOKUP(pg_class); /* Oid of relation */
char srsubstate; /* state of the relation in subscription */
/*
* Although srsublsn is a fixed-width type, it is allowed to be NULL, so
* we prevent direct C code access to it just as for a varlena field.
*/
#ifdef CATALOG_VARLEN /* variable-length fields start here */
XLogRecPtr srsublsn BKI_FORCE_NULL; /* remote LSN of the state change
* used for synchronization
* coordination, or NULL if not
* valid */
#endif
} FormData_pg_subscription_rel;
typedef FormData_pg_subscription_rel *Form_pg_subscription_rel;
DECLARE_UNIQUE_INDEX_PKEY(pg_subscription_rel_srrelid_srsubid_index, 6117, SubscriptionRelSrrelidSrsubidIndexId, pg_subscription_rel, btree(srrelid oid_ops, srsubid oid_ops));
MAKE_SYSCACHE(SUBSCRIPTIONRELMAP, pg_subscription_rel_srrelid_srsubid_index, 64);
#ifdef EXPOSE_TO_CLIENT_CODE
/* ----------------
* substate constants
* ----------------
*/
#define SUBREL_STATE_INIT 'i' /* initializing (sublsn NULL) */
#define SUBREL_STATE_DATASYNC 'd' /* data is being synchronized (sublsn
* NULL) */
#define SUBREL_STATE_FINISHEDCOPY 'f' /* tablesync copy phase is completed
* (sublsn NULL) */
#define SUBREL_STATE_SYNCDONE 's' /* synchronization finished in front of
* apply (sublsn set) */
#define SUBREL_STATE_READY 'r' /* ready (sublsn set) */
/* These are never stored in the catalog, we only use them for IPC. */
#define SUBREL_STATE_UNKNOWN '\0' /* unknown state */
#define SUBREL_STATE_SYNCWAIT 'w' /* waiting for sync */
#define SUBREL_STATE_CATCHUP 'c' /* catching up with apply */
#endif /* EXPOSE_TO_CLIENT_CODE */
typedef struct SubscriptionRelState
{
Oid relid;
XLogRecPtr lsn;
char state;
} SubscriptionRelState;
extern void AddSubscriptionRelState(Oid subid, Oid relid, char state,
XLogRecPtr sublsn, bool retain_lock);
extern void UpdateSubscriptionRelState(Oid subid, Oid relid, char state,
XLogRecPtr sublsn, bool already_locked);
extern char GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn);
extern void RemoveSubscriptionRel(Oid subid, Oid relid);
extern bool HasSubscriptionRelations(Oid subid);
extern List *GetSubscriptionRelations(Oid subid, bool not_ready);
extern void UpdateDeadTupleRetentionStatus(Oid subid, bool active);
#endif /* PG_SUBSCRIPTION_REL_H */