I'm getting a little confused by postgresql timezones
i was checking the dates in some rows and i noticed the timezone -4 in them
but my actual timezone is -3
the government made changes to the daylight saving timezones and the tzdata files where changes
the system date was fine but postgres don't notice the change until i restarted it
i tried setting it with
set TIME ZONE LOCAL
but it sill got the bad timezone -4
select extract(epoch from now()),now();
date_part | now
------------------+------------------------------
1335240339.68894 | 2012-04-24 00:05:39.68894-04
(1 fila)
but after i restarted postgresql
# select extract(epoch from now()),now();
date_part | now
----------------+-------------------------------
1335240403.672 | 2012-04-24 01:06:43.672002-03
(1 fila)
my timezone was always
show timezone;
TimeZone
------------------
America/Santiago
(1 fila)
may i need to restart postgres every time tzdata info is changed?
According to this FAQ entry, PostgreSQL is coming with the latest tzdata database. In order to keep it up to date, one should install minor PostgreSQL releases on a regular basis.
It is also possible to have PostgreSQL compiled with system tzdata database support using the --with-system-tzdata configure option.
In both cases, running server will not monitor for changes in the tzdata databases, so you'll have to explicitly notify it via the restart.
Related
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.
I'm using Postgresql 9.6 and pgAdmin 4. Fresh install on both Windows and Mac, happens on both.
I need to store the current time and date.
None of my timestamp functions are returning times.
Time and Date work fine
SELECT CURRENT_DATE
Output: 2016-07-15
SELECT CURRENT_TIME
Output: 14:27:22.333352+01:00
SELECT CURRENT_TIMESTAMP
Output: 2016-07-15T00:00:00Z
Expected: 2016-07-15T14:27:22+01:00
SELECT now()
Output: 2016-07-15T00:00:00Z
Expected: 2016-07-15T14:27:22+01:00
What is the problem here?
set timezone TO 'GMT';
SET TIME ZONE 'UTC';
OR
You can set timezone param into pgsql/data/postgresql.conf file:
timezone = 'US/Central'
and then restart postgresql sever.
The problem is a bug in pgAdmin 4.
Timestamps are displayed incorrectly with the time set to 00:00:00Z
The data is stored correctly and the correct time can be observed using a different a different client such as psql
This issue has been resolved with newer version of pgAdmin4.
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.
prompt$ date
Mon Oct 7 17:32:24 UTC 2013
prompt$ psql -U postgres
postgres=# show timezone;
TimeZone
----------
GMT
(1 row)
postgres=# select now();
now
-------------------------------
2013-10-07 20:32:42.354384+03
(1 row)
Why is it returning it in +03 timezone format? What am I obviously missing here?
EDIT: I solved the problem, but a question still remains. Here is what happened:
I had changed the system's OS timezone, without restarting the postgres server. Previous OS timezone was indeed +03. After I restarted postgres, it worked correctly. But it is a strange situation: postgresql.conf has not any timezone explicitly defined and the client (psql) should should always output timestamps in the timezone reported by "show timezone". So there is still this unexplained question:
Why psql was reporting GMT as timezone setting but displayed timestamps in the OS new timezone. Is this expected behaviour?
This is certainly odd behavior, largely because I would have expected show timezone to show the same timezone as now() showed. My recommendation is try to reproduce the situation and then email the PostgreSQL list or file a bug report. It sounds like you might be able to cause this by changing your system timezone while PostgreSQL is running. A reload or restart might fix the problem.
I also second the notion of watching out for ALTER USER ... SET TIMEZONE, but on top of that you can also ALTER DATABASE ... SET TIMEZONE and even ALTER FUNCTION ... SET TIMEZONE
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.