介绍
在管理Oracle数据库时,我们经常会使用到各种命令,这些命令或长或短。除了经常使用的命令我们能记得住,像那种偶尔会用一次的,很难靠记忆敲出来。为了避免在使用中再次百度找半天,于是就将这些命令写下来了,方便以后查阅。
命令
Linux命令
命令说明  | 命令  | 备注  | 
查看oracle主进程状态  | ps -ef|grep ora_smon  | |
查看1521端口占用情况  | netstat -ntulp |grep 1521  | |
指定当前环境的Oracle实例名(SID)  | export ORACLE_SID=  | ORACLE_SID必须大写  | 
sqlplus命令
命令说明  | 命令  | 备注  | 
以SYSDBA登录到命令窗口  | sqlplus / as sysdba  | |
快速关闭数据库  | shutdown immediate  | 命令窗口执行,建议使用此参数关闭数据库。  | 
立即关闭数据库  | shutdown abort  | 命令窗口执行,非必要,不建议此方式关闭,因为它可能需要介质恢复。  | 
启动数据库至NOMOUNT状态  | startup nomount  | 命令窗口执行,将数据库启动到nomount阶段。  | 
启动数据库至MOUNT状态  | startup mount  | 命令窗口执行,将数据库启动到mount阶段。  | 
以独占模式启动到MOUNT状态  | startup mount exclusive restrict;  | 命令窗口执行  | 
启动数据库  | startup  | 命令窗口执行,将数据库启动到打开阶段,也可以简述为启动数据库。  | 
打开数据库  | alter database open  | 命令窗口执行,将数据库启动到打开阶段。  | 
开启归档模式  | alter database archivelog  | 命令窗口执行  | 
关闭归档模式  | alter database noarchivelog  | 命令窗口执行  | 
RMAN命令
命令说明  | 命令  | 备注  | 
打印数据库的物理架构  | report schema;  | RMAN命令行执行  | 
打印全部备份集信息  | list backup;  | RMAN命令行执行  | 
打印所有数据文件的备份集信息  | list backup of database;  | RMAN命令行执行  | 
打印特定表空间的备份集信息  | list backup of tablespace 表空间名;  | RMAN命令行执行  | 
打印控制文件的备份集信息  | list backup of controlfile;  | RMAN命令行执行  | 
打印归档日志的备份集信息  | list backup of archivelog all;  | RMAN命令行执行  | 
打印spfile备份集  | list backup of spfile;  | RMAN命令行执行,该参数与列出控制文件一样,因为新版中备份会将控制文件和spfile文件一块备份。  | 
打印数据库化身  | list incarnation of database;  | RMAN命令行执行  | 
打印数据库的归档日志  | list archivelog all  | RMAN命令行执行  | 
静默删除指定备份集  | delete noprompt backupset 16;  | RMAN命令行执行  | 
静默删除所有归档日志  | delete noprompt archivelog all;  | RMAN命令行执行  | 
删除指定天数前的归档日志  | delete archivelog until time 'sysdate-7';  | RMAN命令行执行  | 
删除sequence小于等于指定值的归档日志  | delete archivelog until sequence 1150;  | RMAN命令行执行  | 
删除与控制文件信息不匹配的归档日志  | delete expired archivelog all;  | 通常用在先在OS上删除归档,但控制文件信息不认为这些归档已被删除。  | 
srvctl命令
srvctl是RAC集群管理使用的命令。
说明  | 命令  | 备注  | 
查看集群中所有数据库运行状态  | srvctl status database -d database_name -v  | |
启动集群中所有数据库实例  | srvctl start database -d database_name  | |
停止集群中所有数据库实例  | srvctl stop database -d database_name  | |
查看集群中监听运行状态  | srvctl status listener  | |
启动集群中的监听  | srvctl stop listener  | |
停止集群中的监听  | srvctl start listener  | |
查看集群中节点级应用程序的运行状态  | srvctl status nodeapps  | VIP,Network,GSD,ONS  | 
查看集群中ASM的运行状态  | srvctl status asm  | 
sql命令
查询等待事件
select s.sid, s.SERIAL#, p.SPID,
       sl.SQL_ID, s.EVENT,
       s.P1TEXT, s.P1,
       s.p2TEXT, s.P2,
       s.p3TEXT, s.P3,
       sl.SQL_FULLTEXT
from v$session s, v$process p, v$sql sl
where  s.PADDR = p.ADDR
and s.STATUS = 'ACTIVE'
and s.SQL_ID = sl.SQL_ID;查询锁表
select s.sid, s.serial#, s.machine, s.program,
       lo.os_user_name, lo.oracle_username,
       do.object_name, lo.locked_mode
from v$session s,v$locked_object lo,dba_objects do
where s.sid = lo.session_id
and lo.object_id = do.object_id;查询30天内的redo log切换频率
select to_char(lh.first_time, 'YYYY/MM/DD') times,
to_char(lh.first_time,'day') day,
round((count(*)/24),2) avg_per_hour,
count(*) total ,
sum(case to_char(first_time, 'HH24') when '00' then 1 else 0 end ) h00,
sum(case to_char(first_time, 'HH24') when '01' then 1 else 0 end ) h01,
sum(case to_char(first_time, 'HH24') when '02' then 1 else 0 end ) h02,
sum(case to_char(first_time, 'HH24') when '03' then 1 else 0 end ) h03,
sum(case to_char(first_time, 'HH24') when '04' then 1 else 0 end ) h04,
sum(case to_char(first_time, 'HH24') when '05' then 1 else 0 end ) h05,
sum(case to_char(first_time, 'HH24') when '06' then 1 else 0 end ) h06,
sum(case to_char(first_time, 'HH24') when '07' then 1 else 0 end ) h07,
sum(case to_char(first_time, 'HH24') when '08' then 1 else 0 end ) h08,
sum(case to_char(first_time, 'HH24') when '09' then 1 else 0 end ) h09,
sum(case to_char(first_time, 'HH24') when '10' then 1 else 0 end ) h10,
sum(case to_char(first_time, 'HH24') when '11' then 1 else 0 end ) h11,
sum(case to_char(first_time, 'HH24') when '12' then 1 else 0 end ) h12,
sum(case to_char(first_time, 'HH24') when '13' then 1 else 0 end ) h13,
sum(case to_char(first_time, 'HH24') when '14' then 1 else 0 end ) h14,
sum(case to_char(first_time, 'HH24') when '15' then 1 else 0 end ) h15,
sum(case to_char(first_time, 'HH24') when '16' then 1 else 0 end ) h16,
sum(case to_char(first_time, 'HH24') when '17' then 1 else 0 end ) h17,
sum(case to_char(first_time, 'HH24') when '18' then 1 else 0 end ) h18,
sum(case to_char(first_time, 'HH24') when '19' then 1 else 0 end ) h19,
sum(case to_char(first_time, 'HH24') when '20' then 1 else 0 end ) h20,
sum(case to_char(first_time, 'HH24') when '21' then 1 else 0 end ) h21,
sum(case to_char(first_time, 'HH24') when '22' then 1 else 0 end ) h22,
sum(case to_char(first_time, 'HH24') when '23' then 1 else 0 end ) h23
from v$log_history lh
where (sysdate-lh.FIRST_TIME) <30
group by to_char(first_time, 'YYYY/MM/DD'),
to_char(lh.first_time,'day')
order by times desc;查询数据库中的所有系统视图及描述
select * from dictionary;









