DEV Community

Devin Clark
Devin Clark

Posted on • Originally published at magistratehq.com on

Set Postgres System Timezone

By default, Postgres uses the system timezone as the default. This usually isn't what you want for a database on your local dev machine. Generally, the timezone should be UTC. The database not being in the same timezone as production will cause bugs that don't exist locally but do exist on production.

The most common answer I find when I'm searching for how to do this for the thousandth time is this:

SET TIME ZONE 'UTC';
Enter fullscreen mode Exit fullscreen mode

This works, but will not persist across restarts.

The more persistent way to accomplish this is to modify postgresql.conf. To find where the postgresql.conf file is on your system, you can run this query in psql:

SHOW config_file;
Enter fullscreen mode Exit fullscreen mode

Once you have found the location of the file, you can find this line in the file, uncomment it, and change the value to be 'UTC'.

#timezone = '(defaults to server environment setting)'
Enter fullscreen mode Exit fullscreen mode

This is what the line should look like after the change:

timezone = 'UTC'
Enter fullscreen mode Exit fullscreen mode

After making the change, we need to reload Postgres so the config change will take effect. This can be done by either running pg_ctl reload on the command line, or running SELECT pg_reload_conf(); from psql.

Top comments (0)