最常用的
執行 sqlplus "/as sysdba" 以系統管理者進入資料庫
關閉資料庫: shutdown immediate
啟動資料庫 startup
--<em>oracle</em> 常用sql
--查詢資料庫資訊
select * from v$database;
--查詢目前執行個體資訊
select * from v$instance;
--查詢資料庫版本資訊
select * from v$version;
--查詢所有使用者(dba權限)
select * from dba_users;
--查詢共享記憶體中的sql資訊,執行較慢
select hash_value from v$sqltext where sql_text like '%查詢sql%';
select sql_text from v$sqltext where hash_value =查找的hash_value order by hash_value,piece;
--查詢目前系統表空間存儲資訊
select a.file_id,a.file_name, a.TABLESPACE_NAME,a.bytes/1024/1024||'M' as totalspace,
nvl(b.freespace,0)||'M' as freespace,a.autoextensible from dba_data_files a,
(select sum(bytes)/1024/1024 as freespace,file_id,tablespace_name from dba_free_space
group by tablespace_name,file_id ) b
where a.file_id=b.file_id(+)
order by a.tablespace_name,file_name;
--統計已占用的表空間
select sum(a.bytes/1024/1024-nvl(b.freespace,0))||'M' from dba_data_files a,
where a.file_id=b.file_id(+) and a.tablespace_name='tablespace名稱'
--查詢目前活動session最近一次執行的sql
select sql_text from v$sqltext where hash_value=(
select PREV_HASH_VALUE from v$session where status='ACTIVE' and username is not null ) order by piece
--查詢相關使用者的索引情況
select a.*,b.column_name,b.column_length from
(select owner,index_name,table_name,index_type,tablespace_name
from dba_indexes where owner ='使用者名' and index_name not in
(select constraint_name from dba_constraints where owner='使用者名' and constraint_type in ('P','R'))
)a,(select * from dba_ind_columns b where index_owner='使用者名') b
where a.index_name=b.index_name
order by a.owner,a.table_name,a.index_name
--重建索引
alter index 索引名稱 rebuild nologging;
--檢視事務復原率
select name,value from v$sysstat where name in('user commits','transaction rollbacks');
--sql分析優化
--腳本位置${oracle_home}/rdbms/admin/utlxplan.sql 建立執行計劃表
--授權通路
create public synonym plan_table for plan_table;
grant select,update,insert,delete on plan_table to public;
--腳本位置${oracle_home}/sqlplus/admin/plustrce.sql 執行授權角色
--spfile
--資料庫建庫完成後,第一次
手工啟動手工建立spfile檔案,指令格式為
create spfile[='filename'] from pfile[='filename'];
--判斷是采用spfile還是pfile啟動資料庫的,可以下面sql根據是那種方式<P>###NextPage###</P>
select decode(count(*),0,'pfile',1,'spfile') from V$spparameter where isspecified='TRUE' and rownum=1;
--spfile,pfile建立預設位置為$ORACLE_HOME/dbs/,$ORACLE_HOME/database/(windows)
--啟動時公司搜尋預設位置下spfile.ora,spfile$ORACLE_SID.ora,init$ORACLE_SID.ora
--采用指定的方式啟動
startup pfile='filename';
--建立spfile,pfile可以在資料庫關閉後仍然可以建立
--如果pfile内有spfile檔案參數的設定,采用pfile方式啟動後還可以修改初始參數到spfile中
--<em>oracle</em>9.2.0.1版本後建立資料庫時系統會自動建立spfile,預設的啟動方式就是采用spfile
--運作時間spfile檔案沒有鎖定
--修改密碼
alter user username identified by newpassword;
--oracle9i 驗證方式有兩種,可以在sqlnet.ora中配置
SQLNET.AUTHENTICATION_SERVICES=(NTS) --作業系統驗證,無須使用者輸入密碼
SQLNET.AUTHENTICATION_SERVICES=(none) --用正确的使用者和密碼驗證
--設定密碼級别 remote_login_passwordfile
--設定為exclusive,表示密碼檔案由一個資料庫使用,遠端用戶端可以用sys登陸(如果密碼檔案删除後,遠端無法登陸)
--設定為shared,表示多個資料庫可以共享一個密碼檔案,但是隻可以識别一個使用者SYS,不能将sysdba權限授權給其他使用者
--設定為none,表示沒有密碼檔案 遠端無法用sys登陸,隻能通過作業系統驗證方式
--密碼檔案如果丢失或損壞,系統無法啟動
--可以手工建立<em>oracle</em>系統密碼
orapwd file=<fname> password=<password> entries=<users>
entries --sysdba連結最大數
--密碼檔案沒有鎖定,隻是啟動時的引導作用
V$SYSTEM_EVENT 資料庫執行個體整個運作期間所有程序事件的等待時間、次數視圖,作為系統優化的依據
等待事件分為三種類型 空閑等待、例行等待、資源等待
注意很多時候程序是空閑等待處理的,是以在該視圖主要檢視資源等待時間,
如果是程序在例行操作中等待,可以檢視該事件的平均等待時間
--v$session_wait
--常見的空閑等待事件:client message、null event、pipe get、pmon/smon timer、rdbms rpc message及sql*net等;
--常見的非等閑事件:
buffer busy waits、
db file scattered read、
db file sequential read、
enqueue、
free buffer waits、
latch free、
log file sync、
log file paralle write
導
入導出建議一定要同版本的導入導出工具
常見錯誤 exp-00003
估算導出dmp檔案大小
select sum(bytes) from user_segments where segment_type='TABLE';
這個計算結果不包含LOB, 和VARRAY, 亦不含分區表資料
--設定歸檔模式
startup mount;
alter database archivelog;
alter database open;
alter system set log_archive_start=true scope=spfile;
shutdown immediate
startup;
資料庫已經誤删除資料檔案,如何啟動
startup mount
alter database datafile 'filepos' offline drop;(noarchivelog)
alter database datafile 'filepos' offline;(archivelog)
drop tablespace 'spacename' including contents;
log_miner的使用
--檢視聯機日志資訊
select a.group#,b.member, sequence#,first_change# from v$log a ,v$logfile b
where a.group#=b.group#;
v$rollstat三個字段說明
rssize 復原段大小
optsize optimal大小
hwmsize 你的復原段曾經最高大小
--統計目前復原段大小、最高峰大小
select sum(rssize)/1024/1024||'M',sum(hwmsize/1024/1024)||'M'
from v$rollstat;
--檢視事務占用的復原段大小(事務尚未送出)
select b.used_ublk,b.xidusn,a.sid from v$session a,v$transaction b
where a.taddr=b.addr;
--檢視作業系統硬體資訊
prtdiag -v
--臨時表空間為空
錯誤号ORA-25153:
alter tablespace 表空間名 add tempfile '檔案名' size 檔案大小;
建立臨時表空間
create temporary tablespace 新表空間名 tempfile '檔案名' size 檔案大小;
alter database default temporary tablespace 新表空間名;
drop tablespace 舊空間名 including contents;
rman資料檔案損壞恢複腳本
--資料檔案損壞
run{
allocate channel c1 type disk;
restore datafile 資料檔案号;
recover datafile 資料檔案号;
release channel c1;
}
一次控制檔案損壞,恢複過程
故意修改控制檔案,出現ora-00205錯誤
在rman下恢複控制檔案
restore controlfile from file='最近的一次控制檔案備份'
在alter database open resetlogs 出現
ORA 1152 file <name> was not restored from a sufficiently old backup 錯誤
不行
然後在rman下從自動檔案恢複
restore controlfile from autobackup;
啟動仍然出現該錯誤,
通過rman恢複database也不行,
最後沒辦法,采用
ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
然後根據trc檔案中的指導
采用第二種方式也不行,隻能采用第一種建立
在資料庫nomount狀态下
執行trc相關 腳本
alter dat
abase open;
資料庫啟動正常
本文轉自xiaocao1314051CTO部落格,原文連結:http://blog.51cto.com/xiaocao13140/1931691 ,如需轉載請自行聯系原作者