pg_log,數據庫日志表postgresqllog
create database logdata;
CREATE TABLE postgres_log
(
log_time timestamp(3) with time zone, --日志生成時間
user_name text, --登陸用戶名
database_name text, --數據庫名
process_id integer,
connection_from text,--登陸ip
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)
);
csv日志中對應列的解釋:
A:日志生成時間
B:登陸用戶名
C:數據庫名
E:登陸ip
L:日志級別
M:日志錯誤代碼
N:異常信息
O:異常詳細信息
T:查詢腳本
W:應用名稱
COPY postgres_log FROM 'd:\\datafile\\postgresql-2018-04-17_094948.csv' WITH csv;
將數據庫日志拷貝到表中
postgres=# create database test;
CREATE TABLE pg_log test-# ( test(# log_time timestamp(3) with time zone, test(# user_name text, test(# database_name text, test(# process_id integer, test(# connection_from text, test(# session_id text, test(# session_line_num bigint, test(# command_tag text, test(# session_start_time timestamp with time zone, test(# virtual_transaction_id text, test(# transaction_id bigint, test(# error_severity text, test(# sql_state_code text, test(# message text, test(# detail text, test(# hint text, test(# internal_query text, test(# internal_query_pos integer, test(# context text, test(# query text, test(# query_pos integer, test(# location text, test(# application_name text, test(# PRIMARY KEY (session_id, session_line_num) test(# );
logdata=# \x
Expanded display is off.
logdata=# select * from postgres_log;
log_time | user_name | database_name | process_id | connection_from | session_id | session_line_num | command_tag | session_start_time | virtual_transaction_id | transaction_id | error
_severity | sql_state_code | message | detail | hint | internal_query | internal_query_pos | context | query |
query_pos | location | application_name
----------------------------+-----------+---------------+------------+-----------------+--------------+------------------+-------------+------------------------+------------------------+----------------+------
----------+----------------+----------------------------------------------------------+--------+--------------------------------------------------------+----------------+--------------------+---------+-------+
-----------+----------+------------------
2020-08-19 09:36:35.756+08 | | | 1626 | | 5f3bbd43.65a | 1 | | 2020-08-19 09:36:35+08 | | 0 | LOG
| 00000 | ending log output to stderr | | Future log output will go to log destination "csvlog". | | | | |
| |
2020-08-19 09:36:35.761+08 | | | 1628 | | 5f3bbd43.65c | 1 | | 2020-08-19 09:36:35+08 | | 0 | LOG
| 00000 | database system was shut down at 2020-08-18 19:36:35 CST | | | | | | |
| |
2020-08-19 09:36:35.767+08 | | | 1626 | | 5f3bbd43.65a | 2 | | 2020-08-19 09:36:35+08 | | 0 | LOG
| 00000 | database system is ready to accept connections | | | | | | |
| |
(3 rows)
logdata=#