postgres -c <参数> = <值>在Docker中对Postgres 11不起作用

时间:2018-11-30 18:39:49

标签: postgresql docker configuration

我正在docker容器中运行Postgres。我想更改Postgres的默认配置,以便运行:

docker container run -d postgres -c max_connections=200 -c shared_buffers=1GB -c effective_cache_size=3GB -c maintenance_work_mem=256MB -c checkpoint_completion_target=0.7 -c wal_buffers=16MB 

但是当我连接到运行的Postgres时:

 docker exec -it container_name psql

然后是:

的结果
SHOW max_connections;

 max_connections
-----------------
 100
(1 row)

不仅仅是max_connections。所有参数均未更改。而且我不知道我在做什么问题?

更新:的结果

root=# SELECT *
root-# FROM   pg_settings
root-# WHERE  name = 'max_connections';

      name       | setting | unit |                       category                       |                     short_desc                     | extra_desc |  context   | vartype |       source       | min_val | max_val | enumvals | boot_val | reset_val |                sourcefile                | sourceline | pending_restart
-----------------+---------+------+------------------------------------------------------+----------------------------------------------------+------------+------------+---------+--------------------+---------+---------+----------+----------+-----------+------------------------------------------+------------+-----------------
 max_connections | 100     |      | Connections and Authentication / Connection Settings | Sets the maximum number of concurrent connections. |            | postmaster | integer | configuration file | 1       | 262143  |          | 100      | 100       | /var/lib/postgresql/data/postgresql.conf |         64 | f
(1 row)

2 个答案:

答案 0 :(得分:1)

是否可能连接到错误的容器?当我尝试像您一样运行psql时,我得到:

$ docker exec -it boring_hermann psql
psql: FATAL:  role "root" does not exist

...因为标准用户是root,并且无法访问容器的DB。当我以999用户的身份运行时,组999(在该映像中被列为postgres的那个),它可以正常工作:

$ docker exec -u 999:999 -it boring_hermann psql
psql (11.1 (Debian 11.1-1.pgdg90+1))
Type "help" for help.

postgres=# show max_connections;
 max_connections 
-----------------
 200
(1 row)

答案 1 :(得分:1)

如果在启动服务器时无法使其正常工作,请尝试ALTER SYSTEM

psql -c "ALTER SYSTEM SET max_connections=200; SELECT pg_reload_conf()"

这将更改postgresql.auto.conf中的设置。

更改shared_buffers,wal_buffers and max_connections需要重新启动PostgreSQL服务器,其他参数可以随时更改。