Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/custom-rmgr.sgml`
8674025461aa12a323efede6b9e0b6620d19d14752f4146800000001000007dc
<!-- doc/src/sgml/custom-rmgr.sgml -->

<sect1 id="custom-rmgr">
 <title>Custom WAL Resource Managers</title>

 <para>
  This section explains the interface between the core
  <productname>PostgreSQL</productname> system and custom WAL resource
  managers, which enable extensions to integrate directly with the <link
  linkend="wal"><acronym>WAL</acronym></link>.
 </para>
 <para>
  An extension, especially a <link linkend="tableam">Table Access
  Method</link> or <link linkend="indexam">Index Access Method</link>, may
  need to use WAL for recovery, replication, and/or <link
  linkend="logicaldecoding">Logical Decoding</link>.
 </para>
 <para>
  To create a new custom WAL resource manager, first define an
  <structname>RmgrData</structname> structure with implementations for the
  resource manager methods. Refer to
  <filename>src/backend/access/transam/README</filename> and
  <filename>src/include/access/xlog_internal.h</filename> in the
  <productname>PostgreSQL</productname> source.
<programlisting>
/*
 * Method table for resource managers.
 *
 * This struct must be kept in sync with the PG_RMGR definition in
 * rmgr.c.
 *
 * rm_identify must return a name for the record based on xl_info (without
 * reference to the rmid). For example, XLOG_BTREE_VACUUM would be named
 * "VACUUM". rm_desc can then be called to obtain additional detail for the
 * record, if available (e.g. the last block).
 *
 * rm_mask takes as input a page modified by the resource manager and masks
 * out bits that shouldn't be flagged by wal_consistency_checking.
 *
 * RmgrTable[] is indexed by RmgrId values (see rmgrlist.h). If rm_name is
 * NULL, the corresponding RmgrTable entry is considered invalid.
 */
typedef struct RmgrData
{
    const char *rm_name;
    void        (*rm_redo) (XLogReaderState *record);
    void        (*rm_desc) (StringInfo buf, XLogReaderState *record);
    const char *(*rm_identify) (uint8 info);
    void        (*rm_startup) (void);
    void        (*rm_cleanup) (void);
    void

Title: Custom WAL Resource Managers
Summary
This section explains how extensions can integrate directly with PostgreSQL's Write-Ahead Logging (WAL) system by creating custom WAL resource managers. This is particularly useful for Table Access Methods and Index Access Methods that require WAL for recovery, replication, and logical decoding. The process involves defining an RmgrData structure with implementations for the resource manager methods, as detailed in the PostgreSQL source code.