Hi,
I'm trying to write a background writer, and I'm facing a problem with
timestamps. The following code is where I'm having a problem (it's just a demo
for
the problem):
BackgroundWorkerInitializeConnection("test", NULL);
while (!got_sigterm)
{
int ret;
/* Wait 1s */
ret = WaitLatch(&MyProc->procLatch,
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
1000L);
ResetLatch(&MyProc->procLatch);
/* Insert dummy for now */
StartTransactionCommand();
SPI_connect();
PushActiveSnapshot(GetTransactionSnapshot());
ret = SPI_execute("INSERT INTO log VALUES
(now(),statement_timestamp(),clock_timestamp())", false, 0);
SPI_finish();
PopActiveSnapshot();
CommitTransactionCommand();
}
\d log
Column | Type | Modifiers
---------------------+--------------------------+---------------
now | timestamp with time zone |
statement_timestamp | timestamp with time zone |
clock_timestamp | timestamp with time zone |
Here is its content. Only the clock_timestamp is right. There are missing
records at the
beginning because i truncated the table for this example.
now | statement_timestamp |
clock_timestamp
-------------------------------+-------------------------------+-------------------------------
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:52.77683+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:53.784301+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:54.834212+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:55.848497+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:56.872671+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:57.888461+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:58.912448+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:01:59.936335+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:02:00.951247+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:02:01.967937+01
2013-03-20 15:01:44.618623+01 | 2013-03-20 15:01:44.618623+01 | 2013-03-20
15:02:02.983613+01
Most of the code is copy/paste from worker_spi (I don't really understand the
PushActiveSnapshot(GetTransactionSnapshot()) and PopActiveSnapshot() but the
behaviour is the same with or without them, and they were in worker_spi).
I guess I'm doing something wrong, but I really dont't know what it is.
Should I attach the whole code ?
Regards,
Marc
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers