Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change timezone of postgreSQL 9.5 on docker?

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!

like image 405
Harry Avatar asked Jun 06 '17 15:06

Harry


4 Answers

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

like image 189
Denis Rudov Avatar answered Sep 18 '22 18:09

Denis Rudov


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

like image 23
mortymacs Avatar answered Sep 22 '22 18:09

mortymacs


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
like image 31
German Avatar answered Sep 18 '22 18:09

German


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

postgres:
    image: postgres:alpine
    environment:
        TZ: "Europe/Madrid"
like image 24
BhEaN Avatar answered Sep 19 '22 18:09

BhEaN