
我已經將 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 上,它似乎不會造成問題,儘管那裡也會出現「統計檔案」警告。
謝謝。