How do I get the current timezone name in Postgres 9.3? How do I get the current timezone name in Postgres 9.3? postgresql postgresql

How do I get the current timezone name in Postgres 9.3?


I don't think this is possible using PostgreSQL alone in the most general case. When you install PostgreSQL, you pick a time zone. I'm pretty sure the default is to use the operating system's timezone. That will usually be reflected in postgresql.conf as the value of the parameter "timezone". But the value ends up as "localtime". You can see this setting with the SQL statement.

show timezone;

But if you change the timezone in postgresql.conf to something like "Europe/Berlin", then show timezone; will return that value instead of "localtime".

So I think your solution will involve setting "timezone" in postgresql.conf to an explicit value rather than the default "localtime".


It seems to work fine in Postgresql 9.5:

SELECT current_setting('TIMEZONE');


This may or may not help you address your problem, OP, but to get the timezone of the current server relative to UTC (UT1, technically), do:

SELECT EXTRACT(TIMEZONE FROM now())/3600.0;

The above works by extracting the UT1-relative offset in minutes, and then converting it to hours using the factor of 3600 secs/hour.

Example:

SET SESSION timezone TO 'Asia/Kabul';SELECT EXTRACT(TIMEZONE FROM now())/3600.0;-- output: 4.5 (as of the writing of this post)

(docs).