![关于将 postgres 作为 Docker 容器运行的问题。1. TimeZone,2. global.stat](https://linux22.com/image/772750/%E5%85%B3%E4%BA%8E%E5%B0%86%20postgres%20%E4%BD%9C%E4%B8%BA%20Docker%20%E5%AE%B9%E5%99%A8%E8%BF%90%E8%A1%8C%E7%9A%84%E9%97%AE%E9%A2%98%E3%80%821.%20TimeZone%EF%BC%8C2.%20global.stat.png)
我已经将 postgres 作为 Docker 容器运行了一段时间。最初,TZ 和 PGTZ 未设置,因此我认为它默认为 UTC。在我的开发系统上,我在 docker-compose.yml 中尝试了以下内容:
postgres:
image: postgres:13
ports: ["5557:5432"]
restart: unless-stopped
volumes:
- ./Index:/var/lib/postgresql/data
environment:
TZ: "America/Cayman"
PGTZ: "America/Cayman"
POSTGRES_PASSWORD: "postgres"
这似乎对本地时区进行了调整。我还没有将其部署到实时系统,因为我想知道这是否会弄乱与数据库事务历史记录和日志文件等相关的任何内容。数据库完整性现在很好,而且我有相当长的备份。我不确定是否真的有必要设置时区,但将所有容器设置为本地区域而不是 UTC 还是不错的。
另一个问题与此无关,并在这里提到: 警告:无法打开统计文件“pg_stat_tmp/global.stat”:操作不允许
简要地:
该数据库索引映射到 Docker 包根目录中的主机上的文件夹,就数据库而言,其他一切似乎都运行良好。我使用的是 Mac,但如果我从 CLI 列出 DB 文件夹的权限,我会得到:
-rw-------@ 1 sscotti staff 3 Feb 22 11:01 PG_VERSION
drwx------@ 6 sscotti staff 192 Feb 22 11:54 base
drwx------@ 60 sscotti staff 1920 Feb 22 16:00 global
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_commit_ts
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_dynshmem
-rw-------@ 1 sscotti staff 4782 Feb 22 11:02 pg_hba.conf
-rw-------@ 1 sscotti staff 1636 Feb 22 11:01 pg_ident.conf
drwx------@ 5 sscotti staff 160 Feb 22 17:46 pg_logical
drwx------@ 4 sscotti staff 128 Feb 22 11:01 pg_multixact
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_notify
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_replslot
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_serial
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_snapshots
drwx------@ 2 sscotti staff 64 Feb 22 16:00 pg_stat
drwx------@ 5 sscotti staff 160 Feb 22 17:50 pg_stat_tmp
drwx------@ 3 sscotti staff 96 Feb 22 11:01 pg_subtrans
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_tblspc
drwx------@ 2 sscotti staff 64 Feb 22 11:01 pg_twophase
drwx------@ 4 sscotti staff 128 Feb 22 11:01 pg_wal
drwx------@ 3 sscotti staff 96 Feb 22 11:01 pg_xact
-rw-------@ 1 sscotti staff 88 Feb 22 11:01 postgresql.auto.conf
-rw-------@ 1 sscotti staff 28073 Feb 22 11:01 postgresql.conf
-rw-------@ 1 sscotti staff 36 Feb 22 16:00 postmaster.opts
-rw------- 1 sscotti staff 94 Feb 22 16:00 postmaster.pid
pg_stat folder is actually empty.
and pg_stat_temp has:
-rw------- 1 sscotti staff 1952 Feb 22 17:54 db_0.stat
-rw------- 1 sscotti staff 20360 Feb 22 17:54 db_13395.stat
-rw------- 1 sscotti staff 1151 Feb 22 17:54 global.stat
问题似乎是数据库文件绑定到主机上的本地文件夹,而不是 Docker 卷。将其绑定到可从主机轻松访问的本地文件夹要方便得多,但我认为这存在一些权限问题。我可能实际上想更改为卷,但卷仍然必须是持久的,并且可以轻松备份到我们用于备份的本地 NAS 或云服务。
对于适用于 MacOS 的 Docker Desktop,使用绑定文件夹而不是卷似乎会对性能造成一些影响,但在 LINUX 上似乎不会造成问题,尽管那里也会出现“统计文件”警告。
谢谢。