PG数据库日志分析

一 日志文件目录
/cosmic/postgres/pg_data/log

二 CSV日志文件内容

如上是日志文件postgresql-20.csv的部分内容。日志文件的可读性较差,可以通过下面方法将CSV日志导入到数据库的表里。
三 将CSV日志导入数据库表里
postgresql.conf参数文件里检查参数
log_destination = 'csvlog'
logging_collector = on
创建日志记录表
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_log用来保存 CSV日志数据。
导入日志信息
COPY postgres_log FROM '/cosmic/postgres/pg_data/log/postgresql-20.csv' WITH csv;四 sql语句分析
运行时间最长的sql
select cast(split_part(
PG数据库日志分析
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



