gpt4 book ai didi

postgresql - 减少Postgres Docker的日志输出?

转载 作者:行者123 更新时间:2023-12-03 11:24:55 25 4
gpt4 key购买 nike

如果你跑

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条启动信息的日志行,更不用说在开始对其执行查询时的所有其他详细信息。这是很重要的信息,但是当您在本地开发中不断启动并一遍又一遍地破坏相同的容器时,这就是噪音。

我如何“安静”这些日志?我不想完全摆脱它们...我仍然想看到严重错误或严重警告。我还仍然希望它们定向到 stdoutstderr,而不是单独的文件或作为独立的进程。

理想情况下,我正在寻找可以配置的环境变量,但是在图像文档中找不到一个很幸运。我在RabbitMQ官方图片上也遇到了类似的问题,并且可以通过以下操作使其安静得多:
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbit log [{console,[{level,warning}]}]

我正在寻找官方 Postgres images可以做的类似事情。

最佳答案

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

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'

关于postgresql - 减少Postgres Docker的日志输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50771515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com