xact_start meaning when dealing with procedures?

Started by hubert depesz lubaczewskiover 7 years ago6 messages

Hi
I just noticed that when I called a procedure that commits and rollbacks
- the xact_start in pg_stat_activity is not updated. Is it intentional?

I'm on newest 12devel, built today.

Best regards,

depesz

#2Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: hubert depesz lubaczewski (#1)
Re: xact_start meaning when dealing with procedures?

On 09/08/2018 19:57, hubert depesz lubaczewski wrote:

I just noticed that when I called a procedure that commits and rollbacks
- the xact_start in pg_stat_activity is not updated. Is it intentional?

It's an artifact of the way this is computed. The reported transaction
timestamp is the timestamp of the first top-level statement of the
transaction. This assumes that transactions contain statements, not the
other way around, like it is now possible. I'm not sure what an
appropriate improvement would be here.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#3Vik Fearing
vik.fearing@2ndquadrant.com
In reply to: Peter Eisentraut (#2)
Re: xact_start meaning when dealing with procedures?

On 09/08/18 20:13, Peter Eisentraut wrote:

On 09/08/2018 19:57, hubert depesz lubaczewski wrote:

I just noticed that when I called a procedure that commits and rollbacks
- the xact_start in pg_stat_activity is not updated. Is it intentional?

It's an artifact of the way this is computed. The reported transaction
timestamp is the timestamp of the first top-level statement of the
transaction. This assumes that transactions contain statements, not the
other way around, like it is now possible. I'm not sure what an
appropriate improvement would be here.

That would just mean that query_start would be older than xact_start,
but that's okay because the displayed query would be a CALL so we'll
know what's going on.
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

#4Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Vik Fearing (#3)
Re: xact_start meaning when dealing with procedures?

On 09/08/2018 20:25, Vik Fearing wrote:

On 09/08/18 20:13, Peter Eisentraut wrote:

On 09/08/2018 19:57, hubert depesz lubaczewski wrote:

I just noticed that when I called a procedure that commits and rollbacks
- the xact_start in pg_stat_activity is not updated. Is it intentional?

It's an artifact of the way this is computed. The reported transaction
timestamp is the timestamp of the first top-level statement of the
transaction. This assumes that transactions contain statements, not the
other way around, like it is now possible. I'm not sure what an
appropriate improvement would be here.

That would just mean that query_start would be older than xact_start,
but that's okay because the displayed query would be a CALL so we'll
know what's going on.

Note that this issue already exists for other commands that start
transactions internally, such as VACUUM and CREATE INDEX CONCURRENTLY.
At the moment, one should interpret xact_start as referring to the
top-level transaction only.

In practice, I think the value of xact_start versus query_start is to
anayze idle transactions. This doesn't happen with internal
transactions, so it's not a big deal in practice.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#5Jonathan S. Katz
jkatz@postgresql.org
In reply to: Peter Eisentraut (#4)
Re: xact_start meaning when dealing with procedures?

On Aug 10, 2018, at 4:39 AM, Peter Eisentraut <peter.eisentraut@2ndquadrant.com> wrote:

On 09/08/2018 20:25, Vik Fearing wrote:

On 09/08/18 20:13, Peter Eisentraut wrote:

On 09/08/2018 19:57, hubert depesz lubaczewski wrote:

I just noticed that when I called a procedure that commits and rollbacks
- the xact_start in pg_stat_activity is not updated. Is it intentional?

It's an artifact of the way this is computed. The reported transaction
timestamp is the timestamp of the first top-level statement of the
transaction. This assumes that transactions contain statements, not the
other way around, like it is now possible. I'm not sure what an
appropriate improvement would be here.

That would just mean that query_start would be older than xact_start,
but that's okay because the displayed query would be a CALL so we'll
know what's going on.

Note that this issue already exists for other commands that start
transactions internally, such as VACUUM and CREATE INDEX CONCURRENTLY.
At the moment, one should interpret xact_start as referring to the
top-level transaction only.

In practice, I think the value of xact_start versus query_start is to
anayze idle transactions. This doesn't happen with internal
transactions, so it's not a big deal in practice.

This was added as an open item by Michael[1]/messages/by-id/20180810164653.GN13638@paquier.xyz </messages/by-id/20180810164653.GN13638@paquier.xyz&gt;. When the RMT discussed,
we were able to make arguments both ways (i.e. adjusting the behavior vs.
not).

Peter, from your analysis it sounds like we should leave it, but I wanted to
confirm before removing the open item.

Thanks,

Jonathan

[1]: /messages/by-id/20180810164653.GN13638@paquier.xyz </messages/by-id/20180810164653.GN13638@paquier.xyz&gt;

#6Michael Paquier
michael@paquier.xyz
In reply to: Jonathan S. Katz (#5)
Re: xact_start meaning when dealing with procedures?

On Wed, Aug 15, 2018 at 06:23:40PM -0400, Jonathan S. Katz wrote:

This was added as an open item by Michael[1]. When the RMT discussed,
we were able to make arguments both ways (i.e. adjusting the behavior vs.
not).

Peter, from your analysis it sounds like we should leave it, but I wanted to
confirm before removing the open item.

FWIW, I am fine to stick with Peter's judgement. I added it as an open
item to actually have the discussion as I was not sure about the
intention with the feature.
--
Michael