统计日志数据

最近更新时间: 2025-02-18 16:02:00

  • 按照session连接及操作时间排序
  • 复制
    复制成功
select * from tbase_log order by process_id,log_time;
  • 查询错误日志
  • 复制
    复制成功
SELECT * FROM TBase_log WHERE error_severity='ERROR' limit 1;   
  • 统计session操作数统计
  • 复制
    复制成功
postgres=#  select count(1),process_id,user_name,database_name from tbase_log group by process_id,user_name,database_name order by count(1) desc limit 10;
 count | process_id | user_name | database_name 
-------+------------+-----------+---------------
  2770 |      48067 | pgxz      | postgres
    10 |      22143 | pgxz      | postgres
    10 |      28778 | pgxz      | postgres
     9 |      28367 | pgxz      | postgres
     9 |      44280 | pgxz      | postgres
     8 |      32442 | pgxz      | postgres
     7 |      17911 | pgxz      | postgres
     7 |      21865 | pgxz      | postgres
     7 |      26159 | pgxz      | postgres
     7 |      45471 | pgxz      | postgres
(10 rows)
  • 用户操作统计
  • 复制
    复制成功
postgres=#  select count(1),user_name from tbase_log group by user_name order by count(1) desc limit 10;                                                           
 count | user_name 
-------+-----------
 10790 | pgxz
  • 数据库访问次数统计
  • 复制
    复制成功
postgres=#  select count(1),database_name from tbase_log group by database_name order by count(1) desc limit 10;             
 count | database_name 
-------+---------------
 10790 | postgres
(1 row)
  • 错误信息统计
  • 复制
    复制成功
postgres=# select count(1),user_name,database_name from tbase_log where error_severity='ERROR' group by user_name,database_name order by count(1) desc limit 10;           
 count | user_name | database_name 
-------+-----------+---------------
  1390 | pgxz      | postgres
(1 row)