Search code examples
databasepostgresqldatetime

How do I change the timezone to UTC in postgres permanently?


I have set the timezone in postgresql.conf as follows :-

- Locale and Formatting -

datestyle = 'iso, mdy'
#intervalstyle = 'postgres'
timezone = 'UTC'
#timezone_abbreviations = 'Default'

But When I do see the timezone in postgres server it defaults to 'Asia/Kolkata'. I have installed the postgres using brew package in MacOs.


Solution

  • There are many ways to set configuration variables. But most of these settings can be overruled by the client inside its transaction. (Some settings require a server restart or have other restrictions, but not timezone.)

    To make absolutely sure, some operations happen with timezone = 'UTC', you could encapsulate that in a server-side function with its own setting, overriding any user-setting. Find a code example in this related answer:

    But while that fits the wording of your question, I don't think that's what you are looking for. You probably just need to reload after changing postgresql.conf to set the default for new sessions.