Using CSV-Format Log Output
Including csvlog in the log_destination list provides a convenient way to import log files into a database table. This option emits log lines in comma-separated-values (CSV) format, with these columns: time stamp with milliseconds, user name, database name, process ID, client host:port number, session ID, per-session line number, command tag, session start time, virtual transaction ID, regular transaction ID, error severity, SQLSTATE code, error message, error message detail, hint, internal query that led to the error (if any), character count of the error position therein, error context, user query that led to the error (if any and enabled by log_min_error_statement), character count of the error position therein, location of the error in the PostgreSQL source code (if log_error_verbosity is set to verbose), and application name. Here is a sample table definition for storing CSV-format log output:
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)
);
To import a log file into this table, use the COPY FROM command:
COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
There are a few things you need to do to simplify importing CSV log files:
Set log_filename and log_rotation_age to provide a consistent, predictable naming scheme for your log files. This lets you predict what the file name will be and know when an individual log file is complete and therefore ready to be imported.
Set log_rotation_size to 0 to disable size-based log rotation, as it makes the log file name difficult to predict.
Set log_truncate_on_rotation to on so that old log data isn't mixed with the new in the same file.
The table definition above includes a primary key specification. This is useful to protect against accidentally importing the same information twice. The COPY command commits all of the data it imports at one time, so any error will cause the entire import to fail. If you import a partial log file and later import the file again when it is complete, the primary key violation will cause the import to fail. Wait until the log is complete and closed before importing. This procedure will also protect against accidentally importing a partial line that hasn't been completely written, which would also cause COPY to fail.
logging_collector (boolean)
This parameter enables the logging collector, which is a background process that captures log messages sent to stderr and redirects them into log files. This approach is often more useful than logging to syslog, since some types of messages might not appear in syslog output. (One common example is dynamic-linker failure messages; another is error messages produced by scripts such as archive_command.) This parameter can only be set at server start.
Note: It is possible to log to stderr without using the logging collector; the log messages will just go to wherever the server's stderr is directed. However, that method is only suitable for low log volumes, since it provides no convenient way to rotate log files. Also, on some platforms not using the logging collector can result in lost or garbled log output, because multiple processes writing concurrently to the same log file can overwrite each other's output.
Note: The logging collector is designed to never lose messages. This means that in case of extremely high load, server processes could be blocked while trying to send additional log messages when the collector has fallen behind. In contrast, syslog prefers to drop messages if it cannot write them, which means it may fail to log some messages in such cases but it will not block the rest of the system.
参考:
http://www.postgresql.org/docs/current/interactive/runtime-config-logging.html
Using CSV-Format Log Output的更多相关文章
- [Javascript] Grouping and Nesting Console Log Output
Organize your log output by grouping your logs into collapsable hierarchies using console.group(). ; ...
- CSV Format
[CSV Format] The comma separated values format (CSV) has been used for exchanging and converting dat ...
- Getting console.log output with Selenium Python API bindings
持久化存储 Getting console.log output from Chrome with Selenium Python API bindings - Stack Overflow http ...
- Java log code example
Java log example Logrecord filter import java.util.logging.Filter; import java.util.logging.Level; i ...
- [转]Learn SQLite in 1 hour
转载说明: 1.原文地址:http://www.askyb.com/sqlite/learn-sqlite-in-1-hour/ 2.译文地址:http://www.oschina.net/quest ...
- Linux下script命令录制、回放和共享终端操作script -t 2> timing.log -a output.session # 开始录制
Linux下script命令录制.回放和共享终端操作 [日期:2018-09-04] 来源:cnblogs.com/f-ck-need-u 作者:骏马金龙 [字体:大 中 小] 另一篇终端会话共 ...
- mongodb-导出数据到csv文件或json文件
在mongodb的bin目录下, 有一个mongoexport, 可用于数据的导出 [wenbronk@localhost bin]$ ./mongoexport --help Usage: mong ...
- goaccess分析access.log
接上一篇,开始学习goaccess使用~ 源码安装完成后,我的goaccess的配置文件goaccess.conf位于/usr/local/etc/ /usr/local/etc/goaccess/g ...
- nodejs:csv模块解析
Nodejs最大的特点就是基于事件驱动和异步并发操作.大多数人知道nodejs是用于网络后台服务的新平台,可以很方便的提供后台服务:除了用于网络开发外,其实nodejs对于线下文件并发处理也是很方便的 ...
随机推荐
- 调用未绑定的父类方法和使用supper 函数 之间的选择.
class New_int(int): # 定义一个新的类 继承 int 类 def __add__(self,other): # 重写 + 运算符 # __add__ 就是 int 中 + 的行为 ...
- css3控制内容的可选择性
<!doctype html><html> <head> <meta charset="UTF-8"> <meta name= ...
- C语言----变量及作用域 、 指针 、 指针和数组 、 进程空间 、 字符串
1 使用程序来模拟放球.取球的问题 1.1 问题 栈是一种特殊的线性表,它的逻辑结构和线性表相同,只是其运算规则较线性表有更多的限制,故又称为运算受限的线性表. 栈的定义是限制仅在表的一端进行插入和删 ...
- 一步一步理解GB、GBDT、xgboost
GBDT和xgboost在竞赛和工业界使用都非常频繁,能有效的应用到分类.回归.排序问题,虽然使用起来不难,但是要能完整的理解还是有一点麻烦的.本文尝试一步一步梳理GB.GBDT.xgboost,它们 ...
- Debian 安装下载工具软件
Debian 安装下载工具软件 1.下载BT种子Torrent文件 Linux下载种子文件肯定不能使用迅雷了,推荐一款叫做qBittorrent的P2P下载软件,目前在Ubuntu中使用很广泛,同样D ...
- sudo: 无法解析主机:<主机名>
hostname配置出错 解决方法:进入目录 /etc/hosts编辑,命令 sudo gedit /etc/hosts 在其中加入下面行:127.0.0.1 主机名
- 在CentOS 7 上安装广告服务器 Revive Adserver
导读 Revive Adserver是一个自由开源的广告管理系统,能使出版商,广告平台和广告商在网页.应用.视频上投放并管理广告的系统.Revive Adserver以前叫做OpenX Source, ...
- SAP 增强说明
转自http://blog.csdn.net/lyb_yt/article/details/8177974 (一)什么是增强(Enhancement)? 简单地说,增强就是ERP系统中标准程序的出口, ...
- 38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221 ...
- linux下ftp常用命令
1. Linux 终端连接FTP $ ftp 10.85.3.12 Name : fxm5547 Password: ftp> 如果FTP 允许匿名用户,那么用户名要输入anonymous,密码 ...