mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Keep track of transaction commit timestamps
Transactions can now set their commit timestamp directly as they commit, or an external transaction commit timestamp can be fed from an outside system using the new function TransactionTreeSetCommitTsData(). This data is crash-safe, and truncated at Xid freeze point, same as pg_clog. This module is disabled by default because it causes a performance hit, but can be enabled in postgresql.conf requiring only a server restart. A new test in src/test/modules is included. Catalog version bumped due to the new subdirectory within PGDATA and a couple of new SQL functions. Authors: Álvaro Herrera and Petr Jelínek Reviewed to varying degrees by Michael Paquier, Andres Freund, Robert Haas, Amit Kapila, Fujii Masao, Jaime Casanova, Simon Riggs, Steven Singer, Peter Eisentraut
This commit is contained in:
@ -2673,6 +2673,20 @@ include_dir 'conf.d'
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="guc-track-commit-timestamp" xreflabel="track_commit_timestamp">
|
||||
<term><varname>track_commit_timestamp</varname> (<type>bool</type>)</term>
|
||||
<indexterm>
|
||||
<primary><varname>track_commit_timestamp</> configuration parameter</primary>
|
||||
</indexterm>
|
||||
<listitem>
|
||||
<para>
|
||||
Record commit time of transactions. This parameter
|
||||
can only be set in <filename>postgresql.conf</> file or on the server
|
||||
command line. The default value is <literal>off</literal>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</sect2>
|
||||
|
||||
|
@ -15938,6 +15938,45 @@ SELECT collation for ('foo' COLLATE "de_DE");
|
||||
For example <literal>10:20:10,14,15</literal> means
|
||||
<literal>xmin=10, xmax=20, xip_list=10, 14, 15</literal>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The functions shown in <xref linkend="functions-commit-timestamp">
|
||||
provide information about transactions that have been already committed.
|
||||
These functions mainly provide information about when the transactions
|
||||
were committed. They only provide useful data when
|
||||
<xref linkend="guc-track-commit-timestamp"> configuration option is enabled
|
||||
and only for transactions that were committed after it was enabled.
|
||||
</para>
|
||||
|
||||
<table id="functions-commit-timestamp">
|
||||
<title>Committed transaction information</title>
|
||||
<tgroup cols="3">
|
||||
<thead>
|
||||
<row><entry>Name</entry> <entry>Return Type</entry> <entry>Description</entry></row>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>
|
||||
<indexterm><primary>pg_xact_commit_timestamp</primary></indexterm>
|
||||
<literal><function>pg_xact_commit_timestamp(<parameter>xid</parameter>)</function></literal>
|
||||
</entry>
|
||||
<entry><type>timestamp with time zone</type></entry>
|
||||
<entry>get commit timestamp of a transaction</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry>
|
||||
<indexterm><primary>pg_last_committed_xact</primary></indexterm>
|
||||
<literal><function>pg_last_committed_xact()</function></literal>
|
||||
</entry>
|
||||
<entry><parameter>xid</> <type>xid</>, <parameter>timestamp</> <type>timestamp with time zone</></entry>
|
||||
<entry>get transaction ID and commit timestamp of latest committed transaction</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="functions-admin">
|
||||
|
@ -22,6 +22,7 @@ PostgreSQL documentation
|
||||
<refsynopsisdiv>
|
||||
<cmdsynopsis>
|
||||
<command>pg_resetxlog</command>
|
||||
<arg choice="opt"><option>-c</option> <replaceable class="parameter">xid</replaceable>,<replaceable class="parameter">xid</replaceable></arg>
|
||||
<arg choice="opt"><option>-f</option></arg>
|
||||
<arg choice="opt"><option>-n</option></arg>
|
||||
<arg choice="opt"><option>-o</option> <replaceable class="parameter">oid</replaceable></arg>
|
||||
@ -79,9 +80,12 @@ PostgreSQL documentation
|
||||
<para>
|
||||
The <option>-o</>, <option>-x</>, <option>-e</>,
|
||||
<option>-m</>, <option>-O</>,
|
||||
<option>-c</>
|
||||
and <option>-l</>
|
||||
options allow the next OID, next transaction ID, next transaction ID's
|
||||
epoch, next and oldest multitransaction ID, next multitransaction offset, and WAL
|
||||
epoch, next and oldest multitransaction ID, next multitransaction offset,
|
||||
oldest and newest transaction IDs for which the commit time can be retrieved,
|
||||
and WAL
|
||||
starting address values to be set manually. These are only needed when
|
||||
<command>pg_resetxlog</command> is unable to determine appropriate values
|
||||
by reading <filename>pg_control</>. Safe values can be determined as
|
||||
@ -128,6 +132,19 @@ PostgreSQL documentation
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
A safe value for the oldest transaction ID for which the commit time can
|
||||
be retrieved (first part of <option>-c</>) can be determined by looking
|
||||
for the numerically smallest file name in the directory
|
||||
<filename>pg_committs</> under the data directory. Conversely, a safe
|
||||
value for the newest transaction ID for which the commit time can be
|
||||
retrieved (second part of <option>-c</>) can be determined by looking for
|
||||
the numerically greatest file name in the same directory. As above, the
|
||||
file names are in hexadecimal.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
The WAL starting address (<option>-l</>) should be
|
||||
|
@ -66,6 +66,11 @@ Item
|
||||
<structname>pg_database</></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><filename>pg_commit_ts</></entry>
|
||||
<entry>Subdirectory containing transaction commit timestamp data</entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry><filename>pg_clog</></entry>
|
||||
<entry>Subdirectory containing transaction commit status data</entry>
|
||||
|
Reference in New Issue
Block a user