postgres查看历史sql执行记录
postgres查看历史sql执⾏记录
默认是没有⽇志记录的,需要做如下调整:
1,修改配置⽂件,f  # 该⽂件在你的data ⽂件夹下,⽐如我的:/var/lib/postgresql/data/
  调整的参数:
  修改前注意备份f
log_statement = 'all'
# This is used when logging to stderr:
恢复历史浏览记录logging_collector = on        # Enable capturing of stderr and csvlog
# into log files. Required to be on for
# csvlogs.
# (change requires restart)
# These are only used if logging_collector is on:
log_directory = 'log'            # directory where log files are written,
# can be absolute or relative to PGDATA
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'    # log file name pattern,
# can include strftime() escapes
log_file_mode = 0600            # creation mode for log files,
# begin with 0 to use octal notation
#log_truncate_on_rotation = off        # If on, an existing log file with the
# same name as the new log file will be
# truncated rather than appended to.
# But such truncation only occurs on
# time-driven rotation, not on restarts
# or size-driven rotation.  Default is
# off, meaning append to existing files
# in all cases.
#log_rotation_age = 1d            # Automatic rotation of logfiles will
# happen after that time.  0 disables.
#log_rotation_size = 10MB        # Automatic rotation of logfiles will
# happen after that much log output.
# 0 disables.
2, 重启posgres 服务,
3,在该路径下查看你的⽇志⽂件:
  /var/lib/postgresql/data/log
会得到类似如下的⽇志记录:
2020-01-0408:38:14.236 UTC [237] LOG:  statement: SELECT "ir_module_module"."id" as "id",COALESCE("ir_module_module__summary"."value", "ir_module_module"."summary") as "summary","ir_module_module"."contributors"                    (SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,summary' AND lang='zh_CN' AND value!='')
as "ir_module_module__summary" ON ("ir_module_module"."id" = "ir_module_module__summary"."res_id") LEFT JOIN
(SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,shortdesc' AND lang='zh_CN' AND value!='')
as "ir_module_module__shortdesc" ON ("ir_module_module"."id" = "ir_module_module__shortdesc"."res_id") LEFT JOIN
(SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,description' AND lang='zh_CN' AND value!='')
as "ir_module_module__description" ON ("ir_module_module"."id" = "ir_module_module__description"."res_id") WHERE "ir_module_module".id IN (254)
2020-01-0408:38:14.238 UTC [237] LOG:  statement: SELECT "ir_module_module"."id" as "id",COALESCE("ir_module_module__summary"."value", "ir_module_module"."summary") as "summary","ir_module_module"."contributors"                    (SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,summary' AND lang='zh_CN' AND value!='')
as "ir_module_module__summary" ON ("ir_module_module"."id" = "ir_module_module__summary"."res_id") LEFT JOIN
(SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,shortdesc' AND lang='zh_CN' AND value!='')
as "ir_module_module__shortdesc" ON ("ir_module_module"."id" = "ir_module_module__shortdesc"."res_id") LEFT JOIN
(SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,description' AND lang='zh_CN' AND value!='')
as "ir_module_module__description" ON ("ir_module_module"."id" = "ir_module_module__description"."res_id") WHERE "ir_module_module".id IN (28)
2020-01-0408:38:14.240 UTC [237] LOG:  statement: SELECT "ir_module_module"."id" as "id",COALESCE("ir_module_module__summary"."value", "ir_module_module"."summary") as "summary","ir_module_module"."contributors"                    (SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,summary' AND lang='zh_CN' AND value!='')
as "ir_module_module__summary" ON ("ir_module_module"."id" = "ir_module_module__summary"."res_id") LEFT JOIN
(SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,shortdesc' AND lang='zh_CN' AND value!='')
as "ir_module_module__shortdesc" ON ("ir_module_module"."id" = "ir_module_module__shortdesc"."res_id") LEFT JOIN
(SELECT res_id, value FROM "ir_translation"
WHERE type='model' AND name='dule,description' AND lang='zh_CN' AND value!='')
as "ir_module_module__description" ON ("ir_module_module"."id" = "ir_module_module__description"."res_id") WHERE "ir_module_module".id IN (264)
ps: 该postgres服务是使⽤dockers搭建的.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。