<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Two-Phase Commit on Postgres Scripts</title><link>https://www.postgresscripts.com/tags/two-phase-commit/</link><description>Recent content in Two-Phase Commit on Postgres Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>PostgresScripts.com</copyright><lastBuildDate>Fri, 19 Jun 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.postgresscripts.com/tags/two-phase-commit/index.xml" rel="self" type="application/rss+xml"/><item><title>Track Two-Phase Commit State with pg_prepared_xacts</title><link>https://www.postgresscripts.com/post/track-two-phase-commit-state-with-pg-prepared-xacts/</link><pubDate>Fri, 19 Jun 2026 00:00:00 +0000</pubDate><guid>https://www.postgresscripts.com/post/track-two-phase-commit-state-with-pg-prepared-xacts/</guid><description>
&lt;h2 id="track-two-phase-commit-state-with-pg_prepared_xacts"&gt;Track Two-Phase Commit State with pg_prepared_xacts&lt;/h2&gt;
&lt;p&gt;A prepared transaction that never gets committed or rolled back is one of the quieter ways a PostgreSQL database degrades. It keeps holding locks, it pins the transaction-ID horizon so &lt;code&gt;VACUUM&lt;/code&gt; cannot reclaim dead rows, and nothing in normal monitoring screams about it. Left long enough it can drive the cluster toward a transaction-ID wraparound shutdown.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="7945792173"
data-ad-format="auto"
data-full-width-responsive="true"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Two-phase commit (2PC) splits a commit into two steps so an external coordinator can commit the same logical transaction across several resources atomically. In PostgreSQL the first step is &lt;code&gt;PREPARE TRANSACTION 'gid'&lt;/code&gt;, which writes the transaction's state to disk and assigns it a global identifier. The transaction is now durable but undecided: it survives a server restart and waits for a later &lt;code&gt;COMMIT PREPARED 'gid'&lt;/code&gt; or &lt;code&gt;ROLLBACK PREPARED 'gid'&lt;/code&gt;, possibly from a different session.&lt;/p&gt;</description></item></channel></rss>