如何自定义Postgres记录级别?

发布于 01-23 09:32 字数 1101 浏览 1 评论 0 原文

我很难在Docker中配置Postgres记录级别。从记录级别,我的意思是说我的查询就像 - 从tablethatnotexist 中选择计数(*),然后在数据库驱动程序返回的输出中会告诉我,以某种方式 - 关系“ tablethatnotexist”不存在

直到这里还可以,但是在数据库中获得相同的日志只是令人讨厌。我的意思是,我知道我以这种关系来查询数据,我也得到了回应。 日志

因此,获取像 -

没有任何意义,而且仅在文件中添加了额外的日志。

我已经搜索了所有的搜索,但是我只是找不到禁用额外记录的方法,或者只是将其设置为登录关键错误,因为数据库驱动程序会处理最多的错误。

我的开发环境 -

  • 使用Docker组成。

Docker Compose Postgres 服务部分 -

postgres:
    build: ./postgresql
    container_name: postgres
    ports:
      - '127.0.0.1:5432:5432'
    volumes:
      - pg-data:/var/lib/postgresql/data

Postgresql 目录有两个文件, dockerfile init.sql Dockerfile 代码 -

FROM postgres:14-alpine

ENV POSTGRES_USER: ...
ENV POSTGRES_PASSWORD: ...
ENV POSTGRES_DB: ...

COPY *.sql /docker-entrypoint-initdb.d/

请帮助如何自定义 Postgres 仅记录关键日志。

I am having hard time in configuring the postgres logging level in Docker. From logging level, what I mean is that say my query is something like - SELECT COUNT(*) FROM tablethatnotexist then in output returned by the database driver will tell me that in a way - relation "tablethatnotexist" does not exist.

It's fine until here but getting the same log in the database sometime is just irritating. I mean that I know I queried the databse with that relation which doesn't exist and I also got a response for that. So getting a log like -

Postgres Log

doesn't makes any sense and also it just adds up extra logs in the file.

I have searched all around but I just can't found the way to disable the extra logging or just set it to log on the critical errors only since the database driver handles the most errors.

My dev environment -

  • Using docker compose.

Docker compose Postgres service section -

postgres:
    build: ./postgresql
    container_name: postgres
    ports:
      - '127.0.0.1:5432:5432'
    volumes:
      - pg-data:/var/lib/postgresql/data

postgresql directory has two files, Dockerfile and init.sql. Dockerfile code -

FROM postgres:14-alpine

ENV POSTGRES_USER: ...
ENV POSTGRES_PASSWORD: ...
ENV POSTGRES_DB: ...

COPY *.sql /docker-entrypoint-initdb.d/

Please help on how to customize postgres to only log the critical logs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那些过往 2025-01-30 09:32:14

如果使用Docker Compose,则可以将此行添加到docker-compose.yaml文件中:

command: ["postgres", "-c", "log_statement=all"]

所有查询将写入容器日志文件中。

官方文档您可以找到详细信息的详细信息

If using Docker Compose, you can add this line to your docker-compose.yaml file:

command: ["postgres", "-c", "log_statement=all"]

and all your queries will be written into the container log file.

In the official docs you can find details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文