Transaction start in pg_stat_activity

Started by Neil Conwayover 19 years ago7 messageshackers
Jump to latest
#1Neil Conway
neilc@samurai.com

Attached is a first revision of a patch that adds a column to
pg_stat_activity containing the time at which the backend's current
transaction began, or NULL if the backend is not inside a transaction.
This is useful for finding long-running transactions, and AFAIK this
information is not otherwise easily available from outside the backend's
session.

Naturally, this is for 8.3.

-Neil

Attachments:

txn_start_time-1.patchtext/x-patch; charset=us-ascii; name=txn_start_time-1.patchDownload+74-18
#2Simon Riggs
simon@2ndQuadrant.com
In reply to: Neil Conway (#1)
Re: Transaction start in pg_stat_activity

On Sat, 2006-11-18 at 21:44 -0500, Neil Conway wrote:

Attached is a first revision of a patch that adds a column to
pg_stat_activity containing the time at which the backend's current
transaction began, or NULL if the backend is not inside a transaction.
This is useful for finding long-running transactions, and AFAIK this
information is not otherwise easily available from outside the backend's
session.

Naturally, this is for 8.3.

Great idea. Would it be appropriate to show the time the current
snapshot was taken also/instead?

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Simon Riggs (#2)
Re: Transaction start in pg_stat_activity

"Simon Riggs" <simon@2ndquadrant.com> writes:

Great idea. Would it be appropriate to show the time the current
snapshot was taken also/instead?

There is no way we are putting a gettimeofday() call into
GetSnapshotData. I thought you were focused on performance??

regards, tom lane

#4Simon Riggs
simon@2ndQuadrant.com
In reply to: Tom Lane (#3)
Re: Transaction start in pg_stat_activity

On Mon, 2006-11-20 at 10:58 -0500, Tom Lane wrote:

"Simon Riggs" <simon@2ndquadrant.com> writes:

Great idea. Would it be appropriate to show the time the current
snapshot was taken also/instead?

There is no way we are putting a gettimeofday() call into
GetSnapshotData. I thought you were focused on performance??

LOL.

My understanding was there was already a gettimeofday() call per
statement which is displayed in pg_stat_activity. It seems relatively
straightforward to have another column which is *not* updated for each
statement when we are in SERIALIZABLE mode and CommandId > 1.

So I wasn't talking about issuing any additional gettimeofday() calls at
all. :-)

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Simon Riggs (#4)
Re: Transaction start in pg_stat_activity

"Simon Riggs" <simon@2ndquadrant.com> writes:

On Mon, 2006-11-20 at 10:58 -0500, Tom Lane wrote:

There is no way we are putting a gettimeofday() call into
GetSnapshotData. I thought you were focused on performance??

My understanding was there was already a gettimeofday() call per
statement which is displayed in pg_stat_activity. It seems relatively
straightforward to have another column which is *not* updated for each
statement when we are in SERIALIZABLE mode and CommandId > 1.

What for? The proposal already covers transaction start and statement
start, and those are the only two timestamps available (without adding
extra gettimeofday() calls). What you propose will merely repeat one of
them.

regards, tom lane

#6Simon Riggs
simon@2ndQuadrant.com
In reply to: Tom Lane (#5)
Re: Transaction start in pg_stat_activity

On Mon, 2006-11-20 at 11:32 -0500, Tom Lane wrote:

"Simon Riggs" <simon@2ndquadrant.com> writes:

On Mon, 2006-11-20 at 10:58 -0500, Tom Lane wrote:

There is no way we are putting a gettimeofday() call into
GetSnapshotData. I thought you were focused on performance??

My understanding was there was already a gettimeofday() call per
statement which is displayed in pg_stat_activity. It seems relatively
straightforward to have another column which is *not* updated for each
statement when we are in SERIALIZABLE mode and CommandId > 1.

What for? The proposal already covers transaction start and statement
start, and those are the only two timestamps available (without adding
extra gettimeofday() calls). What you propose will merely repeat one of
them.

That's true, but you don't know which one is the snapshot timestamp. To
do that we need to either:
1. record the transaction isolation level of the snapshot, then document
the rule by which one would determine the snapshot timestamp.
2. record the timestamp of the snapshot directly

Either way you need another column.

--
Simon Riggs
EnterpriseDB http://www.enterprisedb.com

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Simon Riggs (#6)
Re: Transaction start in pg_stat_activity

"Simon Riggs" <simon@2ndquadrant.com> writes:

That's true, but you don't know which one is the snapshot timestamp.

You're assuming there is such a thing as "the" unique active snapshot,
an assumption I find highly dubious. In any case, the reasons for
wanting to know which transactions are old have to do with the behavior
of VACUUM, and that only pays attention to the age of the whole
transaction not any individual snapshots. So I still don't see the
point of cluttering pg_stat_activity with yet more columns.

regards, tom lane