原文:https://tableplus.io/blog/2018/10/how-to-show-queries-log-in-postgresql.html

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

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.

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.


Download TablePlus here. It’s free anyway!

查看postgresql的日志show queries log in PostgreSQL?的更多相关文章

  1. 查阅日志文件:有时候报错信息只是给出了问题的表面现象,要想更深入的了解问题,必须查看相应的日志文件,而日志文件又分为系统日志文件(/var/log)和应用的日志文件,结合这两个日志文件,一般就能定位问题所在。

    作为一名合格的 Linux 运维工程师,一定要有一套清晰.明确的解决故障思路,当问题出现时,才能迅速定位.解决问题,这里给出一个处理问题的一般思路: 重视报错提示信息:每个错误的出现,都是给出错误提示 ...

  2. PostgreSQL的日志文件介绍

    PostgreSQL的日志文件 pg_log:数据库活动日志(也就是数据库的操作日志): pg_xlog:事务日志: pg_clog:事务状态日志(pg_clog是pg_xlog的辅助日志). 现在主 ...

  3. MySQL:动态开启慢查询日志(Slow Query Log)

    前言 在开发中,高效能的程序 也包括 高效能的查询,所以优化SQL也是程序员必要技能之一.要优化就必须要有慢日志记录才可以知道哪些查询慢,然后反向去修改 慢日志设置方式 写入文件 写入数据库 实践操作 ...

  4. 如何查看crontab的日志记录

    在Unix和类Unix的操作系统之中,crontab命令常用于设置周期性被执行的指令,也可以理解为设置定时任务. crontab中的定时任务有时候没有成功执行,什么原因呢?这时就需要去日志里去分析一下 ...

  5. linux查看系统的日志的一些实用操作

    last -a 把从何处登入系统的主机名称或ip地址,显示在最后一行. -d 指定记录文件.指定记录文件.将IP地址转换成主机名称. -f <记录文件> 指定记录文件. -n <显示 ...

  6. MySQL 一般查询日志(General Query Log)

    与大多数关系型数据库,日志文件是MySQL数据库的一个重要组成部分.MySQL有几种不同的日志文件,通常包括错误日志文件,二进制日志,通用日志.慢查询日志,等等. 这些日志能够帮助我们定位mysqld ...

  7. 1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题

    1新建一个存储git的文件夹,命令是: toto@toto-K45VD:~$ mkdir gitfolder 2初始化一个git仓库,命令是: toto@toto-K45VD:~$cd gitfold ...

  8. linux查看系统的日志------健康检查特性

    last https://www.cnblogs.com/anruy/articles/5541675.html                 Nginx反向代理,健康状态检测,过载保护及配置文件详 ...

  9. MySQL二进制日志(binary log)总结

    本文出处:http://www.cnblogs.com/wy123/p/7182356.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...

随机推荐

  1. C# checked和unchecked 关键字详解

    checked 和 unchecked关键字用来限定检查或者不检查数学运算溢出的:如果使用了checked发生数学运算溢出时会抛出OverflowException:如果使用了unchecked则不会 ...

  2. jira使用一:如何给项目分组、sprint并行、禁止发送消息给atlassian

    问题一:如何设置多个sprint并行? 问题二: 如何分组显示 设置泳道,并快速过滤 问题3:添加所属产品? 管理员登录Jira后台设置-问题-自定义字段找到:所属产品,进入 配置 界面在配置界面中, ...

  3. python 列表推导式 - python基础入门(16)

    截止到目前为止,python基础内容已经学习了50%左右,在学习编程过程中,我们不仅要学习python语法,同时也需要学习如何把自己代码写的更美观,效率更高. 一.什么是推导式 推导式是从一个或者多个 ...

  4. Redis SETNX实现分布式锁

    1.某进程1执行 SETNX lock 以尝试获取锁 2.由于某进程2已获得了锁,所以进程1执行 SETNX lock 返回0,即获取锁失败 3.进程1执行 GET lock 来检测锁是否已超时,如果 ...

  5. 下载GDB调试工具peda

    命令: 1.git clone https://github.com/longld/peda.git ~/peda 2.echo "source ~/peda/peda.py" & ...

  6. 十四、i2c子系统

    由于之后的触摸屏驱动分析中使用到了GPIO子系统和i2c子系统,因此在分析触摸屏驱动之前我准备把这两个子系统进行简单分析. 在读者学习本章以及后续i2c相关章节之前,最好了解i2c通信方式,可以参考: ...

  7. SAS学习笔记30 SAS各种常用随机函数

    UNIFORM(seed) 产生(0,1)区域均匀分布随机数,乘同余发生器 RANUNI(seed) 产生(0,1)区域均匀分布随机数,素数模发生器 NORMAL(seed) 产生标准正态分布随机数, ...

  8. asp.net core-4.命令行配置

    先用vs2017创建一个控制台应用程序,这里不做多的介绍. 现在命名空间中添加using Microsoft.Extensions.Configuration; 如果没有,就在依赖项—>管理Nu ...

  9. hdu 2844 多重背包的转化问题 以及这个dp状态的确定

    在杭电上测试了下 这里的状态转移方程有两个.,. 现在有价值val[1],val[2],…val[n]的n种硬币, 它们的数量分别为num[i]个. 然后给你一个m, 问你区间[1,m]内的所有数目, ...

  10. (一)Lucene简介以及索引demo

    一.百度百科 Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查 ...