1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Add a txid_status function.

If your connection to the database server is lost while a COMMIT is
in progress, it may be difficult to figure out whether the COMMIT was
successful or not.  This function will tell you, provided that you
don't wait too long to ask.  It may be useful in other situations,
too.

Craig Ringer, reviewed by Simon Riggs and by me

Discussion: http://postgr.es/m/CAMsr+YHQiWNEi0daCTboS40T+V5s_+dst3PYv_8v2wNVH+Xx4g@mail.gmail.com
This commit is contained in:
Robert Haas
2017-03-24 12:00:53 -04:00
parent 42b4b0b241
commit 857ee8e391
7 changed files with 314 additions and 1 deletions

View File

@ -17523,6 +17523,10 @@ SELECT collation for ('foo' COLLATE "de_DE");
<primary>txid_visible_in_snapshot</primary>
</indexterm>
<indexterm>
<primary>txid_status</primary>
</indexterm>
<para>
The functions shown in <xref linkend="functions-txid-snapshot">
provide server transaction information in an exportable form. The main
@ -17573,6 +17577,11 @@ SELECT collation for ('foo' COLLATE "de_DE");
<entry><type>boolean</type></entry>
<entry>is transaction ID visible in snapshot? (do not use with subtransaction ids)</entry>
</row>
<row>
<entry><literal><function>txid_status(<parameter>bigint</parameter>)</function></literal></entry>
<entry><type>txid_status</type></entry>
<entry>report the status of the given xact - <literal>committed</literal>, <literal>aborted</literal>, <literal>in progress</literal>, or NULL if the txid is too old</entry>
</row>
</tbody>
</tgroup>
</table>
@ -17642,6 +17651,24 @@ SELECT collation for ('foo' COLLATE "de_DE");
<literal>xmin=10, xmax=20, xip_list=10, 14, 15</literal>.
</para>
<para>
<function>txid_status(bigint)</> reports the commit status of a recent
transaction. Applications may use it to determine whether a transaction
committed or aborted when the application and database server become
disconnected while a <literal>COMMIT</literal> is in progress.
The status of a transaction will be reported as either
<literal>in progress</>,
<literal>committed</>, or <literal>aborted</>, provided that the
transaction is recent enough that the system retains the commit status
of that transaction. If is old enough that no references to that
transaction survive in the system and the commit status information has
been discarded, this function will return NULL. Note that prepared
transactions are reported as <literal>in progress</>; applications must
check <link
linkend="view-pg-prepared-xacts"><literal>pg_prepared_xacts</></> if they
need to determine whether the txid is a prepared transaction.
</para>
<para>
The functions shown in <xref linkend="functions-commit-timestamp">
provide information about transactions that have been already committed.