postgre安装完之后,默认情况下会包含pg_xlog(包含WAL文件的子目录)、pg_clog(事务提交日志,包含事务提交状态数据的子目录),并没有pg_log目录,需要手动创建该目录。

$PGDATA/postgresql.conf中关于log的配置参数如下

#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------# - Where to Log -#log_destination = 'stderr'             # Valid values are combinations of# stderr, csvlog, syslog, and eventlog,# depending on platform.  csvlog# requires logging_collector to be on.# This is used when logging to stderr:
#logging_collector = off                # 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 = 'pg_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.# These are relevant when logging to syslog:
#syslog_facility = 'LOCAL0'
#syslog_ident = 'postgres'
#syslog_sequence_numbers = on
#syslog_split_messages = on# This is only relevant when logging to eventlog (win32):
# (change requires restart)
#event_source = 'PostgreSQL'# - When to Log -#client_min_messages = notice           # values in order of decreasing detail:#   debug5#   debug4#   debug3#   debug2#   debug1#   log#   notice#   warning#   error#log_min_messages = warning             # values in order of decreasing detail:#   debug5#   debug4#   debug3#   debug2#   debug1#   info#   notice#   warning#   error#   log#   fatal#   panic#log_min_error_statement = error        # values in order of decreasing detail:#   debug5#   debug4#   debug3#   debug2#   debug1#   info#   notice#   warning#   error#   log#   fatal#   panic (effectively off)#log_min_duration_statement = -1        # -1 is disabled, 0 logs all statements# and their durations, > 0 logs only# statements running at least this number# of milliseconds# - What to Log -#debug_print_parse = off
#debug_print_rewritten = off
#debug_print_plan = off
#debug_pretty_print = on
#log_checkpoints = off
#log_connections = off
#log_disconnections = off
#log_duration = off
#log_error_verbosity = default          # terse, default, or verbose messages
#log_hostname = off
#log_line_prefix = ''                   # special values:#   %a = application name#   %u = user name#   %d = database name#   %r = remote host and port#   %h = remote host#   %p = process ID#   %t = timestamp without milliseconds#   %m = timestamp with milliseconds#   %n = timestamp with milliseconds (as a Unix epoch)#   %i = command tag#   %e = SQL state#   %c = session ID#   %l = session line number#   %s = session start timestamp#   %v = virtual transaction ID#   %x = transaction ID (0 if none)#   %q = stop here in non-session#        processes#   %% = '%'# e.g. '<%u%%%d> '
#log_lock_waits = off                   # log lock waits >= deadlock_timeout
#log_statement = 'none'                 # none, ddl, mod, all
#log_replication_commands = off
#log_temp_files = -1                    # log temporary files equal or larger# than the specified size in kilobytes;# -1 disables, 0 logs all temp files
log_timezone = 'Etc/GMT0'# - Process Title -#cluster_name = ''                      # added to process titles if nonempty# (change requires restart)
#update_process_title = on

<======默认情况下log相关的参数值

#log_destination = 'stderr'
#logging_collector = off
#log_directory = 'pg_log'               # directory where log files are written,
#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'        # log file name pattern,
#log_file_mode = 0600                   # creation mode for log files,
#log_truncate_on_rotation = off
#log_rotation_age = 1d                  # Automatic rotation of logfiles will
#log_rotation_size = 10MB
#log_min_messages = warning  

输出格式默认为标准错误输出,遇到的错误直接显示出来。日志收集默认是关闭的,log的目录默认是$PGDATA/pg_log(该目录刚开始是不存在的),如果产生日志格式为'postgresql-%Y-%m-%d_%H%M%S.log'

<=====创建pg_log日志文件夹(确保权限可读可写)

[postgres@qxy data]$ pwd
/spark/pgsql/data
[postgres@qxy data]$ mkdir pg_log

<======修改之后的参数如下,并重新启动postgres

log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
#log_file_mode = 0600
log_rotation_age = 1d
log_rotation_size = 100MB
log_min_messages = info[postgres@qxy data]$
[postgres@qxy data]$ pg_ctl stop -D /spark/pgsql/data -m fast    <=====关闭postgres
waiting for server to shut down.... done
server stopped
[postgres@qxy data]$ pg_ctl start -D /spark/pgsql/data           <=====重启启动postgres
server starting
[postgres@qxy data]$ LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "pg_log".     <======以后的日志将要出现在pg_log目录[postgres@qxy data]$
[postgres@qxy data]$

<======终端操作产生错误

postgres=#
postgres=#
postgres=# \d t1Table "public.t1"Column |         Type          | Modifiers
--------+-----------------------+-----------name   | character varying(31) | postgres=# insert into t1 select md5(random()::text);
ERROR:  value too long for type character varying(31)   <======md5产生的长度大于31字节
postgres=#
postgres=# 

