Postgres: Cannot set timezone

Created on 30 Apr 2019  路  2Comments  路  Source: docker-library/postgres

Here is my compose file

version: '3'

services:
  postgres:
    image: postgres:latest
    ports:
      - "5432:5432"
    volumes:
      - ./db:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=blabla
      - POSTGRES_PASSWORD=blabla
      - POSTGRES_DB=blabla
      - TZ=Asia/Jakarta

But when I login to db with pgadmin, and make a query show timezone. It still in UTC, not 'Asia/Jakarta'

How to fix this?

question

Most helpful comment

If your ./db volume isn't empty then the entrypoint doesn't run and your data doesn't get modified

It works fine with an empty database directory

$ docker run --rm -dit -e TZ=Asia/Jakarta --name postgres postgres
bab831b10045e9a215904498009d462ec7571e32a5e409385d820a68e921c1c8

$ docker exec -it postgres psql -Upostgres
psql (11.2 (Debian 11.2-1.pgdg90+1))
Type "help" for help.

postgres=# show timezone;
   TimeZone   
--------------
 Asia/Jakarta
(1 row)

All 2 comments

If your ./db volume isn't empty then the entrypoint doesn't run and your data doesn't get modified

It works fine with an empty database directory

$ docker run --rm -dit -e TZ=Asia/Jakarta --name postgres postgres
bab831b10045e9a215904498009d462ec7571e32a5e409385d820a68e921c1c8

$ docker exec -it postgres psql -Upostgres
psql (11.2 (Debian 11.2-1.pgdg90+1))
Type "help" for help.

postgres=# show timezone;
   TimeZone   
--------------
 Asia/Jakarta
(1 row)

Thanks @wglambert. It solved.

I delete my /db then run the container again. Thanks :-)

Was this page helpful?
0 / 5 - 0 ratings