Re: current_timestamp wrong - Mailing list pgsql-general

From Tom Lane
Subject Re: current_timestamp wrong
Date
Msg-id 21818.998519174@sss.pgh.pa.us
Whole thread Raw
In response to current_timestamp wrong  (Peter Pilsl <pilsl@goldfisch.at>)
Responses Re: current_timestamp wrong  (Peter Pilsl <pilsl@goldfisch.at>)
List pgsql-general
Peter Pilsl <pilsl@goldfisch.at> writes:
> In a bigger perl-project I had to hunt down a bug and it turned out that on
> very rare occassions the time delivered by 'current_timestamp'
> is wrong by a noticeable amount of time. (up to hours sometimes)

> The problem occures when using the DBI-module for perl and mod_perl in
> apache and the db-handle is stored globally for hours. On the first
> call for current_timestamp after long idle-time the returned value is
> *sometimes* incorrect.

current_timestamp is defined as the time of the start of the current
transaction (this is not a bug, it's a feature).

If your program is set up to hold a transaction open while it's idle,
that could cause stale-looking values of current_timestamp when you
finally do something in the transaction.  Unfortunately I believe that
"autocommit off" mode in the DBD driver does exactly that.

This could possibly be fixed by altering the DBD driver so that after
it's issued COMMIT or ROLLBACK, it doesn't instantly send a BEGIN,
but delays sending BEGIN until it's actually asked to issue a query.
I have not looked at the code to see how hard it'd be to do that.

            regards, tom lane

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: current_timestamp wrong
Next
From: Tom Lane
Date:
Subject: Re: Error reporting when hitting shared memory limits -