<=====查看产生的错误文件

postgres@qxy pg_log]$
[postgres@qxy pg_log]$ ls -ltr
total 8
-rw-------. 1 postgres postgres   96 Sep 28 07:51 postgresql-2018-09-28_075114.log
-rw-------. 1 postgres postgres 1039 Sep 28 07:53 postgresql-2018-09-28_075114.csv
[postgres@qxy pg_log]$
[postgres@qxy pg_log]$ more postgresql-2018-09-28_075114.csv
2018-09-28 07:51:14.371 GMT,,,10248,,5baddd72.2808,1,,2018-09-28 07:51:14 GMT,,0,LOG,00000,"ending log output to stderr",,"Future log output will go to log d
estination ""csvlog"".",,,,,,,""
2018-09-28 07:51:14.375 GMT,,,10250,,5baddd72.280a,1,,2018-09-28 07:51:14 GMT,,0,LOG,00000,"database system was shut down at 2018-09-28 07:51:01 GMT",,,,,,,,
,""
2018-09-28 07:51:14.378 GMT,,,10250,,5baddd72.280a,2,,2018-09-28 07:51:14 GMT,,0,LOG,00000,"MultiXact member wraparound protections are now enabled",,,,,,,,,
""
2018-09-28 07:51:14.380 GMT,,,10248,,5baddd72.2808,2,,2018-09-28 07:51:14 GMT,,0,LOG,00000,"database system is ready to accept connections",,,,,,,,,""
2018-09-28 07:51:14.381 GMT,,,10254,,5baddd72.280e,1,,2018-09-28 07:51:14 GMT,,0,LOG,00000,"autovacuum launcher started",,,,,,,,,""
2018-09-28 07:53:20.343 GMT,"postgres","postgres",10270,"[local]",5badddc1.281e,1,"INSERT",2018-09-28 07:52:33 GMT,2/19,0,ERROR,22001,"value too long for typ
e character varying(31)",,,,,,"insert into t1 select md5(random()::text);",,,"psql.bin"
[postgres@qxy pg_log]$
[postgres@qxy pg_log]$ 

<=====错误文件插入表中(格式化日志内容)

