oracle 9i學習日誌(7)—診斷文件與練習3

診斷文件:包括數據庫發生的重大事件的信息;用來幫助解決問題和更好的維護數據庫。
類型:alertSID.log;後臺跟蹤文件(Background trace files);用戶跟蹤文件(User trace files)。
1、以下操作或事件將被記錄在alertSID.log文件:
    數據庫啓動或關閉;
    非默認值的參數列表(包括參數名稱和參數值,在spfile或pfile損壞時可以藉助這些信息從新構造spfile或pfile);
    啓動後臺進程;
    被instance所用的線程;
    The log sequence number LGWR is writing to;
    有關log調整的信息;
    創建表空間和undo segment;
    已經提交的alter語句;
    錯誤信息,如:ORA-600;
alter_SID.log所在位置由參數BACKGROUND_DUMP_DEST值定義。
 
2、後臺跟蹤文件(Background trace files):
記錄當後臺程序出現重大錯誤時的信息。一般命名爲sid_processname_PID.trc。所在位置由參數
BACKGROUND_DUMP_DEST值定義。
實驗:
SQL> show parameter background_dump_dest
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
background_dump_dest                 string      /u01/admin/lty/bdump
$ cd /u01/admin/lty/bdump
[oracle@localhost bdump]$ ls -l
total 828
-rw-r--r-- 1 oracle oinstall 142968 Mar  6 23:38 alert_lty.log
-rw-r----- 1 oracle oinstall 660699 Mar  3 17:11 lty_d000_3303.trc
-rw-r----- 1 oracle oinstall    779 Feb 23 09:59 lty_qmn0_3324.trc
-rw-r----- 1 oracle oinstall    802 Feb 23 10:05 lty_qmn0_3338.trc
-rw-r----- 1 oracle oinstall    803 Feb 23 10:10 lty_qmn0_3350.trc
 
3、用戶跟蹤文件(User trace files):
由用戶進程產生,也可以被server進程生成,包含跟蹤SQL語句的統計信息和記錄用戶會話錯誤信息。可以用來對SQL的調優和排錯。
命名規則一般爲:sid_ora_PID.trc(如:db01_ora_23845.trc),所處位置由參數USER_DUMP_DEST決定,文件大小由參數MAX_DUMP_FILE_SIZE決定。
啓用和關閉用戶跟蹤
用戶級別:ALTER SESSION SET SQL_TRACE = TRUE啓用(注意:要在當前session設定)。也可以使用DBMS程序dbms_system.SET_SQL_TRACE_IN_SESSION。
instance級別:SQL_TRACE = TRUE啓用(會產生大量信息記錄,需謹慎)。
實驗:
客戶端:
sqlplus system/oracle@xxxx
SQL> alter session set sql_trace = true;
服務器:
$ ps -ef |grep oracle
oracle    3575  3574  0 00:57 ?        00:00:00 oraclelty (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
$cd /u01/admin/lty/udump
$ls –l
total 0
客戶端:
SQL> select * from dual;
服務器:
$ls –l
total 4
-rw-r----- 1 oracle oinstall 1383 Mar  7 00:58 lty_ora_3575.trc
 
4、Practice 3: Managing an Oracle Instance
1 Connect to the database as user SYS and shut down the database.
2 With the database shut down, create an SPFILE from the PFILE. The SPFILE will be created in $ORACLE_HOME/dbs.
  解析:SQL> create pfile from spfile;
   
3 From the operating system, view the SPFILE.
解析:
[oracle@localhost ~]$ cd dbs
[oracle@localhost dbs]$ ls -l
total 48
-rw-r--r-- 1 oracle oinstall 12920 Feb 22 20:14 initdw.ora
-rw-r--r-- 1 oracle oinstall  8475 Feb 22 20:14 init.ora
-rw-r----- 1 oracle oinstall    24 Mar  7 02:07 lkLTY
drwxr-xr-x 2 oracle oinstall  4096 Feb 22 16:29 old
-rwSr----- 1 oracle oinstall  1536 Feb 22 20:14 orapwlty
-rw-r----- 1 oracle oinstall  3584 Feb 22 20:14 spfilelty.ora
$strings spfilelty.ora

4 Connect as user SYS, and start the database using the SPFILE.
5 a Shut down the database and open it in read-only mode.
解析:SQL> startup mount
        SQL> alter database open read only;

b Connect as user HR password HR and insert a row into the REGIONS table as
follows:
INSERT INTO regions VALUES (5, 'Mars');
What happens?
解析:HR默認爲鎖定狀態,SQL> select username, user_id, account_status from dba_users;
         USERNAME                          USER_ID ACCOUNT_STATUS
        ------------------------------ ---------- --------------------------------
         HR                                     47 EXPIRED & LOCKED
        解鎖,SQL> select  username, account_status from dba_users;
        USERNAME                       ACCOUNT_STATUS
       ------------------------------ --------------------------------
        HR                             EXPIRED
       設置密碼,SQL> alter user hr identified by hr;
       查看狀態,SQL> select username, account_status from dba_users;
       USERNAME                       ACCOUNT_STATUS
       ------------------------------ --------------------------------
        HR                             OPEN
       
        另創建用戶lll密碼lll,SQL> create user lll identified by lll;
        以HR登陸後創建表lll,SQL> create table lll(num integer, name char(10));
       插入行,SQL> insert into lll values(0, 'lll');
                   ERROR 位於第 1 行:
                  ORA-00604: error occurred at recursive SQL level 1
                  ORA-16000: database open for read-only access
c Put the database back in read-write mode.
6 a Connect as user HR password HR and insert the following row into the REGIONS
table; do not commit or exit.
INSERT INTO regions VALUES (5, 'Mars');
b In a new telnet session start SQL*Plus. Connect user SYS and perform
a SHUTDOWN TRANSACTIONAL.
c Roll back the insert in the HR session and exit.
What happens to the HR session?
What happens to the SYS session?
7 a In the user SYS session start the database.
b In the open telnet session start SQL*Plus and connect as user HR.
Note: Keep the two SQL*Plus sessions open, one session as user SYS and one as
user HR.
c As user SYS enable a restricted session.
d As user HR, SELECT from the REGIONS table. Is the SELECT successful?
e Exit the session, then reconnect as HR. What happens? The user HR does not have
RESTRICTED SESSION privilege, and therefore, cannot log in.
f As user SYS disable the restricted session.
g Exit the HR telnet session
解析:SQL> alter system enable restricted session;
在數據庫置於restricted狀態時,不會中斷已連接用戶的會話。
本文出自 “冰冷的太陽” 博客,請務必保留此出處http://luotaoyang.blog.51cto.com/545649/281590
0人

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章