日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

03 Files

發布時間:2023/12/4 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 參數初始化, 哪里可以找到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, 一些其他的元數據, 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 產生的文件
Data Pump files: Data Pump Export process 產生的文件
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 方法, 可以使用模糊查詢, 所以比較好
?? ?還有一些非正式聲明的參數, 它們是以下劃線開頭, 例如 _trace_file_public, 一般我們不用關心這些非正式
?? ?聲明的參數, 大師一般只是設置一個 _trace_file_public=true, 作用是設置 trace_file read only by all.
?? ?因為有很多常用工具需要讀取tracefile, 比如 SQL_TRACE, TIMED_STATISTICS, TKPROF
?? ?但是在生產庫, 不需要設置這個參數.(生產庫不設置任何 undocumented
?? ?spfile 修改參數方法:
?? ?Alter system set parameter=value <comment='text'> <deferred>
?? ??? ??? ??? ??? ?<scope=memory|spfile|both> <sid='sid|*'>
?? ?如果我們想刪除我們之前設置的參數, 而是用系統默認的參數, 那么, 我們需要使用如下命令:(reset)
?? ?alter system reset sort_area_size scope=spfile;
?? ?可以通過使用 startup pfile=filename, 這樣, instance啟動時會參考Pfile, 而不是spfile.
?? ?之前說過parameter file的優先級.

?? ?如果spfile損壞了怎么辦, 你有很多辦法, 首先如果你在unix系統下, 因為spfile很小, 可以使用strings命令
?? ?查看spfile中的內容, 進而生成pfile(可以使用editor text編輯), 然后再create spfile from pfile 就可以.
?? ?在windows系統, 可以使用 write.exe(WordPad)打開這個文件, 進而生成pfile, 然后同樣命令創建spfile.

?? ?如果spfile丟了, 那么你可以借助 log file來恢復spifle, 在log file中有instance啟動的信息, 里邊有參數
?? ?設置的情況, copy出來, 制作pfile, 進而生成spfile.
?? ?
2. Trace files
?? ?Trace files are a source of debugging information.(是數據庫自己debug的information)
?? ?數據庫編寫人員, 會將數據庫出現的問題, 寫日志到trace file中.
?? ?oracle 對于 debug 而提供的工具有:
?? ?(我們不需要直接讀tracefile, 我們讀不懂, tracefile是為oracle support 人員準備的, 那么我們可以借助下面工具
?? ? 來進行一些查看.)
?? ?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) 我們比較關心的, 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) 我們一般不關心, 一般是數據庫原廠支持人員才能看懂的診斷內容, 比如 ORA-00600 "Internal Error"

?? ?Requested Trace Files (請求相關的 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最有用, 會經常使用)
?? ?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)
???

with home as (select value homefrom v$diag_infowhere name = 'ADR Home' ) select name,case when value <> home.homethen replace(value, home.home, '$home$')else valueend valuefrom v$diag_info, home / View Code


??? 01 trace_file_location.sql
?? ?在查詢出來的結果中, 兩個參數比較重要: ( 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.
?? ?所以, 可以通過另外的方法, 查看到當前的 trace file
???

column trace new_val T select c.value || '/' || d.instance_name || '_ora_' ||a.spid || '.trc' ||case when e.value is not null then'_' || e.value end tracefrom v$process a, v$session b, v$parameter c, v$instance d, v$parameter ewhere a.addr = b.paddrand b.audsid = userenv('sessionid')and c.name = 'user_dump_dest'and e.name = 'tracefile_identifier' / View Code


??? 02 trace_file_now.sql
??? ?開通當前 trace file 的方法: exec dbms_monitor.session_trace_enable
?? ?你可以為 trace file 加上標簽, 這樣你就更容易找到當前是哪個 tracefile, 辦法是:
?? ?alter session set tracefile_identifier = 'LooK_LEON'; -- 在當前的 session 下
?? ?exec dbms_monitor.session_trace_enable;
?? ?這樣就會在相應目錄下看到帶 'Look_LEON'名稱的trace file, 那么很顯然這就是當前的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的服務.
?? ?所以, 找到對應的 tracefile 文件是十分重要的, 因為可以將它上傳, 讓 oracle support人員查看.

3. Alert File
?? ?alert log file 很重要, 是數據庫日志文件.
?? ?alert log file 是文本文檔文件, 可以看懂.

4. Data file?? ?
?? ?一般創建數據庫時最少包括3個datafile:
?? ?system tablespace 對應 datafile.
?? ?user tablespace 對應 datafile.
?? ?sysaux tablespace 對應 datafile (10g 以后版本)
?? ?
?? ?4種datafile 結構 (物理結構)
?? ?1) operating system(os)file system: 一般操作系統文件, 我用的就是這種
?? ?2) 未安裝任何os的磁盤, 這個磁盤對Oracle來說是個大文件 (這種很少使用)
?? ?3) Automatic Storage management(ASM): 做了一個抽象ASM系統, 即ASM是在OS與database中間
?? ?4) Clustered file system: 為了 RAC, 看起來像第一種file system
?? ?個人感覺, (1), (3)比較常用

?? ?database 分層結構
?? ?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是連續的, 但是其實不是這樣.
?? ?extent 之間不連續, extent 內部連續。
?? ?<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
?? ?本地組內部的User, 都可以不用密碼登陸數據庫, 所以不一定非的是oracle這個用戶
?? ?而如果在網絡上連接數據庫, 操作系統認證就不行了, password file 只可以通過網絡認證為 sysdba的用戶
?? ?首先啟動數據庫, 設置參數 remote_login_passwordfile=EXCLUSIVE, 如果是shared表示多個數據庫可以共用密碼文件
?? ?一般這個參數, 默認就是 EXCLUSIVE
?? ?然后使用, orapwd file=orapw$ORACLE_SID password=aaa entries=20(最大連接數), 這時我們可以使用 sys 用戶遠程
?? ?連接上來, 但是我們自己隨便建立用戶, 不能連接上來, 因為我們隨便建立的用戶不是SYSDBA權限, 所以, 我們要先授權
?? ?我們新建用戶的權限, grant sysdba to leon; 然后就可以從遠端用 leon 用戶連接上來了. 另外注意, orapwd是linux命令
?? ?另外, 遠程連接時, 如果server端采用動態注冊的話, 那么必須要開啟instance時, 才能動態注冊, 所以, 這樣就沒有辦法
?? ?使用這種遠程連接到沒有開啟instance的數據庫, 所以, 這時需要使用靜態注冊, 才可以遠端來接來sysdba,遠端開啟數據庫
9. dump files
?? ?dmp 文件是獨立于平臺(os), 可以用于重建表, 模式, 甚至整個數據庫, 導入工具的作用就是讀取dmp文件, 執行ddl語句,
?? ?并加載它找到的所有數據. 現在這個已經有被 data pump 取代的形式.
10. data pump files
?? ?IMPDP 和 EXPDP 使用這種文件格式, 使用方法與 IMP 和 EXP 一樣.?? ?

總結

以上是生活随笔為你收集整理的03 Files的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。