Re: Problem with background worker
От | Marc Cousin |
---|---|
Тема | Re: Problem with background worker |
Дата | |
Msg-id | 5149DE92.7050809@gmail.com обсуждение исходный текст |
Ответ на | Re: Problem with background worker (Alvaro Herrera <alvherre@2ndquadrant.com>) |
Ответы |
Re: Problem with background worker
Re: Problem with background worker |
Список | pgsql-hackers |
On 20/03/2013 16:33, Alvaro Herrera wrote: > Marc Cousin escribió: >> 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(); >> } > > Ah. The reason for this problem is that the statement start time (which > also sets the transaction start time, when it's the first statement) is > set by postgres.c, not the transaction-control functions in xact.c. So > you'd need to add a SetCurrentStatementStartTimestamp() call somewhere > in your loop. > Yes, that works. Thanks a lot ! Maybe this should be added to the worker_spi example ? Regards
В списке pgsql-hackers по дате отправления: