[英]FATAL: data directory "/var/lib/postgresql/data/pgdata" has invalid permissions Docker-compose
[英]Docker-Compose postgres upgrade initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
我使用 docker-compose 安裝了 postgres 11。 我想將它升級到 12,但即使我已經刪除了容器及其卷,但容器的狀態顯示為“正在重新啟動”。
這是我的 docker-compose 文件
version: '3.5'
services:
postgres:
image: postgres:12
environment:
POSTGRES_HOST_AUTH_METHOD: "trust"
ports:
- "5432"
restart: always
volumes:
- /etc/postgresql/12/postgresql.conf:/var/lib/postgresql/data/postgresql.conf
- db_data:/var/lib/postgresql/data
volumes:
db_data:
但是它不起作用,並且日志有以下問題
2020-07-02T12:54:47.012973448Z The files belonging to this database system will be owned by user "postgres".
2020-07-02T12:54:47.013030445Z This user must also own the server process.
2020-07-02T12:54:47.013068962Z
2020-07-02T12:54:47.013222608Z The database cluster will be initialized with locale "en_US.utf8".
2020-07-02T12:54:47.013261425Z The default database encoding has accordingly been set to "UTF8".
2020-07-02T12:54:47.013281815Z The default text search configuration will be set to "english".
2020-07-02T12:54:47.013293326Z
2020-07-02T12:54:47.013303793Z Data page checksums are disabled.
2020-07-02T12:54:47.013313919Z
2020-07-02T12:54:47.013450079Z initdb: error: directory "/var/lib/postgresql/data" exists but is not empty
2020-07-02T12:54:47.013487706Z If you want to create a new database system, either remove or empty
2020-07-02T12:54:47.013501126Z the directory "/var/lib/postgresql/data" or run initdb
2020-07-02T12:54:47.013512379Z with an argument other than "/var/lib/postgresql/data".
當容器不斷重新啟動時,如何刪除或清空這個 /var/lib/postgresql/data ?
提前致謝
該卷需要是空的或一個有效的已經初始化的 postgres 數據庫,其中包含文件
PG_VERSION
以便可以跳過初始化。...如果那里有任何文件或文件夾,例如
lost+found
它可能無法初始化。 如果您想保留卷中的文件(或無法控制),您可以調整PGDATA
環境變量以指向其中的子目錄,例如-e PGDATA=/var/lib/postgresql/data/db-files/
。
所以我將PGDATA
添加到 compose 文件的environment
部分來解決這個問題(注意最后的some_name
):
services:
postgres:
image: postgres:12
environment:
PGDATA: /var/lib/postgresql/data/some_name/
我今天遇到了同樣的問題,我通過在您的情況下刪除卷 db_data 的內容來修復它
docker volume ls
docker volume inspect db_data <-- will show you the mountpoint
我去了目錄(掛載點)例如:/path/data
cp data data.backup
cd data
rm -R *
並啟動服務:
docker-compose up -d
我遇到了這個問題,因為/var/lib/postgresql/data/postgresql.conf
和/var/lib/postgresql/data
在/var/lib/postgresql/
的 docker 容器中重疊。
損壞配置的示例是:
version: "3.8"
services:
db:
image: "postgres:10"
ports:
- "5432:5432"
volumes:
- ./postgresql.conf:/var/lib/postgresql/data/postgresql.conf
- ./pg-data:/var/lib/postgresql/data
為了避免這種情況,我告訴 PostgreSQL 在/etc/postgresql.conf
中找到它的配置,這樣重疊卷就不會像這樣發生:
version: "3.8"
services:
db:
image: "postgres:10"
command: ["postgres", "-c", "config_file=/etc/postgresql.conf"]
ports:
- "5432:5432"
volumes:
- ./postgresql.conf:/etc/postgresql.conf
- ./pg-data:/var/lib/postgresql/data
這類似於pmsoltani的建議,但我移動了postgresql.conf
文件的位置,而不是數據目錄。
另一種解決方案是簡單地刪除附加到容器的卷:
docker-compose down -v
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.