如何查看已运行的查询

时间:2021-02-13 00:54:59

I have a PostgreSQL DB at my computer and I have an application that runs queries on it.

我的计算机上有一个PostgreSQL DB,我还有一个应用程序在上面运行查询。

How can I see which queries has run on my DB?

我如何查看在我的DB上运行了哪些查询?

I use a Linux computer and pgadmin.

我使用Linux电脑和pgadmin。

3 个解决方案

#1


39  

Turn on the server log:

打开服务器日志:

log_statement = all

This will log every call to the database server.

这将记录每个对数据库服务器的调用。

I would not use log_statement = all on a productive server. Produces huge log files.
The manual about logging-parameters:

我不会在生产服务器上使用log_statement = all。产生巨大的日志文件。关于日志记录参数手册:

log_statement (enum)

log_statement(枚举)

Controls which SQL statements are logged. Valid values are none (off), ddl, mod, and all (all statements). [...]

控制哪些SQL语句被记录。有效值为none (off)、ddl、mod和all (all)。[…]

Resetting the log_statement parameter requires a server reload (SIGHUP). A restart is not necessary. Read the manual on how to set parameters.

重新设置log_statement参数需要服务器重新加载(SIGHUP)。重新启动是不必要的。阅读有关如何设置参数的手册。

Don't confuse the server log with pgAdmin's log. Two different things!

不要将服务器日志与pgAdmin的日志混淆。两种不同的东西!

You can also look at the server log files in pgAdmin, if you have access to the files (may not be the case with a remote server) and set it up correctly. Have a look at: Tools -> Server status. Read more about the server status window in the manual for pgAdmin III.

您还可以查看pgAdmin中的服务器日志文件,如果您能够访问这些文件(远程服务器可能不是这样)并正确设置它。查看一下:Tools ->服务器状态。请阅读关于pgAdmin III手册中的服务器状态窗口的更多信息。

I prefer to read the server log files with vim (or an editor / reader of your choice).

我更喜欢使用vim(或者您选择的编辑器/阅读器)读取服务器日志文件。

#2


30  

PostgreSql is very advanced when related to logging techniques

与日志记录技术相关的PostgreSql非常高级

Logs are stored in Installationfolder/data/pg_log folder. While log settings are placed in postgresql.conf file.

日志存储在Installationfolder/data/pg_log文件夹中。日志设置放在postgresql中。conf文件。

Log format is usually set as stderr. But CSV log format is recommended. In order to enable CSV format change in

日志格式通常设置为stderr。但是推荐使用CSV日志格式。为了启用CSV格式的更改

  • log_destination = 'stderr,csvlog'
  • log_destination = ' stderr,csvlog '
  • logging_collector = on
  • logging_collector =对

In order to log all queries, very usefull for new installations, set min. execution time for a query

为了记录所有查询,非常有用的新安装,设置min。执行时间查询。

  • log_min_duration_statement = 0
  • log_min_duration_statement = 0

In order to view active Queries on your database, use

为了查看数据库中的主动查询,请使用。

  • SELECT * FROM pg_stat_activity
  • SELECT * FROM pg_stat_activity

To log specific queries set query type

要记录特定查询,请设置查询类型

  • log_statement = 'all' # none, ddl, mod, all
  • log_statement = 'all' # none, ddl, mod, all

This is a good link For more information on Logging queries

这是关于日志查询的更多信息的一个很好的链接

#3


3  

I found the log file at /usr/local/var/log/postgres.log on a mac installation from brew.

我在/usr/local/var/log/postgres找到了日志文件从brew登录mac安装。

#1


39  

Turn on the server log:

打开服务器日志:

log_statement = all

This will log every call to the database server.

这将记录每个对数据库服务器的调用。

I would not use log_statement = all on a productive server. Produces huge log files.
The manual about logging-parameters:

我不会在生产服务器上使用log_statement = all。产生巨大的日志文件。关于日志记录参数手册:

log_statement (enum)

log_statement(枚举)

Controls which SQL statements are logged. Valid values are none (off), ddl, mod, and all (all statements). [...]

控制哪些SQL语句被记录。有效值为none (off)、ddl、mod和all (all)。[…]

Resetting the log_statement parameter requires a server reload (SIGHUP). A restart is not necessary. Read the manual on how to set parameters.

重新设置log_statement参数需要服务器重新加载(SIGHUP)。重新启动是不必要的。阅读有关如何设置参数的手册。

Don't confuse the server log with pgAdmin's log. Two different things!

不要将服务器日志与pgAdmin的日志混淆。两种不同的东西!

You can also look at the server log files in pgAdmin, if you have access to the files (may not be the case with a remote server) and set it up correctly. Have a look at: Tools -> Server status. Read more about the server status window in the manual for pgAdmin III.

您还可以查看pgAdmin中的服务器日志文件,如果您能够访问这些文件(远程服务器可能不是这样)并正确设置它。查看一下:Tools ->服务器状态。请阅读关于pgAdmin III手册中的服务器状态窗口的更多信息。

I prefer to read the server log files with vim (or an editor / reader of your choice).

我更喜欢使用vim(或者您选择的编辑器/阅读器)读取服务器日志文件。

#2


30  

PostgreSql is very advanced when related to logging techniques

与日志记录技术相关的PostgreSql非常高级

Logs are stored in Installationfolder/data/pg_log folder. While log settings are placed in postgresql.conf file.

日志存储在Installationfolder/data/pg_log文件夹中。日志设置放在postgresql中。conf文件。

Log format is usually set as stderr. But CSV log format is recommended. In order to enable CSV format change in

日志格式通常设置为stderr。但是推荐使用CSV日志格式。为了启用CSV格式的更改

  • log_destination = 'stderr,csvlog'
  • log_destination = ' stderr,csvlog '
  • logging_collector = on
  • logging_collector =对

In order to log all queries, very usefull for new installations, set min. execution time for a query

为了记录所有查询,非常有用的新安装,设置min。执行时间查询。

  • log_min_duration_statement = 0
  • log_min_duration_statement = 0

In order to view active Queries on your database, use

为了查看数据库中的主动查询,请使用。

  • SELECT * FROM pg_stat_activity
  • SELECT * FROM pg_stat_activity

To log specific queries set query type

要记录特定查询,请设置查询类型

  • log_statement = 'all' # none, ddl, mod, all
  • log_statement = 'all' # none, ddl, mod, all

This is a good link For more information on Logging queries

这是关于日志查询的更多信息的一个很好的链接

#3


3  

I found the log file at /usr/local/var/log/postgres.log on a mac installation from brew.

我在/usr/local/var/log/postgres找到了日志文件从brew登录mac安装。