查看mysql日志post_查看postgresql的日志show queries log in PostgreSQL?

--------------------------------------------------

In this post, we are going to discuss how to log all executed queries for inspection later in PostgreSQL.

1. First, you have to enable logging all queries in PostgreSQL.

Please note that only those queries that are executed can be logged.

To do that, you have to config the PostgreSQL configuration file postgresql.conf.

On Debian-based systems it’s located in /etc/postgresql/9.3/main/ (replace 9.3 with your version of PostgreSQL)

On Red Hat-based systems in /var/lib/pgsql/data/.

If you still can’t find it, then just type $locate postgresql.conf in terminal, or execute the following SQL query:

SHOW config_file;

Then you need to alter these parameters inside PostgreSQL configuration file.

log_statement = 'all'

log_directory = 'pg_log'

log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'

logging_collector = on

log_min_error_statement = error

On older versions of PostgreSQL prior to 8.0, replace 'all' with 'true' for the log_statement:

log_statement = 'true'

2. Then restart the server

Run this command:

sudo /etc/init.d/postgresql restart

or this

sudo service postgresql restart

The content of all queries to the server should now appear in the log.

3. See the log

The location of the log file will depend on the configuration.

On Debian-based systems the default is /var/log/postgresql/postgresql-9.3-main.log (replace 9.3 with your version of PostgreSQL).

On Red Hat-based systems it is located in /var/lib/pgsql/data/pg_log/.

Using TablePlus, you can enable the console log via the GUI and see all the queries.

To do that, click on the console log button near the top right panel, or use the shortcut key Cmd + Shift + C.

fa956344c979d3dd58ed3f5ba344ff94.png

You can also choose to log the meta queries, data queries, or all queries.

New to TablePlus? It’s a modern, native tool with an elegant GUI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值