23

Default timezone is UTC. But I want to change it to GMT+2. I tried as below.

alter database governance set timezone = 'GMT+2';

But it does't work.

How can I manage it?

postgresql version is 9.5. And it run on Docker.

Thanks!

Harry
  • 1,257
  • 3
  • 14
  • 25

4 Answers4

38

You should set timezone in your docker compose file (TZ and PGTZ are required):

postgres:
    image: postgres
    environment:
        TZ: 'GMT+2'
        PGTZ: 'GMT+2'

Reference: https://github.com/docker-library/postgres/issues/137#issuecomment-217064811

mortymacs
  • 3,456
  • 3
  • 27
  • 53
14

For those who uses TZ and nothing happens

the reason for me was that for the first time when container starts it stores TZ variable in PG config in mapped volume. and after changing docker compose file to another TZ value it stays the same and looks like it doesn't work. you should remove db first and then restart docker-compose

Denis Rudov
  • 833
  • 8
  • 16
11

To change timezone of you image try this:

docker run -it -e "TZ=GMT+2" postgres:alpine

docker-compose.yml

postgres:
  image: postgres:alpine
  environment: 
    - TZ=GMT+2
German
  • 1,449
  • 12
  • 13
4

You have to specify the timezone in the docker-compose.yml file in this format:

postgres:
    image: postgres:alpine
    environment:
        TZ: "Europe/Madrid"
BhEaN
  • 71
  • 4