.. _2-解析工具的使用:

解析工具的使用
=================


本章节包含以下内容：

- 工具的启停_
- 典型协议示例_

.. _21-工具的启停:

工具的启停
---------------------------

.. _211-启动:

启动
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

kes_protocol_tool <物理网卡的名称> <需要监控的端口号>

工具启动后，不断地抓取并解析收到的协议消息，将协议直接打印在屏幕上。

.. code::

    [root@DB-NODE-1 bin]#./kes_protocol_tool ens192 54333
    Begin to monitor intf [ens192] [54333]
    [54333]
    TCP [10.10.11.122].[21298]->[10.10.11.121].[54333]
    TCP [10.10.11.122].[21298]->[10.10.11.121].[54333]
    TCP [10.10.11.121].[54333]->[10.10.11.122].[21298]
    Backend->Frontend: AuthenticationSCMMethod
        [SCRAM-SHA-256]
    TCP [10. 10.11.122].[21298]->[10.10.11.121].[54333]
    Frontend->Backend PasswordMessage
        [ SCRAM- SHA- 256 ]
    TCP [10.10.11.121].[54333]->[10.10.11.122].[21298]
    Backend->Frontend: Authenticat ionSCMParameter
        [r=7G// fs1UayfPmS2BfasohcWkZr9GiyRQNO1AKKPZs9WXNOXG, s=munDkY1NEoniwIRsKGPrnA==, i=4096 ]
    TCP [10. 10.11.122].[21298]->[10.10.11.121].[54333]
    Frontend->Backend: PasswordMessage
        [c=biws, r=7G//fs1UayfPmS2BfasohcWkzr9GiyRQNO1AKKPZs9WXN0XG，p=U8Pc4iPH9ySVhmzDAXN05mY2kuK7MRqv 1fE30RwUEMg= ]
    TCP [10.10.11.121].[54333]-> [10.10.11.122].[21298]
    Backend->Frontend: Authenticat ionSCMValue
        [v=jpGY7cmS7Py/ Jwv0Q1XIVY aNbyHz t5Q0IMh8P+GrF8I=]
    Backend->Frontend: AuthenticationOk
    Backend->Frontend: ParameterStatus 
        Name [application_name] 
        Value[ ]
    Backend->Frontend: ParameterStatus
        Name [ctient_encoding]
        Value[UTF8]
    Backend->Frontend: ParameterStatus
        Name [DateStyle]
        Value[ISO, YMD ]
    Backend->Frontend: ParameterStatus
        Name [enable_autocommit_crossquery]
        Value[off]
    Backend->Frontend: ParameterStatus
        Name [enable_func_colname ]
        Value[off]
    Backend->Frontend: ParameterStatus
        Name [enable inplace update ]
        Value[off]
    Backend->Frontend: ParameterStatus
        Name [enable_origin_id] 
        Value[off]
    Backend->Frontend: ParameterStatus
        Name [enable_upper_colname]
        Value[off]


.. _212-停止:

停止
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

方式一：工具在当前session持续不断地运行，直到人为地 Ctrl + C 停止；

方式二：通过其他session，找到进程ID，kill相关进程可以停止工具。


.. _22-典型协议示例:

典型协议示例
-----------------------------

.. _221-后端backend发送的报文:

后端(BACKEND)发送的报文
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

AuthenticationOk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

认证请求成功的返回报文。

.. code::

    TCP [10.10.12.252].[54332]->[10. 10.12.252].[36602]
    Backend->Frontend: Authenticat ionOk
    Backend->Frontend: ParameterStatus
    Name [ application name] Value[kingbase &+_]
    Backend->Frontend: ParameterStatus
    Name [case_sensitive ]
    Value [ on]
    Backend->Frontend: ParameterStatus
    Name[client_encoding]
    Value [SQL ASCII]
    Backend->Frontend: ParameterStatus
    Name [DateStyle]
    Value [ISO, MDY]
    Backend->Frontend: ParameterStatus
    Name [enable_autoc ommit C rossquery]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name [ enable func co Lname ]
    Value[off]
    Backend->Frontend: ParameterStatus
    Name [enable_origin id] Value[off]
    Backend->Frontend: ParameterStatus
    Name [ enable_upper_Co Lname ]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name [enable_xlog]
    Value [on ]
    Backend->Frontend: ParameterStatus
    Name [ integer datetimes ]
    Value [on]
    Backend->Frontend: ParameterStatus
    Name [Intervalstyle]
    Value [ kingbase]
    Backend->Frontend: ParameterStatus
    Name [is_supe ruser ]
    Value [ on]
    Backend->Frontend: Pa ramete rStatus
    Name[ LW_snap]
    Value [on ]
    Backend->Frontend: Pa ramete rStatus
    Name [mysqL interval style]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name[ora forbid func pol ymo rphism]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name[ora numop_styLe ]
    Value[off]
    Backend->Frontend: ParameterStatus
    Name[ora statement Level rol Lback ]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name [ repeat_wait for bad Lsn]
    Value[off]
    Backend->Frontend: ParameterStatus
    Name [server_encoding] Value[SQL_ASCII]
    Backend->Frontend: ParameterStatus
    Name[server_version ]
    Value[12.1 ]
    Backend->Frontend: ParameterStatus
    Name [ session_authorization ]
    Value [wim ]
    Backend->Frontend: ParameterStatus
    Name [ standard conforming strings ]
    Value [on]
    Backend->Frontend: ParameterStatus
    Name [ TimeZone ]
    Value [ America/New York]
    Backend->Frontend: BackendKeyData
    ProcessID:4985 Secret: - 1926733191
    Backend->Frontend: ReadyForQuery
    Idle State

BindComplete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

绑定完成指示（Bind-complete indicator）报文。

.. code:: 

    TCP [10.10.11.152].[54333]->[10.10.11.152] . [54708 ]
    Backend->Frontend: BindComplete
    Backend->Frontend: RowDescription
    number of coLumn: 1
    name 1#: [ ?column?] 
    table id:0
    col oid:O
    column type id:25
    coLumn type size:65535
    coLumn type modifier: -1
    column type
    code:0 (0: text;1 :binary; 2mixed)
    Backend->Frontend: DataRow- text
    number of coLumn: 1
    Value 1#: [stmt no 0]

DataRow
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

数据行（Data Row）报文。

.. code::

    TCP [10.10.12.252].[54332]->[10.10.12.252] . [36622 ]
    Backend->Frontend: RowDescription
    number of column: 1
    name 1#: [c1]
    table id: 16384
    col oid: 1
    column type
    id:23
    column type size:4
    column type modifier: - 1
    column type code:0 (O: text; 1:binary; 2mixed)
    Backend->Frontend: DataRow- text
    number of coLumn: 1
    Value 1#: [ 123123 ]



EmptyQueryResponse
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

空查询响应报文。

.. code::

    TCP [10.10.11.152].[54333] ->[10.10.11.152]，[54700 ]
    Backend->Frontend: EmptyQueryResponse
    Backend->Frontend: ReadyForQuery
    Idle State



ErrorResponse
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

错误消息报文。

.. code:: 

    TCP [ 10.10.12.252].[54332]->[10.10.12.252].[36588 ]
    Backend->Frontend: Erro rResponse 
    [S] [FATAL] 
    [V] [FATAL ]
    [C] [28P01]
    [M] [password authentication failed for U user "wim"]
    [F] [auth.c]
    [L] [353]
    [R] [auth_failed]

S 严重性(Severity)
  该字段的内容是ERROR，FATAL， 或者 PANIC（在一个错误消息里），或者 WARNING， NOTICE，DEBUG，INFO 或 LOG （在一条通知消息里），或者是这些的某种本地化翻译的字串。总是会出现。

V 严重性(Severity)
  该字段的内容是ERROR，FATAL， 或者 PANIC（在一个错误消息里），或者 WARNING， NOTICE，DEBUG，INFO 或 LOG （在一条通知消息里），不会被本地化翻译。总是会出现。

C 代码
  错误的 SQLSTATE 代码（一个 5 字符字串，后面跟着 SQL 规范的习惯）。 不能本地化。总是出现。

M 消息(Message)
  用户可读的错误信息的主体。这些信息应该准确并且简洁（通常是一行）。总是出现。

D 细节(Detail)
  一个可选的从属错误信息，承载有关问题的更多错误消息。可以是多行。

H 提示(Hint)
  一个可选的有关如何处理问题的建议。它和细节不同的地方是它提出了建议（可能并不合适）而不仅仅是事实。可以是多行。

P 位置(Position)
  这个字段值是一个十进制 ASCII 整数，表示一个错误游标的位置，它 是一个指向原始查询字串的索引。第一个字符的索引是 1，位置是以字符计算 而非字节计算的。

W 哪里(Where)
  一个指示错误发生的环境的指示器。目前，这个参数包含一个活跃的PL 函数 的调用堆栈的追溯。这个追溯每条记录一行，最新的在最上面。

F 文件(File)
  报告错误的源代码所在文件名。

L 行(Line)
  报告错误的源代码中的行号。




NoData
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

无数据指示（no-data indicator）报文。

.. code::

    TCP [10.10.11.152].[54333] ->[10.10.11.152].[54712]
    Backend->Frontend: BindComplete
    Backend->Frontend: NoData
    Frontend->Backend: Close
    Backend->Frontend: ReadyForQuery
    Idle State


NoticeResponse
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

通知消息（notice）报文。

.. code::

    TCP [10.10.11.152]，[54333]->[10.10.11.152].[54734 ]
    Backend->Frontend: NoticeResponse
    [S] [WARNING ]
    [V] [WARNING]
    [C] [25P01]
    [M] [there is no transaction in progress]
    [F] [xact.c]
    [L] [4084 ]
    [R] [Use rAbortTransactionBlock]


ParameterDescription
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

参数描述报文。

.. code:: 

    TCP [10.10.11.152].[54333]->[10.10.11.152].[54744 ]
    Backend->Frontend: Paramete rDesc ription
    Backend->Frontend: RowDesc ription
    number of column: 1
    name 1#: [t]
    table id: 45900
    col oid:2
    column type id:25
    column type size:65535
    column type 
    modifier: - 1
    column type code:0 (O: text; 1:binary; 2mixed)
    Backend->Frontend: ReadyForQuery
    Idle State


ParameterStatus
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

运行参数状态报告（run-time parameter status report）报文。

.. code:: 

    TCP [10.10.12.252].[54332]->[10.10.12.252].[36602]
    Backend->Frontend: AuthenticationOk
    Backend->Frontend: ParameterStatus
    Name [ application name] Value[kingbase &+_]
    Backend->Frontend: ParameterStatus
    Name [case_sensitive ]
    Value [ on]
    Backend->Frontend: ParameterStatus
    Name[c ltient_encoding]
    Value [SQL ASCII]
    Backend->Frontend: ParameterStatus
    Name [DateStyle]
    Value [ISO, MDY]
    Backend->Frontend: ParameterStatus
    Name [enable_autoc ommit C rossquery]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name [ enable func co Lname ]
    Value[off]
    Backend->Frontend: ParameterStatus
    Name [enable_origin id] Value[off]
    Backend->Frontend: ParameterStatus
    Name [ enable_upper_Co Lname ]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name [enable_xlog]
    Value [on ]
    Backend->Frontend: ParameterStatus
    Name [ integer datetimes ]
    Value [on]
    Backend->Frontend: ParameterStatus
    Name [Intervalstyle]
    Value [ kingbase]
    Backend->Frontend: ParameterStatus
    Name [is_supe ruser ]
    Value [ on]
    Backend->Frontend: Pa ramete rStatus
    Name[ LW_snap]
    Value [on ]
    Backend->Frontend: Pa ramete rStatus
    Name [mysqL interval style]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name[ora forbid func pol ymo rphism]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name[ora numop_styLe ]
    Value[off]
    Backend->Frontend: ParameterStatus
    Name[ora statement Level rol Lback ]
    Value [off]
    Backend->Frontend: ParameterStatus
    Name [ repeat_wait for bad Lsn]
    Value[off]
    Backend->Frontend: ParameterStatus
    Name [server_encoding] Value[SQL_ASCII]
    Backend->Frontend: ParameterStatus
    Name[server_version ]
    Value[12.1 ]
    Backend->Frontend: ParameterStatus
    Name [ session_authorization ]
    Value [wim ]
    Backend->Frontend: ParameterStatus
    Name [ standard conforming strings ]
    Value [on]
    Backend->Frontend: ParameterStatus
    Name [ TimeZone ]
    Value [ America/New York]
    Backend->Frontend: BackendKeyData
    ProcessID:4985 Secret: - 1926733191
    Backend->Frontend: ReadyForQuery
    Idle State


ParseComplete
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Parse命令完成报文。

.. code::

    TCP [10.10.11.152].[54333] ->[10.10.11.152]，[54744]
    Backend->Frontend: ParseComplete
    Backend->Frontend: ReadyForQuery
    Idle State


ReadyForQuery
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

当后端准备好接收新的查询请求时发送该报文。

.. code::

    Backend->Frontend: ReadyForQuery


.. _222-前端frondend发送的报文:

前端(FRONDEND)发送的报文
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Bind
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

绑定命令报文。

.. code::

    TCP [10.10.11.152].[54744] ->[10.10.11.152].[54333]
    Frontend->Backend: Bind
    Frontend->Backend: Describe


Close
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

关闭命令报文。

.. code::

    TCP [10.10.11.152].[54333] ->[10.10.11.152].[54744]
    Frontend->Backend: Close
    Backend->Frontend: ReadyForQuery
    Idle State


Describe
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Describe命令报文。

.. code:: 

    TCP [10.10.11.152].[54744] ->[10.10.11.152].[54333]
    Frontend->Backend: Bind
    Frontend->Backend: Describe

Parse
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Parse命令报文。

.. code:: 

    TCP [10.10.11.152].[54744] ->[10.10.11.152].[54333]
    Frontend->Backend: Parse


PasswordMessage
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

密码消息报文。

.. code:: 

    TCP [10.10.12.252].[36600]->[10.10.12.252].[54332]
    Frontend->Backend: PasswordMessage
    [c=biws, r=U8GQDTenel0WB6AXr/XdNjCbLp0/E1LqjK2dNxhqDnN0fFIg, p=ZFCjUmUwhAtG4yBPyDTt5G9LQqsTBDOhOa30Ab7cERw=]


Query
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

简单查询（simple query）报文。

.. code:: 

    TCP [10.10.12.252].[36602]->[10. 10.12.252].[54332]
    Frontend->Backend: Query
    [select extname from pg_extension where extname= 'sys_audlog'; ]


Terminate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Termination报文。

.. code::

    TCP [ 10.10.12.252].[36602]->[10.10.12.252].[54332]
    Frontend->Backend:
    Terminate



