Thread: Transaction Id and status of any operation

Transaction Id and status of any operation

From
Rohit Goyal
Date:
Hi All, 

I want to know the file or function from code which can give me the transaction Id and its status. For example I want to find the details of transaction currently inserting on some specific table.

Also please tel me what function are called to check whether status of transaction has changed. For example, I would like to get notified whenever the status of any transaction changes. Please tel me the files or function for this.

Regards,
Rohit Goyal

Re: Transaction Id and status of any operation

From
Kevin Grittner
Date:
Rohit Goyal <rhtgyl.87@gmail.com> wrote:

> I want to know the file or function from code which can give me
> the transaction Id and its status. For example I want to find the
> details of transaction currently inserting on some specific
> table.

From the connection inserting the rows, these functions might help:

http://www.postgresql.org/docs/current/interactive/functions-info.html#FUNCTIONS-TXID-SNAPSHOT

If you want some other connection to figure this out, you might
want to inspect the pg_stat_activity and/or pg_locks views.

http://www.postgresql.org/docs/current/interactive/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW

http://www.postgresql.org/docs/current/interactive/view-pg-locks.html

> Also please tel me what function are called to check whether
> status of transaction has changed. For example, I would like to
> get notified whenever the status of any transaction changes.
> Please tel me the files or function for this.

Are you talking about the state and/or waiting columns in
pg_stat_activity, looking to determine when a transaction
completes, or something else?

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: Transaction Id and status of any operation

From
Merlin Moncure
Date:
On Tue, Nov 19, 2013 at 2:49 AM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
> Hi All,
>
> I want to know the file or function from code which can give me the
> transaction Id and its status. For example I want to find the details of
> transaction currently inserting on some specific table.
>
> Also please tel me what function are called to check whether status of
> transaction has changed. For example, I would like to get notified whenever
> the status of any transaction changes. Please tel me the files or function
> for this.

Generally speaking, per MVCC rules, transactions can only see other
transactions if they completed.  It is up to the application to manage
what to do when a transaction fails.

There are internal C APIs (see: transam.c) to query transaction
success through the clog system but I'm suspicious that this is the
wrong line of thinking for you.  Stepping back, what are you trying to
do?

merlin


Re: Transaction Id and status of any operation

From
Rohit Goyal
Date:


On Wed, Nov 20, 2013 at 12:51 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
On Tue, Nov 19, 2013 at 2:49 AM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
> Hi All,
>
> I want to know the file or function from code which can give me the
> transaction Id and its status. For example I want to find the details of
> transaction currently inserting on some specific table.
>
> Also please tel me what function are called to check whether status of
> transaction has changed. For example, I would like to get notified whenever
> the status of any transaction changes. Please tel me the files or function
> for this.

Generally speaking, per MVCC rules, transactions can only see other
transactions if they completed.  It is up to the application to manage
what to do when a transaction fails.

There are internal C APIs (see: transam.c) to query transaction
success through the clog system but I'm suspicious that this is the
wrong line of thinking for you.  Stepping back, what are you trying to
do?

merlin

Thanks for quick help !!!

I want to create an 2 array's which will store all each transaction Id and also it current status in 2nd array. I also want status of transaction to be update whenever any transaction change it status.


Regards,
Rohit Goyal

Re: Transaction Id and status of any operation

From
Merlin Moncure
Date:
On Wed, Nov 20, 2013 at 9:22 AM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
>
>
> On Wed, Nov 20, 2013 at 12:51 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
>>
>> On Tue, Nov 19, 2013 at 2:49 AM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
>> > Hi All,
>> >
>> > I want to know the file or function from code which can give me the
>> > transaction Id and its status. For example I want to find the details of
>> > transaction currently inserting on some specific table.
>> >
>> > Also please tel me what function are called to check whether status of
>> > transaction has changed. For example, I would like to get notified
>> > whenever
>> > the status of any transaction changes. Please tel me the files or
>> > function
>> > for this.
>>
>> Generally speaking, per MVCC rules, transactions can only see other
>> transactions if they completed.  It is up to the application to manage
>> what to do when a transaction fails.
>>
>> There are internal C APIs (see: transam.c) to query transaction
>> success through the clog system but I'm suspicious that this is the
>> wrong line of thinking for you.  Stepping back, what are you trying to
>> do?
>>
>> merlin
>
>
> Thanks for quick help !!!
>
> I want to create an 2 array's which will store all each transaction Id and
> also it current status in 2nd array. I also want status of transaction to be
> update whenever any transaction change it status.

Yes, but why do you want to do that? This is what the database is
already doing and it's a lot more complicated than you think is.


merlin


Re: Transaction Id and status of any operation

From
Rohit Goyal
Date:
Hi, 
I want to test one of my algorithm for research. For this i want to maintain my own data structure in which I want to store the current status of transaction. 

Regards,
Rohit Goyal


On Wed, Nov 20, 2013 at 4:38 PM, Merlin Moncure <mmoncure@gmail.com> wrote:
On Wed, Nov 20, 2013 at 9:22 AM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
>
>
> On Wed, Nov 20, 2013 at 12:51 AM, Merlin Moncure <mmoncure@gmail.com> wrote:
>>
>> On Tue, Nov 19, 2013 at 2:49 AM, Rohit Goyal <rhtgyl.87@gmail.com> wrote:
>> > Hi All,
>> >
>> > I want to know the file or function from code which can give me the
>> > transaction Id and its status. For example I want to find the details of
>> > transaction currently inserting on some specific table.
>> >
>> > Also please tel me what function are called to check whether status of
>> > transaction has changed. For example, I would like to get notified
>> > whenever
>> > the status of any transaction changes. Please tel me the files or
>> > function
>> > for this.
>>
>> Generally speaking, per MVCC rules, transactions can only see other
>> transactions if they completed.  It is up to the application to manage
>> what to do when a transaction fails.
>>
>> There are internal C APIs (see: transam.c) to query transaction
>> success through the clog system but I'm suspicious that this is the
>> wrong line of thinking for you.  Stepping back, what are you trying to
>> do?
>>
>> merlin
>
>
> Thanks for quick help !!!
>
> I want to create an 2 array's which will store all each transaction Id and
> also it current status in 2nd array. I also want status of transaction to be
> update whenever any transaction change it status.

Yes, but why do you want to do that? This is what the database is
already doing and it's a lot more complicated than you think is.


merlin



--
Regards,
Rohit Goyal