如何在设置中更改Postgres Docker镜像的WAL级别?

16

我正在使用postgres:11.6-alpine镜像来运行我的应用程序,并且我想在安装时将图像的wal_level设置为'logical',最好使用docker-compose。

我发现的解决方案需要您覆盖postgresql.conf文件。但是,我不想要一个完整的postgresql.conf文件来更改此设置。

有没有什么办法可以做到这一点?

2个回答

43

将您的PostgreSQL容器配置中的command部分更新如下。


services:
  postgres:
    image: postgres:11.6-alpine
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=my_db
      - POSTGRES_PASSWORD=changeme
    command:
      - "postgres"
      - "-c"
      - "wal_level=logical"

或者

    command: [ "postgres", "-c", "wal_level=logical" ]

如果您需要这种格式。

2
这似乎不再起作用了,我收到了错误信息:PostgreSQL服务器的“root”执行不被允许。必须在非特权用户ID下启动服务器,以防止可能的系统安全威胁。请参阅文档,了解如何正确启动服务器的更多信息。 - Clintm
是的,看起来 wal_level=logical 已经不存在了。但是我找不到任何关于删除它的文档资料。 - Ville
1
这个命令在我的 postgres:14.7 Docker 镜像上使用 wal_level=logical 覆盖成功。 - messanjah

2
如果你收到了类似这样的错误:"root" execution of the PostgreSQL server is not permitted. The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server.,那么说明你尝试使用 "root" 用户身份运行 PostgreSQL 服务器。为了避免可能的系统安全威胁,服务器必须在非特权用户 ID 下启动。因此,你需要首先将自己标识为 postgres 用户或者你创建的其他用户,在大多数情况下,这样就可以解决这个问题了。
su postgres

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接