首页 > 数据库 >怎样更直观的查看KingbaseES数据库日志

怎样更直观的查看KingbaseES数据库日志

时间:2023-02-28 17:56:21浏览次数:35  
标签:log text 数据库 sys TEST test 日志 KingbaseES

数据库日志相关参数:默认设置

log_destination = 'stderr'      # Valid values are combinations of
                                # stderr, csvlog, syslog, and eventlog,
                                # depending on platform.  csvlog
                                # requires logging_collector to be on.
        
logging_collector = on          # Enable capturing of stderr and csvlog
log_directory = 'sys_log'                       # directory where log files are written,
#log_filename = 'kingbase-%Y-%m-%d_%H%M%S.log'  # log file name pattern,
#log_file_mode = 0600                   # creation mode for log files,
#log_rotation_age = 1d                  # Automatic rotation of logfiles will(按时间自动轮换分割日志)
#log_rotation_size = 10MB               # Automatic rotation of logfiles will(按大小自动轮换分割日志)

其中log_destination包括stderr、csvlog和syslog,默认值是stderr格式,csvlog记录内容会比stderr更详细

—stderr时

[kingbase2@localhost sys_log]$ tail -1 kingbase-2023-01-04_000000.log
2023-01-04 14:12:56.979 CST [3037] STATEMENT:  select userid::regrole, dbid, query from sys_stat_statements order by mean_time desc limit 5;

—csvlog 时,会记录数据库、用户信息等

TEST=# alter system set log_destination ='csvlog';
ALTER SYSTEM
TEST=#
TEST=# select sys_reload_conf();
 sys_reload_conf
-----------------
 t
(1 row)

TEST=# show log_destination ;
 log_destination
-----------------
 csvlog
(1 row)

[kingbase2@localhost sys_log]$ tail -4 kingbase-2023-01-05_153654.csv
2023-01-05 15:39:13.368 CST,"system","test",4934,"[local]",63b67e91.1346,1,"idle",2023-01-05 15:38:57 CST,4/4681,0,ERROR,42601,"syntax error at or near ""switch""",,,,,,"alter system switch logfile;",14,,"kingbase_*&+_"

KingbaseES数据库日志查看方式只能到默认的sys_log目录下打开数据库日志查看,这种查看方式类似于oracle中的alert log

[kingbase2@localhost sys_log]$ cat  kingbase-2023-01-05_153654.csv |egrep error
2023-01-05 15:39:13.368 CST,"system","test",4934,"[local]",63b67e91.1346,1,"idle",2023-01-05 15:38:57 CST,4/4681,0,ERROR,42601,"syntax error at or near ""switch""",,,,,,"alter system switch logfile;",14,,"kingbase_*&+_"

但是有的时候我们会被这种显示格式困扰,不容易直观的查看。
下面介绍一种日志查看方式:

