Kas*_*hif 8 postgresql docker docker-compose
我使用 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:
Run Code Online (Sandbox Code Playgroud)
但是它不起作用并且日志有以下问题
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".
Run Code Online (Sandbox Code Playgroud)
当容器不断重新启动时,如何删除或清空此 /var/lib/postgresql/data ?
提前致谢
rjd*_*olb 18
我遇到这个问题是因为/var/lib/postgresql/data/postgresql.conf
和 的/var/lib/postgresql/data
docker 容器中的重叠/var/lib/postgresql/
。
损坏的配置的一个示例是:
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
Run Code Online (Sandbox Code Playgroud)
为了避免这种情况,我告诉 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
Run Code Online (Sandbox Code Playgroud)
这与pmsoltani 的建议类似,但我移动了文件的位置postgresql.conf
而不是数据目录。
pms*_*ani 10
该卷需要为空或一个有效的已初始化的 postgres 数据库,其中包含该文件
PG_VERSION
,以便可以跳过 init。...如果那里有任何文件或文件夹,
lost+found
它可能无法初始化。如果您想在卷中保留一些文件(或无法控制),您可以调整PGDATA
环境变量以指向其中的子目录,例如-e PGDATA=/var/lib/postgresql/data/db-files/
.
所以我添加PGDATA
到environment
撰写文件的部分来解决这个问题(注意some_name
最后):
services:
postgres:
image: postgres:12
environment:
PGDATA: /var/lib/postgresql/data/some_name/
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10450 次 |
最近记录: |