创建文件事件监视器

在创建事件监视器时,必须确定所收集信息的存储位置。文件事件监视器将事件记录存储在文件中。 文件事件监视器及其选项将由 CREATE EVENT MONITOR 语句定义。

开始之前

您需要 SQLADM 或 DBADM 权限才能创建文件事件监视器。

关于此任务

文件事件监视器将事件记录流输送至一系列 8 字符编号的文件,这些文件的扩展名为“EVT”(如 00000000.evt、00000001.evt 和 00000002.evt)。即使数据被分为较小的数据块,也应考虑将数据作为一个逻辑文件(即,数据流的开头是文件 00000000.evt 中的第一个字节;数据流的结尾是文件 nnnnnnnn.evt 的最后一个字节)。事件监视器永远不会让单个事件记录跨越两个文件。

过程

  1. 指定会将事件监视数据收集在一个文件或一组文件中,并提供存储事件文件的目录位置。
    CREATE EVENT MONITOR dlmon FOR eventtype
                         WRITE TO FILE '/tmp/dlevents'

    dlmon 是事件监视器的名称。

    /tmp/dlevents 是目录路径(在 UNIX 系统上)的名称,事件监视器会将事件文件写至该目录。

  2. 指定要监视的事件的类型。可使用单个事件监视器来监视一个或多个事件类型。
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents'
    此事件监视器将监视 CONNECTIONS 和 DEADLOCKS WITH DETAILS 事件类型。
  3. 通过调整 BUFFERSIZE 值来指定文件事件监视器缓冲区的大小(以 4K 页计):
    
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
    8 is the capacity in 4K pages of the two event file buffers.

    The default size of each buffer is 4 pages (two 16K buffers are allocated). The minimum size is 1 page. The maximum size of the buffers is limited by the size of the monitor heap, because the buffers are allocated from that heap. For performance reasons, highly active event monitors should have larger buffers than relatively inactive event monitors.

  4. Indicate if you need the event monitor to be blocked or non-blocked. For blocked event monitors, each agent that generates an event will wait for the event buffers to be written to file if they are full. This can degrade database performance, as the suspended agent and any dependent agents cannot run until the buffers are clear. Use the BLOCKED clause to ensure no losses of event data:
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                         BLOCKED 
    缺省情况下,事件监视器处于受阻状态。如果数据库性能比收集每个事件记录更重要,那么使用非分块事件监视器。在这种情况下,如果事件缓冲区已满,那么生成事件的每个代理程序将不会等待事件缓冲区写至文件。因此,非分块事件监视器可能会导致活动频繁的系统上的数据丢失。使用 NONBLOCKED 子句来使事件监视导致的额外处理时间降至最少:
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                         NONBLOCKED 
  5. 指定可对每个事件监视器收集的事件文件的最大数目。如果达到此限制,那么事件监视器将释放自身。
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                         NONBLOCKED MAXFILES 5 
    5 是将要创建的事件文件的最大数目。
    还可指定不限制事件监视器可创建的事件文件数:
    
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                         NONBLOCKED MAXFILES NONE
  6. 指定事件监视器创建的每个事件文件的最大大小(以 4K 页计)。如果达到此限制,那么创建新文件。
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                         NONBLOCKED MAXFILES 5 MAXFILESIZE 32
    32 is the maximum number of 4K pages that an event file can contain.
    This value must be greater than the value specified by the BUFFERSIZE parameter. You can also specify that there is to be no limit on an event file's size:
    
    CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                         WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                         NONBLOCKED MAXFILES NONE MAXFILESIZE NONE
  7. Specify if the event monitor is to be activated automatically each time the database starts. By default, event monitors (with the exception of the WLM event monitors) are not activated automatically when the database starts.
    • To create an event monitor that starts automatically when the database starts, issue the following statement:
      CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                           WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                           NONBLOCKED AUTOSTART
    • 要创建在数据库启动时不自动启动的事件监视器,请发出以下语句:
      
      CREATE EVENT MONITOR dlmon FOR CONNECTIONS, DEADLOCKS WITH DETAILS
                           WRITE TO FILE '/tmp/dlevents' BUFFERSIZE 8 
                           NONBLOCKED MANUALSTART
  8. 要激活或释放事件监视器,请使用 SET EVENT MONITOR STATE 语句。

结果

一旦创建并激活文件事件监视器,该事件监视器就会在指定的事件发生时记录监视数据。