postgres 日志在哪里?

Where are the postgres logs?

我正在使用 DBeaver 连接 postgres 数据库并希望通过 DBeaver 访问日志。

我 运行 下面的命令来查找日志目标并将 stderr 作为位置。

show log_destination ;

如何在 DB 应用程序上访问该文件?仅供参考,我想要所有日志,而不是来自 DBeaver 的日志。

在最近的 PostgreSQL 版本中,这很简单:

SELECT  pg_current_logfile();

对于旧版本,进行如下操作:

  • 验证日志收集器是否已启动:

    SHOW logging_collector;
    
    • 如果不是,日志的位置取决于 PostgreSQL 的启动方式。

    • 如果是,日志会在log_directory:

      SHOW log_directory;
      

      如果这是相对路径,则它是相对于 PostgreSQL 数据目录的。

由于日志文件位于数据库服务器上,您可能无法使用客户端工具访问它。

https://tableplus.com/blog/2018/10/how-to-show-queries-log-in-postgresql.html#:~:text=The%20location%20of%20the%20log,pgsql%2Fdata%2Fpg_log%2F%20.

在Ubuntu下/var/log/postgresql

你可以运行pg_lsclusters

> pg_lsclusters                                                                                                          
Ver Cluster Port Status Owner    Data directory              Log file
11  main    5432 online postgres /var/lib/postgresql/11/main /var/log/postgresql/postgresql-11-main.log