ORACLE 日常维护命令手册
1查看数据库版本
SELECT * FROM V$VERSION;
2查看数据库语言环境
SELECT USERENV('LANGUAGE') FROM DUAL;
3查看ORACLE实例状态
SELECT INSTANCE_NAME,HOST_NAME,STARTUP_TIME,STATUS,DATABASE_STATUS
FROM V$INSTANCE;
4查看ORACLE监听状态
lsnrctl status
5查看数据库归档模式
SELECT NAME,LOG_MODE,OPEN_MODE FROM V$DATABASE;
6查看回收站中对象
SELECT OBJECT_NAME,ORIGINAL_NAME,TYPE FROM RECYCLEBIN;
7清空回收站中对象
PURGE RECYCLEBIN;
8还原回收站中的对象
FLASHBACK TABLE "BIN$GOZUQZ6GS222JZDCCTFLHQ==$0" TO BEFORE DROP RENAME TO TEST;
9闪回误删除的表
FLASHBACK TABLE AAA TO BEFORE DROP;
10闪回表中记录到某一时间点
ALTER TABLE TEST ENABLE ROW MOVEMENT;
FLASHBACK TABLE TEST TO TIMESTAMP TO_TIMESTAMP('2009-10-15 21:17:47','YYYY-MM-DD HH24:MI:SS');
11查看当前会话
SELECT SID,SERIAL#,USERNAME,PROGRAM,MACHINE,STATUS FROM V$SESSION;
12查看DDL锁
SELECT *
FROM DBA_DDL_LOCKS
WHERE OWNER = 'FWYANG';
13检查等待事件
SELECT SID, A.USERNAME, EVENT, WAIT_CLASS, T1.SQL_TEXT
FROM V$SESSION A, V$SQLAREA T1
WHERE WAIT_CLASS <> 'Idle'
AND A.SQL_ID = T1.SQL_ID;
14检查数据文件状态
SELECT FILE_NAME,STATUS FROM DBA_DATA_FILES;
15检查表空间使用情况
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100, 2),
'990.99') "使用比",
F.TOTAL_BYTES "空闲空间(M)",
F.MAX_BYTES "最大块(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 4 DESC;
16收缩表空间
ALTER TABLESPCE TS_AJ_DATA COALESCE;
17增加表空间大小
SELECT T.TABLESPACE_NAME, T.FILE_NAME, T.BYTES / 1024 / 1024 / 1024
FROM DBA_DATA_FILES T
WHERE T.TABLESPACE_NAME = 'TS_AJ_DATA';
ALTER TABLESPACE TS_AJ_DATA ADD DATAFILE '/DATA/TS_AJ_DATA05_10G.DBF'
SIZE 10000M
AUTOEXTEND OFF;
18检查不起作用的约束
SELECT OWNER, CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE, STATUS
FROM DBA_CONSTRAINTS
WHERE STATUS = 'DISABLE';
19检查发生坏块的数据库对象
SELECT TABLESPACE_NAME, SEGMENT_TYPE, OWNER, SEGMENT_NAME
FROM DBA_EXTENTS
WHERE FILE_ID = < AFN >
AND < BLOCK > BETWEEN BLOCK_ID AND BLOCK_ID + BLOCKS - 1;
20检查无效的数据库对象
SELECT OWNER,OBJECT_NAME,OBJECT_TYPE
FROM DBA_OBJECTS
WHERE STATUS ='INVALID';
21查看语句执行进度
SELECT SE.SID,
OPNAME,
TRUNC(SOFAR / TOTALWORK * 100, 2) || '%' AS PCT_WORK,
ELAPSED_SECONDS ELAPSED,
ROUND(ELAPSED_SECONDS * (TOTALWORK - SOFAR) / SOFAR) REMAIN_TIME,
SQL_TEXT
FROM V$SESSION_LONGOPS SL, V$SQLAREA SA, V$SESSION SE
WHERE SL.SQL_HASH_VALUE = SA.HASH_VALUE
AND SL.SID = SE.SID
AND SOFAR != TOTALWORK
ORDER BY START_TIME;
22检查碎片程度高的表
SELECT SEGMENT_NAME TABLE_NAME, COUNT(*) EXTENTS
FROM DBA_SEGMENTS
WHERE OWNER NOT IN ('SYS', 'SYSTEM')
GROUP BY SEGMENT_NAME
HAVING COUNT(*) = (SELECT MAX(COUNT(*))
FROM DBA_SEGMENTS
GROUP BY SEGMENT_NAME);
23检查表空间的 I/O 比例
SELECT DF.TABLESPACE_NAME NAME,
DF.FILE_NAME "FILE",
F.PHYRDS PYR,
F.PHYBLKRD PBR,
F.PHYWRTS PYW,
F.PHYBLKWRT PBW
FROM V$FILESTAT F, DBA_DATA_FILES DF
WHERE F.FILE# = DF.FILE_ID
ORDER BY DF.TABLESPACE_NAME;
24检查碎片程度高的表
SELECT segment_name table_name, COUNT(*) extents
FROM dba_segments
WHERE owner NOT IN ('SYS', 'SYSTEM')
GROUP BY segment_name
HAVING COUNT(*) = (SELECT MAX(COUNT(*))
FROM dba_segments
GROUP BY segment_name);
25检查文件系统的 I/O 比例
SELECT SUBSTR(A.FILE#, 1, 2) "#",
SUBSTR(A.NAME, 1, 30) "NAME",
A.STATUS,
A.BYTES,
B.PHYRDS,
B.PHYWRTS
FROM V$DATAFILE A, V$FILESTAT B
WHERE A.FILE# = B.FILE#;
26检查消耗CPU最高的进程
SELECT P.PID PID,
S.SID SID,
P.SPID SPID,
S.USERNAME USERNAME,
S.OSUSER OSNAME,
P.SERIAL# S_#,
P.TERMINAL,
P.PROGRAM PROGRAM,
P.BACKGROUND,
S.STATUS,
RTRIM(SUBSTR(A.SQL_TEXT, 1, 80)) SQLFROM
FROM V$PROCESS P, V$SESSION S, V$SQLAREA A
WHERE P.ADDR = S.PADDR
AND S.SQL_ADDRESS = A.ADDRESS(+)
AND P.SERIAL# <> '1';
27检查运行很久的SQL
SELECT USERNAME,
SID,
OPNAME,
ROUND(SOFAR * 100 / TOTALWORK, 0) || '%' AS PROGRESS,
TIME_REMAINING,
SQL_TEXT
FROM V$SESSION_LONGOPS, V$SQL
WHERE TIME_REMAINING <> 0
AND SQL_ADDRESS = ADDRESS
AND SQL_HASH_VALUE = HASH_VALUE;
28等待时间最多的5个系统等待事件的获取
SELECT *
FROM (SELECT *
FROM V$SYSTEM_EVENT
WHERE EVENT NOT LIKE 'SQL%'
ORDER BY TOTAL_WAITS DESC)
WHERE ROWNUM <= 5;
29查找前十条性能差的SQL
SELECT *
FROM (SELECT PARSING_USER_ID EXECUTIONS,
SORTS,
COMMAND_TYPE,
DISK_READS,
SQL_TEXT
FROM V$SQLAREA
ORDER BY DISK_READS DESC)
WHERE ROWNUM < 10;
30检查死锁
SELECT bs.username "Blocking User", bs.username "DB User",
ws.username "Waiting User", bs.SID "SID", ws.SID "WSID",
bs.serial# "Serial#", bs.sql_address "address",
bs.sql_hash_value "Sql hash", bs.program "Blocking App",
ws.program "Waiting App", bs.machine "Blocking Machine",
ws.machine "Waiting Machine", bs.osuser "Blocking OS User",
ws.osuser "Waiting OS User", bs.serial# "Serial#",
ws.serial# "WSerial#",
DECODE (wk.TYPE,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'USER Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL USER LOCK',
'DX', 'Distributed Xaction',
'CF', 'Control FILE',
'IS', 'Instance State',
'FS', 'FILE SET',
'IR', 'Instance Recovery',
'ST', 'Disk SPACE Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'LOG START OR Switch',
'RW', 'ROW Wait',
'SQ', 'Sequence Number',
'TE', 'Extend TABLE',
'TT', 'Temp TABLE',
wk.TYPE
) lock_type,
DECODE (hk.lmode,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (hk.lmode)
) mode_held,
DECODE (wk.request,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (wk.request)
) mode_requested,
TO_CHAR (hk.id1) lock_id1, TO_CHAR (hk.id2) lock_id2,
DECODE
(hk.BLOCK,
0, 'NOT Blocking', /**//* Not blocking any other processes */
1, 'Blocking', /**//* This lock blocks other processes */
2, 'Global', /**//* This lock is global, so we can't tell */
TO_CHAR (hk.BLOCK)
) blocking_others
FROM v$lock hk, v$session bs, v$lock wk, v$session ws
WHERE hk.BLOCK = 1
AND hk.lmode != 0
AND hk.lmode != 1
AND wk.request != 0
AND wk.TYPE(+) = hk.TYPE
AND wk.id1(+) = hk.id1
AND wk.id2(+) = hk.id2
AND hk.SID = bs.SID(+)
AND wk.SID = ws.SID(+)
AND (bs.username IS NOT NULL)
AND (bs.username <> 'SYSTEM')
AND (bs.username <> 'SYS')
ORDER BY 1;
31查看正在运行的JOB
SELECT * FROM DBA_JOBS_RUNNING;
32检查数据库JOB的完成情况
SELECT JOB, LOG_USER, LAST_DATE, NEXT_DATE, WHAT, FAILURES
FROM DBA_JOBS;
33查看正在运行的JOB对应的SID、SERIAL#、SPID
SELECT A.JOB, B.SID, B.SERIAL#, C.SPID
FROM DBA_JOBS_RUNNING A, V$SESSION B, V$PROCESS C
WHERE A.SID = B.SID
AND B.PADDR = C.ADDR
AND JOB = '21';
34通过SID查询SERIAL#、SPID
SELECT B.SID, B.SERIAL#, C.SPID
FROM V$SESSION B, V$PROCESS C
WHERE B.SID = '554'
AND B.PADDR = C.ADDR;
35停止会话
--SID:554 SERIAL#:1134 SPID:23242
ORACLE级别:
ALTER SYSTEM KILL SESSION '554,1134';
操作系统级别:
kill -9 23242
转自 https://blog.csdn.net/sunbocong/article/details/80044982
ORACLE 日常维护命令手册的更多相关文章
- 程序员必备:Oracle日常维护命令
上一篇讲了Linux的日常维护命令,这篇讲讲Oracle的日常维护命令.工作中需要使用Oracle数据库的童鞋们,相信或多或少都需要对Oracle做一些基本的维护操作,例如导入导出总该有吧?( ...
- 2.goldengate日常维护命令(转载)
goldengate日常维护命令 发表于 2013 年 7 月 4 日 由 Asysdba 1.查看进程状态 GGSCI (PONY) 2> info all 2.查看进程详细状态,有助于排错 ...
- svn服务配置和日常维护命令
Subversion独立服务和与apache整合服务. 一 .Svn独立服务安装 操作系统: Redhat Linux AS3 AS 4 ContOS AS 4 安装包获取: 下载[url]ht ...
- mha日常维护命令
mha日常维护命令 http://m.blog.chinaunix.net/uid-28437434-id-3959021.html?/13033.shtml 1.查看ssh登陆是否成功masterh ...
- MHA 日常维护命令集
MHA 日常维护命令集 1.查看ssh登陆是否成功 masterha_check_ssh --global_conf=/etc/masterha/masterha_default.conf --con ...
- MQ日常维护操作手册
假设队列管理器为QMgrName,以下所有使用QMgrName的地方您都可以替换成您维护的mq队列管理器名称. 一.MQ的启动与停止 用root用户启/停需要root用户包含在mqm组中. 1.MQ的 ...
- ORACLE 12c RAC日常维护命令
转至:https://blog.51cto.com/ixdba/901545 CRS提供了很多命令可以管理和查看集群服务状态,常用的有crs_stat.crs_start.crs_stop.crsct ...
- RAC日常维护命令
olsnodes -n 查看节点个数 crs_stat -t 查看RAC中各节点的资源状态 crs_stat -p 查看RAC的节点的配置 crsctl命令: 对于crsctl命 ...
- Oracle日常维护脚本
1.正常停库流程 ps -ef|grep LOCAL=NO|cut -c 9-15|xargs kill -9 shutdown immediate; 2.备份数据库 bac ...
随机推荐
- OSGi.NET使用笔记
一手资料来源于“开放工厂”,以下程序将会引用到一个核心文件UIShell.OSGi.dll 目前我对于OSGi这个框架的理解就是,主程序搜索并加载插件,以插件方式开放,便于扩展. 现在开始正式的旅程. ...
- switch的练习
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- [转]C#截获本机数据包方法实例
本文向大家介绍Windows Sockets的一些关于用C#实现的原始套接字(Raw Socket)的编程,以及在此基础上实现的网络封包监视技术.同Winsock1相比,Winsock2最明显的就是支 ...
- 切换默认jdk版本执行
Java代码 # cd /usr/bin # ln -s -f /usr/java/jdk1.6.0_24/jre/bin/java # ln -s -f /usr/java/jdk1.6.0_24/ ...
- stringstream的使用 UVA 10815
水题题目描述就不写了 主要是发现stringstream真的是好用,可以把string绑定到stringstream中,然后就能以空格为分隔符分割出每个单词,听说每次重新创建stringstream开 ...
- Leetcode264. Ugly Number II丑数2
编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 ...
- TZ_02MyBatis_一级缓存和二级缓存
1.Mybatis中的缓存 1>什么是缓存 存在于内存中的临时数据. 2> 为什么使用缓存 减少和数据库的交互次数,提高执行效率. 3>什么样的数 ...
- ActiveMQ消息中间件
最近学习到ActiveMQ,之前也没有用过相关或者类似的工具,因此特地写个文章进行相关的学习记录. 相关参考博文:https://www.cnblogs.com/cyfonly/p/6380860.h ...
- Comparator进行List集合排序
对数据库中查询到的结果进行排序,一般开发中,实体类是没有实现Comparable接口的,所以不能实现compareTo()方法进行排序, 只能用Comparator去进行排序,只需要在带排序的集合中加 ...
- 2019.7.27 NOIP模拟测试9 反思总结
先来整理题目 T1题目大意:给出n个数字和一个质数作为模数,一个变量x初始值为1.进行m次操作,每次让x随机乘上n个数中的一个,问m次操作以后x的期望值. 答案一定可以用分数表示,输出分子乘分母逆元的 ...