首页 > 数据库 > > 错误报告和日志-使用CSV格式写日志
以“逗号分隔值” 即CSV(Comma Separated Value)的形式发出日志。
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 ("transaction_id", session_line_num)
);
详细说明请参见表1。
字段名 | 字段含义 | 字段名 | 字段含义 |
|---|---|---|---|
log_time | 毫秒级的时间戳 | sql_state_code | SQLSTATE代码 |
user_name | 用户名 | message | 错误消息 |
database_name | 数据库名 | detail | 详细错误消息 |
process_id | 进程ID | hint | 提示 |
connection_from | 客户主机:端口号 | internal_query | 内部查询(查询那些导致错误的信息,如果有的话) |
session_id | 会话ID | internal_query_pos | 内部查询指针 |
session_line_num | 每个会话的行数 | context | 环境 |
command_tag | 命令标签 | query | 错误发生位置的字符统计 |
session_start_time | 会话开始时间 | query_pos | 错误发生位置指针 |
virtual_transaction_id | 常规事务 | location | 在GaussDB 200源代码中错误的位置(如果log_error_verbosity的值设为verbose ) |
transaction_id | 事务ID | application_name | 应用名称 |
error_state_code | ERRORSTATE代码 | - | - |
COPY postgres_log FROM '/opt/data/pg_log/logfile.csv' WITH csv;说明:
此处的日志名“logfile.csv”要换成实际生成的日志的名称。
简化输入到CSV日志文件,可以通过如下操作:
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69959250/viewspace-3145373/ ,如需转载,请注明出处,否则将追究法律责任。