【正文】
? Explain database files: data files, control files, online redo logs ? Explain SGA memory structures: DB buffer cache, shared SQL pool, and redo log buffer ? Explain primary background processes: DBW0, LGWR, CKPT, PMON, SMON, and ARC0 ? Explain SQL processing steps: parse, execute, fetch 數(shù)據(jù)字典 數(shù)據(jù)字典 Data Dictionary ? 數(shù)據(jù)字典 – 數(shù)據(jù)字典是 Oracle數(shù)據(jù)庫的重要組成。 – 包括: ? 數(shù)據(jù)庫所有對象的定義(表,視圖,索引,簇,同義詞,序列 ,過程,函數(shù),程序包,觸發(fā)器) ? 空間的分配和使用狀況 ? 列的缺省值 ? 完整性約束信息 ? 用戶名 ? 已授予用戶的角色和權(quán)限 ? 審計(jì)信息等 ? 數(shù)據(jù)字典結(jié)構(gòu) – 基表 ? 存放相關(guān)數(shù)據(jù)庫信息的基礎(chǔ)表 – 視圖 ? 匯總并顯示存放數(shù)據(jù)字典基表中信息的視圖 ? 數(shù)據(jù)字典所有者 – Oracle的 sys用戶擁有數(shù)據(jù)字典所有的基表和視圖。不能更新、插入、 刪除。 – 系統(tǒng)管理員需要嚴(yán)格管理系統(tǒng)用戶 .(sys and system) 數(shù)據(jù)字典分類 – USER_* :用戶擁有的對象 – ALL_*: 可訪問的對象 – DBA_*: 所有對象 . 93個(gè) – 118個(gè) – 165個(gè) –從 DICTIONARY( DICT)中可查到名稱 常用的數(shù)據(jù)字典 Dba_tablespaces Dba_data_files Dba_tables Dba_users Dba_views Dba_indexes Dba_db_links Dba_free_space Dba_ind_columns Dba_jobs Dba_objects Dba_rollback_segs Dba_segments Dba_sequences Dba_snappshots Dba_synonyms Dba_tab_columns Dba_triggers Dba_constraints Dba_cons_columns 前綴 范圍 USER 用戶視圖 ALL 用戶可訪問的部分 DBA 數(shù)據(jù)庫管理員視圖 PL*SQL PL*SQL – SQL是結(jié)構(gòu)化的查詢語言 ? Oracle的 SQL語言包含對 ANSI/ISO標(biāo)準(zhǔn) SQL語言的擴(kuò)充。 – PL*SQL ? 是 Oracle的一種過程化的SQL語言。通過PL*SQL語言,能夠?qū)憯?shù)據(jù)庫的存儲過程和包。 Oracle SQL, SQL*Plus and PL*SQL ? DML – Select (從一個(gè)或多個(gè)表或視圖中檢索數(shù)據(jù) ) select empno,ename,sal,deptno from emp where deptno=10。 – having 子句 select deptno,min(sal),max(sal) from emp where job=‘ CLERK’ group by deptno having min(sal)1000。 – for upfate select empno,sal,m from emp,dept where job=‘ CLERK’ and = and loc=‘ NEW YORK’ for update。 – join select empno,ename,dname from emp,dept where =。 – Insert (向表與視圖中增加新行 ) insert into emp values(8888,‘ abc’ ,‘ clerk’ ,0000,sysdate,2023,0,10)。 ? 不支持 select into ,要用 create as create table as select * from tablename 常用的 sql函數(shù) ? number function – abs(n) – mod(m,n) – power(m,n) – round(m,n) – sign(n) – sort(n) 開平方 – trunc(n,m) ? Date function – ADD_MONTHS(d,n) – LAST_DAY(d) – MONTHS_BETWEEN(d1, d2) – NEXT_DAY(d, char) – SYSDATE ... ? Conversion Functions – TO_CHAR(d ,format) – TO_CHAR(n ,format) – TO_NUMBER – TO_DATE ? character function – CONCAT(char1, char2) / *返回 char1與 char2的連接 */ – INITCAP(char) /* 返回第一個(gè)字母大寫的 string */ – LPAD(char1,n [,char2]) – LTRIM(char [,set]) – LOWER – REPLACE(char,search_string[,replacement_string]) – SUBSTR(char, m [,n]) – INSTR (char1,char2 [,n[,m]]) – UPPER(char) – LENGTH(char) ... ? 其它函數(shù) – NVL(expr1, expr2) – USER ... SQL*Plus SQLPlus 是 Oracle 的一個(gè)實(shí)用程序 . ? sql*plus的使用: –數(shù)據(jù)庫創(chuàng)建后,將安裝 scott/tiger的 demo用戶。 either list them alphabetically or group them by functionality. Starting the Instance Usually you would start an instance without mounting a database only during database creation or the recreation of control files. Starting an instance includes the following tasks: ? Reading the parameter file init ? Allocating the SGA ? Starting the background processes ? Opening the ALERT file and the trace files The database must be named with the DB_NAME parameter either in the init file or in the STARTUP mand. Mounting the Database To perform specific maintenance operations, you start an instance and mount a database but do not open the database. For example, the database must be mounted but not open during the following tasks: ? Renaming data files ? Enabling and disabling redo log archiving options ? Performing full database recovery Mounting a database includes the following tasks: ? Associating a database with a previously started instance ? Locating and opening the control files specified in the parameter file ? Reading the control files to obtain the names and status of the data files and redo log files (However, no checks are performed to verify the existence of the data files and online redo log files at this time.) Opening the Database Normal database operation means that an instance is started and the database is mounted and open。 – Open the database as a readonly database: ALTER DATABASE database OPEN READ ONLY。 控制文件與一個(gè)數(shù)據(jù)庫有關(guān) 應(yīng)該復(fù)用以防止文件丟失 控制文件的內(nèi)容 數(shù)據(jù)庫名 數(shù)據(jù)文件位置 重作日志位置 表空間名 當(dāng)前日志文件順序號 檢查點(diǎn)信息 日志歷史 備分信息 影響控制文件大小的參數(shù) ? 控制文件的大小受下列參數(shù)影響 : – MAXLOGFILES – MAXLOGMEMBERS – MAXLOGHISTORY – MAXDATAFILES – MAXINSTANCES – CONTROL_FILE_RECORD_KEEP_TIME 獲取控制文件的信息 V$CONTROLFILE NAME V$PARAMETER NAME ( control_file) VALUE V$CONTROLFILE_RECORD_SECTION TYPE RECORDS_SIZE RECORDS_TOTAL RECORDS_USED 控制文件使用的原則 –復(fù)用控制文件 –在 CONTROL_FILES 中包含完全路徑 –在數(shù)據(jù)庫結(jié)構(gòu)發(fā)生變化時(shí)備份控制文件 復(fù)用控制文件 control_files=(/DISK1/,/DISK2/) 常見問題 改變控制文件的位置 1. 正常關(guān)閉數(shù)據(jù)庫 2. 將控制文件從當(dāng)前位置依到新的位置 3. 修改 control_file參數(shù) . 4. 啟動數(shù)據(jù)庫 常見問題 一個(gè)控制文件丟失 可關(guān)閉數(shù)據(jù)庫復(fù)制好的控制文件 所有控制文件丟失 ,重建控制文件 svrmgrl startup mount svrmgrl alter database backup controlfile to trace 編輯 udump下的 TRACE文件 執(zhí)行文件 管理表空間和數(shù)據(jù)文件 課程目標(biāo) 了解數(shù)據(jù)庫的邏輯結(jié)構(gòu) 建立表空間 利用幾種方法改變表空間的大小 改變表空間的狀態(tài)和存儲參數(shù) 改變數(shù)據(jù)文件位置 準(zhǔn)備需要的表空間 表空間 ? 表空間由一組數(shù)據(jù)文件組成 ? 每個(gè)數(shù)據(jù)文件屬于一個(gè)表空間 ? 每個(gè)表,索引,分區(qū)和所有其他的段均屬于一個(gè)表空間但可以跨表空間的多個(gè)數(shù)據(jù)文件 SYSTEM 和非 SYSTEM 表空間 SYSTEM 表空間包含 : ? 數(shù)據(jù)字典信息 ? SYSTEM 回滾段 非 SYSTEM表空間包含 : ? 回滾段 ? 臨時(shí)段 ? 應(yīng)用數(shù)據(jù) ? 應(yīng)用索引 臨時(shí)表空間 用于排序操作 不能包含永久性數(shù)據(jù) CREATE TABLESPACE sort DATAFILE ?DISK2/?SIZE 50M MINIMUM EXTENT 1M DEFAULT STORAGE (INITIAL 2M NEXT 2M MAXEXTENTS 500 PCTINCREASE 0) TEMPORARY。 建立表空間 CREATE TABLESPACE app_data DATAFILE ?DISK4/?SIZE 100M,