如何在 docker 上更改 postgreSQL 9.5 的时区?

Har*_*rry 11 docker postgresql-9.5

默认时区为 UTC。但我想把它改成 GMT+2。我试过如下。

alter database governance set timezone = 'GMT+2';
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

我该如何管理?

postgresql 版本是 9.5。它在 Docker 上运行。

谢谢!

Den*_*dov 15

对于那些使用 TZ 但没有任何反应的人

对我来说,原因是容器第一次启动时,它会将 TZ 变量存储在映射卷的 PG 配置中。将 docker compose 文件更改为另一个 TZ 值后,它保持不变并且看起来不起作用。您应该先删除 db,然后重新启动 docker-compose

2023年

如果您使用某些 IDE PG 的客户端,它可能需要有关您的时区的其他信息

是如何修复它的附加信息

在此输入图像描述


mor*_*ipo 13

您应该在 docker compose 文件中设置时区(TZ并且PGTZ是必需的):

postgres:
    image: postgres
    environment:
        TZ: 'GMT+2'
        PGTZ: 'GMT+2'
Run Code Online (Sandbox Code Playgroud)

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

  • 谢谢!也适用于“postgres:14.1”图像。 (2认同)

Ger*_*man 8

要更改图像的时区,请尝试以下操作:

docker run -it -e "TZ=GMT+2" postgres:alpine
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml

postgres:
  image: postgres:alpine
  environment: 
    - TZ=GMT+2
Run Code Online (Sandbox Code Playgroud)


小智 5

您必须按docker-compose.yml以下格式在文件中指定时区:

postgres:
    image: postgres:alpine
    environment:
        TZ: "Europe/Madrid"
Run Code Online (Sandbox Code Playgroud)