How to set timezone for Postgres psql?

dfrankow picture dfrankow · Aug 2, 2012 · Viewed 55.6k times · Source

How do I set timezone for psql to something other than my default (US/Central)? Here's what I've tried so far:

$ psql
psql (9.1.4, server 9.0.4)
...

$ psql -c 'show timezone'
  TimeZone  
------------
 US/Central

$ psql --set=timezone=US/Eastern -c 'show timezone'
  TimeZone  
------------
 US/Central

$ psql --variable=timezone=US/Eastern -c 'show timezone'
  TimeZone  
------------
 US/Central

Edit: I don't want to change the server timezone, just the client.

Edit #2: I want it in non-interactive mode.

Answer

Richard Huxton picture Richard Huxton · Aug 2, 2012
psql (9.1.4)
Type "help" for help.

richardh=> show timezone;
 TimeZone 
----------
 GB
(1 row)

richardh=> set timezone='UTC';
SET
richardh=> show timezone;
 TimeZone 
----------
 UTC
(1 row)

richardh=> set timezone='US/Eastern';
SET
richardh=> show timezone;
  TimeZone  
------------
 US/Eastern
(1 row)

richardh=> set timezone='blah';
ERROR:  invalid value for parameter "TimeZone": "blah"