Re: when transaction is committed in postgres

From: Samed YILDIRIM <samed(at)reddoc(dot)net>
To: abctevez <swqshapu(at)163(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: when transaction is committed in postgres
Date: 2018-03-29 11:29:50
Message-ID: 8393341522322990@web29o.yandex.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

<div>Hi Richard,</div><div> </div><div>There are more than one option you can use.</div><div> </div><div><strong>1. Two-phase commit</strong></div><div>You can prepare your transactions with unique id before commit.</div><div>- If the connection between client and postgres is lost at preparation phase (PREPARE TRANSACTION), you can control it with pg_prepared_xacts system view whether it can be committed. If you can see your transaction on the system view, you can commit the transaction (COMMIT PREPARED).</div><div>- If the connection between client and postgres is lost at commit phase of the prepared transaction, you can control it with using pg_prepared_xacts system view again :) If you can see your transaction id, it is waiting for commit. If you do not see, It is committed (of course if you don't execute ROLLBACK PREPARED command).</div><div> </div><div><a href="https://www.postgresql.org/docs/10/static/sql-prepare-transaction.html">https://www.postgresql.org/docs/10/static/sql-prepare-transaction.html</a></div><div> </div><div><strong>2.</strong> <strong>Track commit timestamp</strong></div><div>Enable it (track_commit_timestamp = on) in postgresql.conf first. In your transaction, get your transaction id by using txid_current() function. If the connection between client and postgres is lost, you can check your transaction is committed or not by using pg_xact_commit_timestamp() function. If it returns null, It your transaction is not committed. If returns a timestamp, your transaction is committed.</div><div> </div><div><div><a href="https://www.postgresql.org/docs/10/static/functions-info.html">https://www.postgresql.org/docs/10/static/functions-info.html</a></div></div><div> </div><div><strong>3.</strong> <strong>txid_status() function</strong></div><div>If you are using PostgreSQL 10, you can check your transaction status (committed, aborted or in progress) directly with transaction id.</div><div> </div><div><a href="https://www.postgresql.org/docs/10/static/functions-info.html">https://www.postgresql.org/docs/10/static/functions-info.html</a></div><div> </div><div>Best regards.</div><div>Samed YILDIRIM</div><div> </div><div> </div><div>29.03.2018, 09:59, "abctevez" &lt;swqshapu(at)163(dot)com&gt;:</div><blockquote type="cite"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial;"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial;"><div>      Hello,I read the introduction of transaction on the postgresql official website. It notes that transaction is committed when commit call.</div><div>      Suppose that , I execute begin、execute command and then commit using some postgres client such as jdbc or odbc, what happens if the postgresql server receive commit command and response commit message failure,like tcp shakehand?If it is still to be committed, the client has no way to know whether the transaction is committed successfully or not.How does postgresql handle such situation</div><div> </div><div>Thanks advances</div><div>Richard</div></div> <p><span title="neteasefooter"> </span></p></div> <p><span title="neteasefooter"> </span></p></blockquote>

Attachment Content-Type Size
unknown_filename text/html 3.1 KB

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jasmin Dizdarevic 2018-04-01 19:38:48 select unnest(), unnest()
Previous Message abctevez 2018-03-29 06:46:17 when transaction is committed in postgres