Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion doc/src/sgml/config.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -10295,8 +10295,56 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
</varlistentry>

</variablelist>
</sect1>

<sect2 id="runtime-config-CSN-based-snapshot">
<title>CSN Based Snapshot</title>
<para>
By default, snapshots in <productname>PostgreSQL</productname> contains a
XID (TransactionID) that allows to identify the status of a transaction
and make arbitrary visibility calculations.
</para>

<para>
<productname>PostgreSQL</productname> also provides a CSN (Commit
Sequence Number) based machinery as an additional tool for visibility
calculations. It may be used within distributed transactions when a xid of
a local transaction can't correctly identify order of the distributed one.
</para>

<variablelist>
<varlistentry id="guc-enable-csn-snapshot" xreflabel="enable_csn_snapshot">
<term><varname>enable_csn_snapshot</varname> (<type>boolean</type>)
<indexterm>
<primary><varname>enable_csn_snapshot</varname> configuration parameter</primary>
</indexterm>
</term>
<listitem>

<para>
Enable/disable the CSN tracking for the snapshot.
</para>

<para>
<productname>PostgreSQL</productname> uses a physical clock timestamp as
a CSN, so enabling the CSN based snapshots can be useful for implementing
cross-instance snapshots and visibility of distributed transaction.
</para>

<para>
when enabled <productname>PostgreSQL</productname> creates
<filename>pg_csn</filename> directory under <envar>PGDATA</envar> to keep
the track of CSN and XID mappings.
</para>

<para>
The default value is on.
</para>
</listitem>
</varlistentry>

</variablelist>
</sect2>
</sect1>
<sect1 id="runtime-config-compatible">
<title>Version and Platform Compatibility</title>

Expand Down
1 change: 1 addition & 0 deletions src/backend/access/rmgrdesc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ include $(top_builddir)/src/Makefile.global
OBJS = \
brindesc.o \
clogdesc.o \
csnlogdesc.o \
committsdesc.o \
dbasedesc.o \
genericdesc.o \
Expand Down
95 changes: 95 additions & 0 deletions src/backend/access/rmgrdesc/csnlogdesc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*-------------------------------------------------------------------------
*
* clogdesc.c
* rmgr descriptor routines for access/transam/csn_log.c
*
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/backend/access/rmgrdesc/csnlogdesc.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"

#include "access/csn_log.h"


void
csnlog_desc(StringInfo buf, XLogReaderState *record)
{
char *rec = XLogRecGetData(record);
uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;

if (info == XLOG_CSN_ZEROPAGE)
{
int pageno;

memcpy(&pageno, XLogRecGetData(record), sizeof(int));
appendStringInfo(buf, "pageno %d", pageno);
}
else if (info == XLOG_CSN_TRUNCATE)
{
int pageno;

memcpy(&pageno, XLogRecGetData(record), sizeof(int));
appendStringInfo(buf, "pageno %d", pageno);
}
else if (info == XLOG_CSN_ASSIGNMENT)
{
CSN csn;

memcpy(&csn, XLogRecGetData(record), sizeof(CSN));
appendStringInfo(buf, "assign "INT64_FORMAT"", csn);
}
else if (info == XLOG_CSN_SETCSN)
{
xl_csn_set *xlrec = (xl_csn_set *) rec;
int nsubxids;

appendStringInfo(buf, "set "INT64_FORMAT" for: %u",
xlrec->csn,
xlrec->xtop);
nsubxids = ((XLogRecGetDataLen(record) - MinSizeOfCSNSet) /
sizeof(TransactionId));
if (nsubxids > 0)
{
int i;
TransactionId *subxids;

subxids = palloc(sizeof(TransactionId) * nsubxids);
memcpy(subxids,
XLogRecGetData(record) + MinSizeOfCSNSet,
sizeof(TransactionId) * nsubxids);
for (i = 0; i < nsubxids; i++)
appendStringInfo(buf, ", %u", subxids[i]);
pfree(subxids);
}
}
}

const char *
csnlog_identify(uint8 info)
{
const char *id = NULL;

switch (info & ~XLR_INFO_MASK)
{
case XLOG_CSN_ASSIGNMENT:
id = "ASSIGNMENT";
break;
case XLOG_CSN_SETCSN:
id = "SETCSN";
break;
case XLOG_CSN_ZEROPAGE:
id = "ZEROPAGE";
break;
case XLOG_CSN_TRUNCATE:
id = "TRUNCATE";
break;
}

return id;
}
6 changes: 4 additions & 2 deletions src/backend/access/rmgrdesc/xlogdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ xlog_desc(StringInfo buf, XLogReaderState *record)
appendStringInfo(buf, "max_connections=%d max_worker_processes=%d "
"max_wal_senders=%d max_prepared_xacts=%d "
"max_locks_per_xact=%d wal_level=%s "
"wal_log_hints=%s track_commit_timestamp=%s",
"wal_log_hints=%s track_commit_timestamp=%s "
"enable_csn_snapshot=%s",
xlrec.MaxConnections,
xlrec.max_worker_processes,
xlrec.max_wal_senders,
xlrec.max_prepared_xacts,
xlrec.max_locks_per_xact,
wal_level_str,
xlrec.wal_log_hints ? "on" : "off",
xlrec.track_commit_timestamp ? "on" : "off");
xlrec.track_commit_timestamp ? "on" : "off",
xlrec.enable_csn_snapshot ? "on" : "off");
}
else if (info == XLOG_FPW_CHANGE)
{
Expand Down
2 changes: 2 additions & 0 deletions src/backend/access/transam/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ include $(top_builddir)/src/Makefile.global
OBJS = \
clog.o \
commit_ts.o \
csn_log.o \
csn_snapshot.o \
generic_xlog.o \
multixact.o \
parallel.o \
Expand Down
Loading