pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Retrieve the postgres transaction id
7+ messages / 4 participants
[nested] [flat]

* Retrieve the postgres transaction id
@ 2004-05-11 13:07  Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>
  0 siblings, 1 reply; 7+ messages in thread

From: Cédric Coulon @ 2004-05-11 13:07 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

Is there a way to retrieve the postgres transaction id using JDBC?

Bye,
Cédric.

-- 
Cédric Coulon                       cedric.coulon@lina.univ-nantes.fr
Atlas group, INRIA
LINA - Université de Nantes               voice: +33 (0)2 51 12 59 63
2, Rue de la Houssinière BP 92208         fax  : +33 (0)2 51 12 58 97
44322 Nantes Cedex 03 France




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Retrieve the postgres transaction id
@ 2004-05-11 14:16  Oliver Jowett <oliver@opencloud.com>
  parent: Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>
  0 siblings, 1 reply; 7+ messages in thread

From: Oliver Jowett @ 2004-05-11 14:16 UTC (permalink / raw)
  To: Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>; +Cc: pgsql-jdbc

Cédric Coulon wrote:
> Hi,
> 
> Is there a way to retrieve the postgres transaction id using JDBC?

There's no special JDBC path for doing this.

(later) A bit of experimentation yields this (I'm sure there's a better 
way):

   select transaction from pg_locks where pid = pg_backend_pid();

You should be able to run that as a normal query through JDBC.

-O



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Retrieve the postgres transaction id
@ 2004-05-11 15:07  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Tom Lane @ 2004-05-11 15:07 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>; pgsql-jdbc

Oliver Jowett <oliver@opencloud.com> writes:
> (later) A bit of experimentation yields this (I'm sure there's a better 
> way):
>    select transaction from pg_locks where pid = pg_backend_pid();

You'd need to qualify that more, since as-is it will also show rows for
other locks the transaction holds.  Possibly "where transaction is not
null" will be sufficient.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Retrieve the postgres transaction id
@ 2004-05-11 15:37  Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 7+ messages in thread

From: Cédric Coulon @ 2004-05-11 15:37 UTC (permalink / raw)
  To: pgsql-jdbc

Thx for yours helps.
But Isn't there a possibility that a backend has more than one 
transaction with locks?

Cedric.

Tom Lane wrote:

> Oliver Jowett <oliver@opencloud.com> writes:
> 
>>(later) A bit of experimentation yields this (I'm sure there's a better 
>>way):
>>   select transaction from pg_locks where pid = pg_backend_pid();
> 
> 
> You'd need to qualify that more, since as-is it will also show rows for
> other locks the transaction holds.  Possibly "where transaction is not
> null" will be sufficient.
> 
> 			regards, tom lane
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 

-- 
Cédric Coulon                       cedric.coulon@lina.univ-nantes.fr
Atlas group, INRIA
LINA - Université de Nantes               voice: +33 (0)2 51 12 59 63
2, Rue de la Houssinière BP 92208         fax  : +33 (0)2 51 12 58 97
44322 Nantes Cedex 03 France



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Retrieve the postgres transaction id
@ 2004-05-11 23:39  Oliver Jowett <oliver@opencloud.com>
  parent: Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>
  0 siblings, 2 replies; 7+ messages in thread

From: Oliver Jowett @ 2004-05-11 23:39 UTC (permalink / raw)
  To: Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>; +Cc: pgsql-jdbc

Cédric Coulon wrote:
> Thx for yours helps.
> But Isn't there a possibility that a backend has more than one 
> transaction with locks?

As I understand it, no. There is exactly one connection per backend, and 
one transaction per connection, and there is no way to change the 
transaction associated with a connection without committing/aborting the 
existing transaction.

-O



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Retrieve the postgres transaction id
@ 2004-05-12 02:33  Dave Cramer <pg@fastcrypt.com>
  parent: Oliver Jowett <oliver@opencloud.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Dave Cramer @ 2004-05-12 02:33 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: Cédric_Coulon <cedric.coulon@lina.univ-nantes.fr>; pgsql-jdbc

That won't be true soon, nested transactions are coming ...

Just a heads up.
Dave
On Tue, 2004-05-11 at 19:39, Oliver Jowett wrote:
> Cédric Coulon wrote:
> > Thx for yours helps.
> > But Isn't there a possibility that a backend has more than one 
> > transaction with locks?
> 
> As I understand it, no. There is exactly one connection per backend, and 
> one transaction per connection, and there is no way to change the 
> transaction associated with a connection without committing/aborting the 
> existing transaction.
> 
> -O
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 
> 
> 
> !DSPAM:40a167fc177361515062736!
> 
> 
-- 
Dave Cramer
519 939 0336
ICQ # 14675561




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Retrieve the postgres transaction id
@ 2004-05-12 03:23  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Oliver Jowett <oliver@opencloud.com>
  1 sibling, 0 replies; 7+ messages in thread

From: Tom Lane @ 2004-05-12 03:23 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>; pgsql-jdbc

Oliver Jowett <oliver@opencloud.com> writes:
> Cédric Coulon wrote:
>> But Isn't there a possibility that a backend has more than one 
>> transaction with locks?

> As I understand it, no. There is exactly one connection per backend, and 
> one transaction per connection,

This is true at the moment.  Alvaro is hard at work on nested
transactions, which will imply more than one active XID per connection.
It's not decided yet how that will reflect into pg_locks, but I'd expect
there will be some visible consequence...

Probably the question that should have been asked at the outset of this
thread is "why do you want to know"?  I can't offhand think of a good
reason for clients to be interested in transaction numbers --- they are
surely just an internal implementation detail.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2004-05-12 03:23 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-05-11 13:07 Retrieve the postgres transaction id Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>
2004-05-11 14:16 ` Oliver Jowett <oliver@opencloud.com>
2004-05-11 15:07   ` Tom Lane <tgl@sss.pgh.pa.us>
2004-05-11 15:37     ` Cédric Coulon <cedric.coulon@lina.univ-nantes.fr>
2004-05-11 23:39       ` Oliver Jowett <oliver@opencloud.com>
2004-05-12 02:33         ` Dave Cramer <pg@fastcrypt.com>
2004-05-12 03:23         ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox