Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql now() returning incorrect value

Tags:

postgresql

I have two postgresql servers - one running local on my windows machine and one running on a beta linux server.

I am running this command on both (at very close to the same time):

select current_setting('TIMEZONE'), now();

Local DB result:

"US/Pacific";"2015-10-09 12:29:51.053-07"

Beta DB result:

"US/Pacific";"2015-10-09 12:23:00.121953-07"

As you can see, the timezones are the same, but the times are not- the time on the local database is correct, but the time on the beta server appears to be about 6 minutes and 51 seconds slow.

EDIT based on answers:

Also, I checked the dates and times on both operating systems and both are correct.

The selects are not a part of a big transaction. I am using pgAdmin to run just those statements. Also, I ran the timeofday() with the now() function and they returned the exact same times as the now() function calls.

Any idea how this is happening?

like image 699
jlars62 Avatar asked Apr 14 '26 03:04

jlars62


2 Answers

Are you sure you checked the current date/time on the OS in both machines? It looks like the clock on them are not "synchronized"...

Also, are you running that "select" inside "long running" transaction? "now()" function returns always the time "frozen" in the beginning of the transaction. To get running time inside a transaction, use timeofday() function.

like image 180
Christian Avatar answered Apr 17 '26 00:04

Christian


You checked the dates on both machines - but did you also check the times? The best way to keep the time in sync is using NTP across all your machines. Also if you are unsure about the transactions, you can use timeofday() to get the current system time.

SELECT timeofday();
like image 31
A. Scherbaum Avatar answered Apr 17 '26 00:04

A. Scherbaum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!