TEST=# CREATE   TABLE public.sys_log (
TEST(#      logtime timestamp with time zone,
TEST(#      loguser text,
TEST(#      logdatabase text,
TEST(#      logpid text,
TEST(#      loghost text,
TEST(#      logsessionid text,
TEST(#      logcmdcount text,
TEST(#      logcmdtag text,
TEST(#      logsessiontime timestamp with time zone,
TEST(#      logtransaction text,
TEST(#      log_level  text,
TEST(#      logseverity  text,
TEST(#      logstate text,
TEST(#      logmessage text,
TEST(#      logdetail text,
TEST(#      loghint text,
TEST(#      loginternalquery text,
TEST(#      loginternalquerypos text,
TEST(#      logcontext text,
TEST(#      logquery text,
TEST(#      logquerypos text,
TEST(#      loglocation text,
TEST(#      logapplicationname text);
CREATE TABLE
test=# copy public.sys_log from '/opt/Kingbase/ES/V8/data/sys_log/kingbase-2023-01-05_153654.csv' with csv;
COPY 1
test=# select * from public.sys_log limit 1;
TEST=# \x
Expanded display is on.
TEST=# select * from public.sys_log limit 1;
-[ RECORD 1 ]-------+---------------------------------
logtime             | 2023-01-06 05:39:13.368000+08
loguser             | system
logdatabase         | test
logpid              | 4934
loghost             | [local]
logsessionid        | 63b67e91.1346
logcmdcount         | 1
logcmdtag           | idle
logsessiontime      | 2023-01-06 05:38:57+08
logtransaction      | 4/4681
log_level           | 0
logseverity         | ERROR
logstate            | 42601
logmessage          | syntax error at or near "switch"
logdetail           |
loghint             |
loginternalquery    |
loginternalquerypos |
logcontext          |
logquery            | alter system switch logfile;
logquerypos         | 14
loglocation         |
logapplicationname  | kingbase_*&+_

注:
logtransaction 记录事务的一个位置
log_level 日志的级别
logseverity 对应FATAL, ERROR, WARN, INFO, ALL,等等,根据设置的level去记录对应的日志。
这样可以过滤出想要的内容,查看更加直观简洁,但只能每一个日志文件copy进去一张表中。

还有一种方法,可以使用file_fdw插件去直接读取数据库以外的日志文件,如下所示:

test=# create extension file_fdw;
CREATE EXTENSION
test=# \dx file_fdw;
                      List of installed extensions
   Name   | Version | Schema |                Description
----------+---------+--------+-------------------------------------------
 file_fdw | 1.0     | public | foreign-data wrapper for flat file access
(1 row)

创建外部表接口
test=# create server ser_file_fdw foreign data wrapper file_fdw;
CREATE SERVER

查看外部服务接口
test=# \des
           List of foreign servers
     Name     | Owner  | Foreign-data wrapper
--------------+--------+----------------------
 ser_file_fdw | system | file_fdw
 sysaudit_svr | system | sysaudit_fdw
(2 rows)

创建外部表查看日志
test=# CREATE foreign TABLE public.sys_log_svt (
test(# logtime timestamp with time zone,
test(# loguser text,
test(# logdatabase text,
test(# logpid text,
test(# loghost text,
test(# logsessionid text,
test(# logcmdcount text,
test(# logcmdtag text,
test(# logsessiontime timestamp with time zone,
test(# logtransaction text,
test(# log_level text,
test(# logseverity text,
test(# logstate text,
test(# logmessage text,
test(# logdetail text,
test(# loghint text,
test(# loginternalquery text,
test(# loginternalquerypos text,
test(# logcontext text,
test(# logquery text,
test(# logquerypos text,
test(# loglocation text,
test(# logapplicationname text
<kingbase-2023-01-05_153654.csv',format 'csv',header 'true',delimiter ',',null ' ');
CREATE FOREIGN TABLE

test=# select * from sys_log_svt limit 1;
logtime | loguser | logdatabase | logpid | loghost | logsessionid | logcmdcount | logcmdtag |
logsessiontime | logtransaction | log_level | logseverity | logstate | logmessa
ge | logdetail | loghint
| loginternalquery | loginternalquerypos | logcontext | logquery
| logquerypos | loglocation | logapplicationname
-------------------------------+---------+-------------+--------+---------+---------------+-------------+-----------+---
---------------------+----------------+-----------+-------------+----------+--------------------------------------------
--------------------------------------+-----------+---------------------------------------------------------------------
------------------------------+------------------+---------------------+------------+-----------------------------------
--+-------------+-------------+--------------------
2023-01-06 08:42:16.201000+08 | system | test | 15396 | [local] | 63b6a982.3c24 | 1 | SELECT | 20
23-01-06 08:42:10+08 | 4/4954 | 0 | ERROR | 42883 | function to_datetime(integer, integer, inte
ger, integer, integer) does not exist | | No function matches the given name and argument types. You might nee
d to add explicit type casts. | | | | select to_datetime(2022,1,1,01,01)
; | 8 | | kingbase_*&+_
(1 row)

以上两种方法可以将数据库日志以数据库表的方式进行查看,可以过滤出想要的内容,查看更加简洁。

标签:log,text,数据库,sys,TEST,test,日志,KingbaseES
From: https://www.cnblogs.com/kingbase/p/17030663.html

相关文章

  • KingbaseES V8R6 运维系列 --单机小版本升级
    ​案例说明:在KingbaseESV8R6版本提供了sys_upgrade的升级工具,本案例描述了KingbaseESV8R6单机环境下数据库的小版本升级操作,案例涉及的版本从‘(Kingbase)V008R006C0......
  • 解决Java读取数据库的时间类型时大8小时时差问题
    解决办法:在jdbc连接中设置serverTimezone参数,指定为东八区,可以使用serverTimezone=Asia/Shanghai或者serverTimezone=GMT%2b8如:jdbc:mysql://127.0.0.1:3306/demo_ds......
  • 数据库报ORA-00600 [2252]错误
    同事运维的数据库出现了一个ORA-00600 [2252]错误,针对该问题简单记录下。1、alter日志信息:TueFeb2814:22:302023Errorsinfiled:\app\diag\rdbms\pubb\pubb\trac......
  • 数据库简介及概要
    1、数据库简介:数据库(Database,DB)是一个长期存储在计算机内的、有组织的、有共享的、统一管理的数据集合。简单来讲就是可以放大量数据的地方。管理数据库的计算机系统......
  • 数据库之二、表的创建、数据类型、表的约束
    1、表的创建 创建表之前一般需要在特定的库中创建表,先创建一个库,之后的表都在该库中创建。创建数据库的语法:......
  • C#文件转Byte存储到SQLServer数据库
    场景:临时不同的系统,相同的数据库,通用文件读取1.数据库字段采用:varbinary(max)类型2.代码注:这里获取文件是通过先将byte[]数据先存到当前服务器对应项目的文件夹中(加了......
  • 【MyBatis】测试链接数据库查询用户
    配置文件访问:【MyBatis】配置Mybatis项目-小鼻涕孩-博客园(cnblogs.com)数据表数据:Test.java:1importorg.apache.ibatis.io.Resources;2importorg.apache.......
  • 使用 logrotate 切割nginx日志
    日志滚动logrotate能够自动完成日志的压缩、备份、删除和日志邮寄等工作。●logrotate默认的主配置文件是/etc/logrotate.conf。●/etc/logrotate.d的目录下的文件,这......
  • 记一次druid 数据库连接池遇到 union或者union all语句时报错以及处理
    报错日志大概如下:##Errorupdatingdatabase.Cause:java.sql.SQLException:sqlinjectionviolation,syntaxerror:syntaxerror,errorin:'UNIONALL......
  • 温习日志-21
    温习日志——2023年2月28日下午学习内容ABriefIntroductiontotheCommandLine通过在终端,输入cd相对路径实现更改路径在终端输入ls会列出当前所在文件夹的所有......