Postgresql 减少Postgres Docker的日志输出?

Postgresql 减少Postgres Docker的日志输出?,postgresql,docker,logging,Postgresql,Docker,Logging,如果你跑 docker run --rm postgres 你会得到: The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.utf8". The default database en

如果你跑

docker run --rm postgres
你会得到:

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /var/lib/postgresql/data -l logfile start

****************************************************
WARNING: No password has been set for the database.
         This will allow anyone with access to the
         Postgres port to access your database. In
         Docker's default configuration, this is
         effectively any other container on the same
         system.

         Use "-e POSTGRES_PASSWORD=password" to set
         it in "docker run".
****************************************************
waiting for server to start....2018-06-09 06:11:42.530 UTC [39] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2018-06-09 06:11:42.543 UTC [40] LOG:  database system was shut down at 2018-06-09 06:11:42 UTC
2018-06-09 06:11:42.552 UTC [39] LOG:  database system is ready to accept connections
 done
server started
ALTER ROLE


/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

2018-06-09 06:11:42.665 UTC [39] LOG:  received fast shutdown request
waiting for server to shut down....2018-06-09 06:11:42.668 UTC [39] LOG:  aborting any active transactions
2018-06-09 06:11:42.669 UTC [39] LOG:  worker process: logical replication launcher (PID 46) exited with exit code 1
2018-06-09 06:11:42.672 UTC [41] LOG:  shutting down
2018-06-09 06:11:42.687 UTC [39] LOG:  database system is shut down
 done
server stopped

PostgreSQL init process complete; ready for start up.

2018-06-09 06:11:42.776 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2018-06-09 06:11:42.776 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2018-06-09 06:11:42.780 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2018-06-09 06:11:42.791 UTC [57] LOG:  database system was shut down at 2018-06-09 06:11:42 UTC
2018-06-09 06:11:42.800 UTC [1] LOG:  database system is ready to accept connections
63行日志记录启动信息,更不用说开始对其执行查询时的所有额外详细信息了。这是一个很好的信息,但是当你在当地的开发中不断地启动和销毁相同的容器时,这是噪音


我怎样才能“安静”这些日志?我不想完全摆脱他们。。。我仍然希望看到严重错误或严重警告。我还希望将它们定向到
stdout
stderr
,而不是单独的文件或分离的进程

理想情况下,我正在寻找一个可以配置的环境变量,但在图像文档中,我还没有找到一个。我对官方RabbitMQ映像也有类似的问题,并通过以下方式使其变得更加安静:

RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbit log [{console,[{level,warning}]}]

我正在寻找类似的官方版本。

我没有找到环境变量,但您可以使用配置文件设置日志选项

docker run -i --rm postgres:12.1 cat /usr/share/postgresql/postgresql.conf.sample > my-postgres.conf
echo "log_min_messages = error" >> my-postgres.conf
docker run --rm postgres -v "$PWD/my-postgres.conf":/etc/postgresql/postgresql.conf postgres -c 'config_file=/etc/postgresql/postgresql.conf'

我在此图像中未找到任何更改日志记录级别的标志。您可以在分离模式下运行此docker容器。docker run-d或者您可以在手动更改日志级别后在此官方映像上构建自定义映像。