Ubuntu timezone changed but mongodb still prints datetime based on previous timezone - mongodb

I used following commands to change timezone in my Ubuntu 16.04 server
sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime and tzselect
After typing date I get the correct datetime.
But on mongodb when I print time of recently added document by res.ops[0]._id.getTimestamp() I still get the datetime prior to the timezone change.
I restarted mongodb and the server itself. But still no change. And I am using node.js as backend.

You need to save the time as UTC and then on the server side get the document with time and apply to it your wanted timezone. That way you decouple timezones from your data.

Related

How to get correct timezone id of current session

On my local machine have CET timezone (postgres config same), when i run request SELECT current_setting('TIMEZONE') from java i get 'GMT-1' which is incorrect. I cant use that id in java. How to get from postgresql 'GMT+1' instead?
Is there command to get ISO timezone name/id?

Database timezone not using TZ

I have a timestamp column 'submitted_on' with default as now().
I have set the heroku TZ to my zone and added a php user ini with the same timezone.
But the database is still using UTC timezone. I see this when I ran this sql:
show timezone;
Is there a fix? Or this is how heroku databases work? Also I'm using free dynos.
Setting a TZ config var only affects the Dynos environment, as the database is located on a different machine, it has no effect.
Generally speaking, you should always keep servers clocks running on UTC, store all times in UTC, and perform any timezone/locale changes in your application framework.
The parameter timezone is determined when the database cluster is created.
You can either change the value in postgresql.conf, or you can use ALTER SYSTEM as a superuser to change the value.
I don't know if Heroku allows you either of these options.

Postgres time on heroku 5 minutes ahead

It's currently 11:05 UTC. When I call "SELECT CURRENT_TIMESTAMP" on our Heroku Postgres DB it says 11:10 UTC.
How is that massive difference possible? Do we have to manually set the current time?
current_timestamp function relies on system time and returns time of the beginning of transaction (if any). in your case probably system time is not sync with ntp servers. you can check system time with command 'date'.
Heroku said the NTP client on this machine stopped working. They've restarted it and it's working again.

How to import tz data (IANA) into Postgres server

We're trying to get the timezone data updated on a Windows Postgres install without having to update the server installation.
Background: Our application is using Postgres' built in timezone information and relies on accurate data. Therefore updating Postgres is is not the solution as timezone data is changing too often.
Is there a way to import / update IANA's timezone data into Postgres?
Finally I figured it out. For anyone having similar needs:
Get yourself cygwin, and run: make TOPDIR=$HOME/tzdir install in order to get the compiled time zone data. Copy that into the share\timezone directory of your postgres install. Restart postgres and off you go!

How do you set the time in Postgres?

How do you set the time in Postgres? I've set the time zone in Postgres to Eastern Standard Time using set timezone='-5'. However, the time was 45 minutes off where it should have been. Thinking Postgres was getting the time from Linux, I set the date in Linux using date -s="24 AUG 2011 13:48" and rebooted, and yet the problem persists.
Any ideas?
Postgresql will get its time (not necessarily time zone) setting from the OS, yes.
If your Linux machine has internet access, you can install NTP to keep the time in sync. Simply setting the time locally should be persisted back to the BIOS RTC, though.