原文: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!

最新文章

  1. xmpp整理笔记:环境的快速配置(附安装包)
  2. WebRequest中的工厂方法模式
  3. (JAVA版)冒泡排序
  4. 前端学习-使用JS库Leaflet.js生成世界地图并获取标注地址经纬度。
  5. jmeter,监控插件
  6. 写个自己的Xcode4插件
  7. jedis入门一
  8. setFocus一定要写在setLayout设置的后面,否则不起作用——使用setFocusPolicy为控件设置不同的焦点策略:Tab焦点,Click焦点,Wheel焦点和没有焦点
  9. Android 定义自己的学习(5)它们的定义Progressbar
  10. vs调试有时能进去后台,有时不能进去
  11. C#关于AutoResetEvent的使用介绍(用AutoResetEvent实现同步)
  12. Ubuntu14下安装svn仓库,以及权限配置
  13. Ubuntu文件中文乱码
  14. 第一课android开发之在activity间传递参数
  15. React 轮播图实现
  16. 微信小程序计算经纬距离
  17. 数据库中in和exists关键字的区别
  18. js发送邮件 不会调用客户端。
  19. c++ Stl 随笔
  20. topcoder srm 690 div1 -3

热门文章

  1. 【VS开发】Wix 安装教程
  2. 高级UI-DrawerLayout侧滑
  3. 最新 美团java校招面经 (含整理过的面试题大全)
  4. 小程序使用mpvue框架无缝接入Vant Weapp组件库
  5. JAVA_split 字符串按照 . 分割
  6. 【Python | opencv+PIL】常见操作(创建、添加帧、绘图、读取等)的效率对比及其优化
  7. MongoDB 聚合函数及排序
  8. go if 判断 完成随机分数的评级
  9. 【规律】Parentheses
  10. SpringBoot exception异常处理机制源码解析