03 Files
本章提要
-----------------------------------------------
組成 oracle 的 8 種主要文件(包括 instance 和 database)
instance: parameter file, trace file, alert file
database: data file, temp file, control file, redo log file, password file
簡單概述:
parameter file: instance 參數(shù)初始化, 哪里可以找到control file.
trace file: diagnostic files created by a server process
alert file: dba 檢查問題的中心
data file: 存儲例如 table, index 等
temp file: 臨時存儲 和 disk-based sort
control file: 哪里可以找到 datafile, redolog file, temp file, 一些其他的元數(shù)據(jù), backup info.
redo log file: transaction logs
password file: are used to authenticate users performing administrative activities over the network.
-- 10g 以后新增加的兩個文件, 為了更好的backup 和 recovery
change-tracking file: 更好的 incremental backup or oracle data
flashback log file: store "before images" of database blocks
-- 其他類型文件 --
dump files: Export 產(chǎn)生的文件
Data Pump files: Data Pump Export process 產(chǎn)生的文件
Flat files: 可以用text editor 打開的文件, 一般用作 loading data
-- 最重要的文件是 data file, redo log file.
-----------------------------------------------
1. parameter file
?? ?很多種類, 例如 tnsnames.ora, listener.ora 等, 不過這里重點討論的是, init<sid>.ora 和 spfile
SID : 概念再補充: the sid is a site identifier, it and ORACLE_HOME(where the oracle software is
?? ?installed) are hashed together in UNIX to create a unique key name for creating or attaching
?? ?a Shared Global Area(SGA) memory region. If your ORACLE_SID or ORACLE_HOME is not set correctly,
?? ?you’ll get the ORACLE NOT AVAILABLE error.
?? ?select value from v$parameter where name = 'db_block_size' -- 查詢 parameter 方法
?? ?show parameter db_block_s?? ??? ?-- 查詢 parameter 方法, 可以使用模糊查詢, 所以比較好
?? ?還有一些非正式聲明的參數(shù), 它們是以下劃線開頭, 例如 _trace_file_public, 一般我們不用關(guān)心這些非正式
?? ?聲明的參數(shù), 大師一般只是設(shè)置一個 _trace_file_public=true, 作用是設(shè)置 trace_file read only by all.
?? ?因為有很多常用工具需要讀取tracefile, 比如 SQL_TRACE, TIMED_STATISTICS, TKPROF
?? ?但是在生產(chǎn)庫, 不需要設(shè)置這個參數(shù).(生產(chǎn)庫不設(shè)置任何 undocumented
?? ?spfile 修改參數(shù)方法:
?? ?Alter system set parameter=value <comment='text'> <deferred>
?? ??? ??? ??? ??? ?<scope=memory|spfile|both> <sid='sid|*'>
?? ?如果我們想刪除我們之前設(shè)置的參數(shù), 而是用系統(tǒng)默認(rèn)的參數(shù), 那么, 我們需要使用如下命令:(reset)
?? ?alter system reset sort_area_size scope=spfile;
?? ?可以通過使用 startup pfile=filename, 這樣, instance啟動時會參考Pfile, 而不是spfile.
?? ?之前說過parameter file的優(yōu)先級.
?? ?如果spfile損壞了怎么辦, 你有很多辦法, 首先如果你在unix系統(tǒng)下, 因為spfile很小, 可以使用strings命令
?? ?查看spfile中的內(nèi)容, 進而生成pfile(可以使用editor text編輯), 然后再create spfile from pfile 就可以.
?? ?在windows系統(tǒng), 可以使用 write.exe(WordPad)打開這個文件, 進而生成pfile, 然后同樣命令創(chuàng)建spfile.
?? ?如果spfile丟了, 那么你可以借助 log file來恢復(fù)spifle, 在log file中有instance啟動的信息, 里邊有參數(shù)
?? ?設(shè)置的情況, copy出來, 制作pfile, 進而生成spfile.
?? ?
2. Trace files
?? ?Trace files are a source of debugging information.(是數(shù)據(jù)庫自己debug的information)
?? ?數(shù)據(jù)庫編寫人員, 會將數(shù)據(jù)庫出現(xiàn)的問題, 寫日志到trace file中.
?? ?oracle 對于 debug 而提供的工具有:
?? ?(我們不需要直接讀tracefile, 我們讀不懂, tracefile是為oracle support 人員準(zhǔn)備的, 那么我們可以借助下面工具
?? ? 來進行一些查看.)
?? ?1) v$ views: Most V$ views contain “debug” information.v$waitstat, v$session_event 等.
?? ?2) audit: This command allows you to specify what events the database should record for later analysis
?? ?3) resource manager: (DBMS_RESOURCE_MANAGER)(CPU, I/O)
?? ?4) oracle events: ask Oracle to produce trace or diagnostic information as needed
?? ?5) dbms_trace: within the PL/SQL engine exhaustively records the call tree of stored procedures 等.
?? ?6) database event trigger: These triggers, such as ON SERVERERROR.
?? ?7) SQL_TRACE/DBMS_MONITOR: This is used to view the exact SQL, wait events and other performance.
?? ?
?? ?Trace files 包含兩種:
?? ?1) 我們比較關(guān)心的, contain diagnostic information about your session and will help you tune your
?? ??? ?application to optimize its performance and diagnose any bottlenecks it is experiencing.
?? ?2) 我們一般不關(guān)心, 一般是數(shù)據(jù)庫原廠支持人員才能看懂的診斷內(nèi)容, 比如 ORA-00600 "Internal Error"
?? ?Requested Trace Files (請求相關(guān)的 trace file)
?? ?DBMS_MONITOR( alter session set sql_trace=true)
?? ?or using the extended trace facility via the 10046 event, might be as follows:
?? ?alter session set events '10046 trace name context forever, level 12'
?? ?These trace files contain diagnostic and performance related information(這種trace file最有用, 會經(jīng)常使用)
?? ?Location: user_dump_dest(dedicated server), background_dump_dest(shared server)
?? ?show parameter dump_dest, 會顯示 3 個 location, 其中:
?? ?background_dump_dest: "server" process, oracle background process
?? ?core_dump_dest: 進程的更加詳盡的診斷文件
?? ?user_dump_dest: (dedicated server)
???
??? 01 trace_file_location.sql
?? ?在查詢出來的結(jié)果中, 兩個參數(shù)比較重要: ( 11g 之后使用 )
?? ?Diag Trace: trace地址, 包括background_trace file 和 user dump trace file.
?? ?Default Trace File: your current session's trace file.
?? ?
?? ?trace name : oraclesid_ora_pid.trc
?? ?v$PROCESS: 可以查看到pid
?? ?V$SESSION: 可以查看到session信息
?? ?V$INSTANCE: 可以查看到 oracle sid.
?? ?所以, 可以通過另外的方法, 查看到當(dāng)前的 trace file
???
??? 02 trace_file_now.sql
??? ?開通當(dāng)前 trace file 的方法: exec dbms_monitor.session_trace_enable
?? ?你可以為 trace file 加上標(biāo)簽, 這樣你就更容易找到當(dāng)前是哪個 tracefile, 辦法是:
?? ?alter session set tracefile_identifier = 'LooK_LEON'; -- 在當(dāng)前的 session 下
?? ?exec dbms_monitor.session_trace_enable;
?? ?這樣就會在相應(yīng)目錄下看到帶 'Look_LEON'名稱的trace file, 那么很顯然這就是當(dāng)前的tracefile.
?? ?這樣的話, 文件名是 <ORACLE_SID>_ora_<PROCESS_ID>_Look_LEON.trc
?? ?Trace Files Generated in Reponse to Internal Errors
?? ?例如: ORA-00600: internal error code, 類似這種錯誤, 是 oracle的bug, 我們只能請求oracle的服務(wù).
?? ?所以, 找到對應(yīng)的 tracefile 文件是十分重要的, 因為可以將它上傳, 讓 oracle support人員查看.
3. Alert File
?? ?alert log file 很重要, 是數(shù)據(jù)庫日志文件.
?? ?alert log file 是文本文檔文件, 可以看懂.
4. Data file?? ?
?? ?一般創(chuàng)建數(shù)據(jù)庫時最少包括3個datafile:
?? ?system tablespace 對應(yīng) datafile.
?? ?user tablespace 對應(yīng) datafile.
?? ?sysaux tablespace 對應(yīng) datafile (10g 以后版本)
?? ?
?? ?4種datafile 結(jié)構(gòu) (物理結(jié)構(gòu))
?? ?1) operating system(os)file system: 一般操作系統(tǒng)文件, 我用的就是這種
?? ?2) 未安裝任何os的磁盤, 這個磁盤對Oracle來說是個大文件 (這種很少使用)
?? ?3) Automatic Storage management(ASM): 做了一個抽象ASM系統(tǒng), 即ASM是在OS與database中間
?? ?4) Clustered file system: 為了 RAC, 看起來像第一種file system
?? ?個人感覺, (1), (3)比較常用
?? ?database 分層結(jié)構(gòu)
?? ?tablespace: 組成了database
?? ?segments: 實際存儲對象, 比如 table, index 等, Every object that consumes storage is ultimately stored in a
?? ??? ?single segment. There are undo segments, temporary segments,cluster segments, index segments and so on.
?? ?extents: An extent is a logically contiguous allocation of space in a file.
?? ?blocks: A block is the smallest unit of space allocation in Oracle.?? ?一般分為 2k,4k,8k,16k
???
?? ?<03_01.jpg>
?? ?注意: 這個圖我們盡量從邏輯角度看, 所以看到extent是連續(xù)的, 但是其實不是這樣.
?? ?extent 之間不連續(xù), extent 內(nèi)部連續(xù)。
?? ?<03_02.jpg>
???
?? ?block structure
5. Temp Files
?? ?Temp files never have REDO generated for them, although they can have UNDO generated. Thus,
?? ?there will be REDO generated working with temporary tables since UNDO is always protected by REDO.
6. Control files
?? ?the control files tell the instance where the database and online redo log files are.
?? ?developer 基本上用不到 control file.
7. Redo Log Files
8. password Files
?? ?本地組內(nèi)部的User, 都可以不用密碼登陸數(shù)據(jù)庫, 所以不一定非的是oracle這個用戶
?? ?而如果在網(wǎng)絡(luò)上連接數(shù)據(jù)庫, 操作系統(tǒng)認(rèn)證就不行了, password file 只可以通過網(wǎng)絡(luò)認(rèn)證為 sysdba的用戶
?? ?首先啟動數(shù)據(jù)庫, 設(shè)置參數(shù) remote_login_passwordfile=EXCLUSIVE, 如果是shared表示多個數(shù)據(jù)庫可以共用密碼文件
?? ?一般這個參數(shù), 默認(rèn)就是 EXCLUSIVE
?? ?然后使用, orapwd file=orapw$ORACLE_SID password=aaa entries=20(最大連接數(shù)), 這時我們可以使用 sys 用戶遠(yuǎn)程
?? ?連接上來, 但是我們自己隨便建立用戶, 不能連接上來, 因為我們隨便建立的用戶不是SYSDBA權(quán)限, 所以, 我們要先授權(quán)
?? ?我們新建用戶的權(quán)限, grant sysdba to leon; 然后就可以從遠(yuǎn)端用 leon 用戶連接上來了. 另外注意, orapwd是linux命令
?? ?另外, 遠(yuǎn)程連接時, 如果server端采用動態(tài)注冊的話, 那么必須要開啟instance時, 才能動態(tài)注冊, 所以, 這樣就沒有辦法
?? ?使用這種遠(yuǎn)程連接到?jīng)]有開啟instance的數(shù)據(jù)庫, 所以, 這時需要使用靜態(tài)注冊, 才可以遠(yuǎn)端來接來sysdba,遠(yuǎn)端開啟數(shù)據(jù)庫
9. dump files
?? ?dmp 文件是獨立于平臺(os), 可以用于重建表, 模式, 甚至整個數(shù)據(jù)庫, 導(dǎo)入工具的作用就是讀取dmp文件, 執(zhí)行ddl語句,
?? ?并加載它找到的所有數(shù)據(jù). 現(xiàn)在這個已經(jīng)有被 data pump 取代的形式.
10. data pump files
?? ?IMPDP 和 EXPDP 使用這種文件格式, 使用方法與 IMP 和 EXP 一樣.?? ?
總結(jié)
- 上一篇: 设计模式--6大原则--单一职责原则
- 下一篇: VMware虚拟机VMDK 快照 数据恢