Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7E951475DC5 for ; Wed, 25 Sep 2002 13:12:32 -0400 (EDT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id AF534475CB4 for ; Wed, 25 Sep 2002 13:12:31 -0400 (EDT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id g8PHC3hR011494; Wed, 25 Sep 2002 13:12:03 -0400 (EDT) To: Michael Paesold Cc: pgsql-sql@postgresql.org Subject: Re: Getting current transaction id In-reply-to: <28749.1032797034@www55.gmx.net> References: <3D8F3775.B5DD079@nsd.ca> <28749.1032797034@www55.gmx.net> Comments: In-reply-to Michael Paesold message dated "Mon, 23 Sep 2002 18:03:54 +0200" Date: Wed, 25 Sep 2002 13:12:03 -0400 Message-ID: <11493.1032973923@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/317 X-Sequence-Number: 9594 Michael Paesold writes: > I just read it's possible to get the MVCC last version numbers. Is it also > possible to get the current transaction id? Well, there's the brute force way: insert a tuple in some table and look at its xmin. Offhand I don't think we provide a SQL function to read current transaction id, though it'd surely be a trivial addition. > Would it be possible to check > later if that transaction has been commited? This would be nice for a distributed > application to enforce an "exactly once" semantics for transactions (even if > there are network related errors while the server sends ack for commiting a > transaction). Again, it's not an exported operation, though you could add a SQL function that called TransactionIdDidCommit(). > And if it's possible, how long would that information be valid, i.e. when do > transaction id's get reused? That would be the tricky part. The ID would be reused after 4 billion transactions, which is long enough that you probably don't care ... but the segment of the transaction log that has the associated commit bit will be recycled as soon as the server has no internal use for it anymore, which could be as early as the next database-wide VACUUM. If you tried to call TransactionIdDidCommit() after that, you'd get the infamous "can't open pg_clog/nnnn" error. > If it's not working I will have to implement my own transactions table. That's what I'd recommend. Transaction IDs are internal to the database and are not designed for users to rely on. regards, tom lane