CREATE TABLE postgres_log
(log_time timestamp(3) with time zone,user_name text,database_name text,process_id integer,connection_from text,session_id text,session_line_num bigint,command_tag text,session_start_time timestamp with time zone,virtual_transaction_id text,transaction_id bigint,error_severity text,sql_state_code text,message text,detail text,hint text,internal_query text,internal_query_pos integer,context text,query text,query_pos integer,location text,application_name text,PRIMARY KEY (session_id, session_line_num)
);postgres=# CREATE TABLE postgres_log
postgres-# (
postgres(#   log_time timestamp(3) with time zone,
postgres(#   user_name text,
postgres(#   database_name text,
postgres(#   process_id integer,
postgres(#   connection_from text,
postgres(#   session_id text,
postgres(#   session_line_num bigint,
postgres(#   command_tag text,
postgres(#   session_start_time timestamp with time zone,
postgres(#   virtual_transaction_id text,
postgres(#   transaction_id bigint,
postgres(#   error_severity text,
postgres(#   sql_state_code text,
postgres(#   message text,
postgres(#   detail text,
postgres(#   hint text,
postgres(#   internal_query text,
postgres(#   internal_query_pos integer,
postgres(#   context text,
postgres(#   query text,
postgres(#   query_pos integer,
postgres(#   location text,
postgres(#   application_name text,
postgres(#   PRIMARY KEY (session_id, session_line_num)
postgres(# );
CREATE TABLE
postgres=#
postgres=#
postgres=# copy postgres_log from '/spark/pgsql/data/pg_log/postgresql-2018-09-28_075114.csv' with csv;
COPY 6
postgres=# 

<=====查询产生的错误

postgres=# select log_time,database_name,user_name,application_name,message from postgres_log;log_time          | database_name | user_name | application_name |                         message
----------------------------+---------------+-----------+------------------+----------------------------------------------------------2018-09-28 07:51:14.371+00 |               |           |                  | ending log output to stderr2018-09-28 07:51:14.375+00 |               |           |                  | database system was shut down at 2018-09-28 07:51:01 GMT2018-09-28 07:51:14.378+00 |               |           |                  | MultiXact member wraparound protections are now enabled2018-09-28 07:51:14.38+00  |               |           |                  | database system is ready to accept connections2018-09-28 07:51:14.381+00 |               |           |                  | autovacuum launcher started2018-09-28 07:53:20.343+00 | postgres      | postgres  | psql.bin         | value too long for type character varying(31)(6 rows)postgres=# 

postgres日志配置方式相关推荐

  1. SpringBoot集成logback彩色日志配置以及banner启动设置(炫酷到爆炸!)

    文章目录 前言 一.banner配置 1.1 banner图像在线生成工具 1.2 banner配置颜色 1.3 banner启动状态控制 二.logback彩色日志配置 2.1 引入依赖 2.2 l ...

  2. F5 HSL高速日志配置(GTMLTM)

    DNS HSL 高速日志配置方式: 首先在GSLB上创建一个pool  名字为pool-syslog 2.在GSLB里面iruels 创建一个irules 名字任意 3.在wide ip 上调用sys ...

  3. 项目构建之springboot集成lomback.xml,和log4j基于properties方式的日志配置记录

    文章目录 springboot集成lomback.xml 描述 在yml中定义的一些配置信息 创建logback-spring.xml文件 logback-spring.xml配置如下: **log4 ...

  4. 关于@Slf4j日志的输出配置方式

    最近项目要求,将日志输出到指定位置,方便以后查看,因为使用了lombok这个jar包,就用了lombok所带的日志功能,具体lombok的配置方式请自行百度配置,本人使用的是Springboot架构, ...

  5. python中logging(日志)配置三种方式

    超详细日志文档 python中,logging由logger.handler.filter.formater四个部分组成: logger(记录器):提供我们记录日志的方法: handler(处理器): ...

  6. postgres远程连接方式配置

    连接远端postgres时需要指定IP地址,默认安装的postgres数据库配置只监控本地地址(localhost),其他主机是无法访问的, 这里通过一个简单的例介绍远程主机连接方式. 环境如下: 主 ...

  7. qt能使用logback_Spring boot使用logback实现日志配置

    欢迎关注头条号:老顾聊技术 精品原创技术分享,知识的组装工 目录 前言 常用日志组件 什么是日志门面和日志实现 常见的日志框架 日志使用 @slf4j注解 日志的配置 logback-spring配置 ...

  8. django 完整日志配置

    django 完整日志配置 django中的log需要在settings.py中配置 import timecur_path = os.path.dirname(os.path.realpath(__ ...

  9. Spring Boot 添加拦截器的配置方式

    在进行 Java Web 开发的时候我们经常会使用到过滤器,例如日志的记录.权限的验证等功能.以前使用 Spring MVC 的时候需要在 web.xml 中配置过滤器,现在使用 Spring Boo ...

最新文章

  1. 人工智能3d建模算法_打破国外垄断,全国产3D芯片为机器人“点睛”
  2. Elasticsearch-03 CentOS7 / Windows上部署Elasticsearch5.6.16集群模式
  3. WordPress 自定义插件初始化及卸载
  4. OOP接口与抽象类的区别
  5. Microsoft SQL Server 全角转半角函数
  6. java英文单词单复数转换
  7. POJ 1797 Heavy Transportation
  8. Java中对象池的本质是什么?(实战分析版)
  9. 小米回应暴力裁员;报告称安卓手机贬值速度是 iPhone 两倍;Ant Design 4.0.1 发布| 极客头条...
  10. centos 利用yum更新git
  11. rr与hr_rr指标:HR和RR的区别
  12. 基于stm32单片机外文文献_单片机STM32外文文献翻译、中英文翻译
  13. PPT精品教程隐私政策
  14. 入侵检测系统建设及常见入侵手法应对
  15. 测试9年,面试华为要薪1万,华为员工:公司没这么低工资的岗
  16. 5000元组装电脑配置清单2021 5000元台式电脑组装配置单
  17. FTL算法分析(1)
  18. OJ每日一练——细菌个数
  19. js数组操作大全(pop,push,unshift,splice,shift方法)
  20. 这4个文档排版方式掌握了,工作效率提高的不止一点点!

热门文章

  1. 关于职场的十部经典电影——值得珍藏
  2. 2018-1-29 数据库基础
  3. 电脑常见问题及及解决方法
  4. Day4 基于DrawerLayout的菜单栏设计
  5. 【英语思维导图制作】万彩脑图大师教程 | 插入表情
  6. CF821 A. Consecutive Sum
  7. 微信小程序自定义倒计时组件及注意事项
  8. UserWarning: Glyph 8722 (\N{MINUS SIGN}) missing from current font. plt.show()
  9. Linux 上 postgresql 数据库迁移到 KingbaseES V8R6数据库
  10. 华为鸿蒙2.0智慧屏,官宣!华为车载智慧屏将于10月30日发布,或搭载鸿蒙OS 2.0...