程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle數據庫基礎 >> 利用oracle外部表查看報警信息

利用oracle外部表查看報警信息

編輯:Oracle數據庫基礎
首先了解什麼是外部表,與其它表的區別,建立一個簡單的外部表(主要看操作過程),最後我們用外部表查看Oracle報警日志
  一.了解Oracle外部表
  外部表定義:結構被存放在數據字典,而表數據被放在OS文件中的表
  作用:在數據庫中查詢OS文件的數據,還可以將OS文件數據裝載到數據庫中
  與其它表的區別:在外部表上不能執行DML操作,也不能在外部表上建索引,只能執行select操用
  二.建一個簡單的外部表
  1.建一個OS上的文件
  因為外部表主要是查看OS上的文件,首先在OS上建一個文件
  mkdir -p /Oracle/ext
  vi /Oracle/ext/ext.dat
  10,20,30
  40,50,60
  70,80,90
  2.授予用戶權限,並建立目錄對象
  在此我們先建一個新用戶
  create user test identifIEd by “123” default tablespace test quota unlimited on test;
  用戶授權
  SQL> grant create any directory to test;
  建立目錄對象
  SQL> conn test / 123
  Connected.
  SQL> create directory ext as '/Oracle/ext';
  Directory created.
  3.建立外部表
  SQL> create table exttable(
  id number,name varchar2(10),i number
  )organization external
  (type Oracle_loader
  default directory ext
  Access parameters
  (records delimited by newline
  fIElds terminated by ','
  )location('ext.dat')
  );
  4.測試
  SQL> select * from exttable;
  ID NAME I
  ---------- ---------- ----------
  10 20 30
  40 50 60
  70 80 90
  測試成功,可見在數據庫中可以查詢OS文件的數據
  二. 使用外部表查看Oracle報警日志
  由於在上面實驗中已建立了一個用戶,並賦相應的權限,而且也有了OS文件(即報警文件alert_SID.log),所以在此直接建立目錄對象並建立外部表就可以了。
  1.建立目錄對象
  SQL> conn test / 123
  Connected.
  SQL> create directory bdump as '/oracle/u01/app/Oracle/admin/db2/bdump';
  Directory created.
  2.建立外部表
  SQL> create table alert_log(
  text varchar2(400)
  )organization external
  (type Oracle_loader
  default directory bdump
  Access parameters
  (records delimited by newline
  )location('alert_db2.log')
  );
  3.測試
  首先查看能否查到alert_db2.log的內容
  SQL> select * from alert_log where rownum < 10;
  TEXT
  Thu Jun 11 00:51:46 2009
  Starting Oracle instance (normal)
  Cannot determine all dependent dynamic librarIEs for /proc/self/exe
  Unable to find dynamic library libocr10.so in search paths
  RPATH = /ade/aime1_build2101/oracle/has/lib/:/ade/aime1_build2101/Oracle/lib/:/a
  de/aime1_build2101/Oracle/has/lib/:
  LD_LIBRARY_PATH is not set!
  The default library directorIEs are /lib and /usr/lib
  Unable to find dynamic library libocrb10.so in search paths
  Unable to find dynamic library libocrutl10.so in search paths
  9 rows selected.
  測試成功
  然後我們測試查報警信息’ORA-%’
  SQL> select * from alert_log where text like 'ORA-%';
  TEXT
  ORA-00202: control file: '/oracle/u01/app/Oracle/product/10.2.0/db2/dbs/cntrldb2
  .dbf'
  ORA-27037: unable to obtain file status
  ORA-205 signalled during: ALTER DATABASE MOUNT...
  ORA-00301: error in adding log file '/home/oracle/Oracle/oradata/testdb/redo01.l
  og' - file cannot be created
  ORA-27040: file create error
  ORA-1501 signalled during: CREATE DATABASE db2
  ORA-00200: control file could not be created
  TEXT
  ORA-00202: control file: '/oracle/u01/app/Oracle/product/10.2.0/db2/dbs/cntrldb2
  .dbf'
  ORA-27038: created file already exists
  ORA-1501 signalled during: CREATE DATABASE db2
  ORA-00200: control file could not be created
  ORA-00202: control file: '/oracle/u01/app/Oracle/product/10.2.0/db2/dbs/cntrldb2
  .dbf'
  ORA-27038: created file already exists
  ORA-1501 signalled during: CREATE DATABASE db2
  測試成功,
  可見我們可以使用外部表來方便的查看Oracle的報警信息.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved