SQL> set pages 600 lines 600
SQL> select instance_name,host_name,startup_time,status,database_status from v$instance;
说明:“STATUS”表示Oracle当前的实例状态,必须为“OPEN”;“DATABASE_STATUS”表示Oracle当前数据库的状态,必须为“ACTIVE”。
SQL> select name,log_mode,open_mode from v$database;
SQL> archive log list
说明:两个命令都可以查看。“LOG_MODE”表示Oracle当前的归档方式。“ARCHIVELOG”表示数据库运行在归档模式下,“NOARCHIVELOG”表示数据库运行在非归档模式下。在我们的系统中数据库必须运行在归档方式下。
如没开启归档,需要开启归档,步骤如下:
SQL> shutdown immediate #先关闭数据库
SQL> startup mount #启动数据库到mount状态,必须的
SQL> alter database archivelog; #打开归档
SQL> archive log list; #检查归档状态
SQL> alter database open; #打开数据库
SQL> select instance_name,host_name,startup_time,status,database_status from v$instance;#查看实例状态
SQL> alter system switch logfile; #切换日志
[oracle@cdb1~]$ ps -ef|grep ora_|grep -v grep&&ps -ef|grep ora_|grep -v grep|wc -l
说明:在检查Oracle的进程命令输出后,输出显示至少应包括以下一些进程:
. Oracle写数据文件的进程,输出显示为:“oradbw0_CKDB”
. Oracle写日志文件的进程,输出显示为:“ora_lgwr CKDB”
. Oracle监听实例状态的进程,输出显示为:“orasmon CKDB”
. Oracle监听客户端连接进程状态的进程,输出显示为:“orapmon CKDB”
. Oracle进行归档的进程,输出显示为:“oraarc0 CKDB”
. Oracle进行检查点的进程,输出显示为:“orackpt CKDB”
. Oracle进行恢复的进程,输出显示为:“orareco CKDB”
[oracle@cdb1 ~]$ lsnrctl status
说明:“Services Summary”项表示Oracle的监听进程正在监听哪些数据库实例,
[oracle@cdb1 ~]$ ps -ef|grep lsn|grep -v grep
[root@cdb1 ~]# cat /var/log/messages |grep failed
说明:查看是否有与Oracle用户相关的报错信息
[oracle@cdb1 log]$ cat /u01/app/oracle/diag/rdbms/cdb1/cdb1/trace/alert_cdb1.log |grep ora-
[oracle@cdb1 log]$ cat /u01/app/oracle/diag/rdbms/cdb1/cdb1/trace/alert_cdb1.log |grep err
[oracle@cdb1 log]$ cat /u01/app/oracle/diag/rdbms/cdb1/cdb1/trace/alert_cdb1.log |grep fail
查看重做日志文件
SQL> select group#,members,bytes,status,archived from v$log;
SQL> select status,name from v$controlfile;
说明:“STATUS”应该为空。状态为空表示控制文件状态正常。
SQL> select group#,status,type,member from v$logfile;
说明:输出结果应该有3条以上(包含3条)记录,“STATUS”应该为非“INVALID”,非“DELETED”。注:“STATUS”显示为空表示正常
SQL> select tablespace_name,status from dba_tablespaces;
说明:输出结果中STATUS应该都为ONLINE。
SQL> select name,status from v$datafile;
说明:输出结果中“STATUS”应该都为“ONLINE”。
SQL> select file_name,status from dba_data_files;
输出结果中“STATUS”应该都为“AVAILABLE”。
SQL> select owner,object_name,object_type from dba_objects where status!='VALID' and owner!='SYS' and owner!='SYSTEM';
说明:如果有记录返回,则说明存在无效对象。若这些对象与应用相关,那么需要重新编译生成这个对象
SQL> SELECT owner, object_name, object_type FROM dba_objects WHERE status= 'INVALID';
SQL> select segment_name,status from dba_rollback_segs;
说明:输出结果中所有回滚段的“STATUS”应该为“ONLINE”。
SQL> select count(*) from v$session;
SQL> set pages 600 lines 600
SQL> select sid,serial#,username,program,machine,status from v$session;
说明:SID 会话(session)的ID号;
SERIAL# 会话的序列号,和SID一起用来唯一标识一个会话;
USERNAME 建立该会话的用户名;
PROGRAM 这个会话是用什么工具连接到数据库的;
STATUS 当前这个会话的状态,ACTIVE表示会话正在执行某些任务,INACTIVE表示当前会话没有执行任何操作;
如果建立了过多的连接,会消耗数据库的资源,同时,对一些“挂死”的连接可能需要手工进行清理。如果DBA要手工断开某个会话,则执行:(一般不建议使用这种方式去杀掉数据库的连接,这样有时候session不会断开。容易引起死连接。建议通过sid查到操作系统的spid,使用ps –ef|grep spidno的方式确认spid不是ORACLE的后台进程。使用操作系统的kill -9命令杀掉连接 )
SQL> alter system kill session 'SID,SERIAL#';
SQL> alter system kill session '137,27';
注意:上例中SID为1到10(USERNAME列为空)的会话,是Oracle的后台进程,不要对这些会话进行任何操作。
SQL>select f.tablespace_name,a.total,f.free,round((f.free/a.total)*100) "% Free"
from
(select tablespace_name, sum(bytes/(1024*1024)) total from dba_data_files group by tablespace_name) a,
(select tablespace_name, round(sum(bytes/(1024*1024))) free from dba_free_space group by tablespace_name) f
WHERE a.tablespace_name = f.tablespace_name(+)
order by "% Free";
SQL>select Segment_Name,
Segment_Type, TableSpace_Name, (Extents/Max_extents)*100 Percent
From sys.DBA_Segments
Where Max_Extents != 0 and (Extents/Max_extents)*100>=95
order By Percent;
SQL>select distinct(owner) from dba_tables
where tablespace_name='SYSTEM' and
owner!='SYS' and owner!='SYSTEM'
union
elect distinct(owner) from dba_indexes
where tablespace_name='SYSTEM' and
owner!='SYS' and owner!='SYSTEM';
说明:如果记录返回,则表明system表空间内存在一些非system和sys用户的对象。应该进一步检查这些对象是否与我们应用相关。如果相关请把这些对象移到非System表空间,同时应该检查这些对象属主的缺省表空间值。
SQL>set pages 80
SQL>set lines 120
SQL>col event for a40
SQL>select sid,event,p1,p2,p3,WAIT_TIME,SECONDS_IN_WAIT from v$session_wait where event not like 'SQL%' and event not like 'rdbms%';
说明:如果数据库长时间持续出现大量像latch free,enqueue,buffer busy waits,db file sequential read,db file scattered read等等待事件时,需要对其进行分析,可能存在问题的语句
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 ;
SQL>SELECT * FROM (SELECT * FROM V$SYSTEM_EVENT WHERE EVENT NOT LIKE 'SQL%' ORDER BY TOTAL_WAITS DESC) WHERE ROWNUM<=5;
COLUMN USERNAME FORMAT A12
COLUMN OPNAME FORMAT A16
COLUMN PROGRESS FORMAT A8
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;
SQL> 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);
SQL> 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;
SQL> 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#;
col sid for 999999
col username for a10
col schemaname for a10
col osuser for a16
col machine for a16
col terminal for a20
col owner for a10
col object_name for a30
col object_type for a10
select sid,serial#,username,SCHEMANAME,osuser,MACHINE,
terminal,PROGRAM,owner,object_name,object_type,o.object_id
from dba_objects o,v$locked_object l,v$session s
where o.object_id=l.object_id and s.sid=l.session_id;
处理方式:
oracle级kill掉该session:
alter system kill session '&sid,&serial#';
操作系统级kill掉session:
#>kill -9 pid
SQL> select spid from v$process where addr not in (select paddr from v$session);
SQL> SET LINE 240
SET VERIFY OFF
COLUMN SID FORMAT 999
COLUMN PID FORMAT 999
COLUMN S_# FORMAT 999
COLUMN USERNAME FORMAT A9 HEADING "ORA USER"
COLUMN PROGRAM FORMAT A29
COLUMN SQL FORMAT A60
COLUMN OSNAME FORMAT A9 HEADING "OS USER"
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)) SQL FROM V$PROCESS P, V$SESSION S,V$SQLAREA A WHERE P.ADDR = S.PADDR AND S.SQL_ADDRESS = A.ADDRESS (+) AND P.SPID LIKE '%&1%';
SQL> SELECT a.VALUE + b.VALUE logical_reads,
c.VALUE phys_reads,
round(100*(1-c.value/(a.value+b.value)),4) hit_ratio
FROM v$sysstat a,v$sysstat b,v$sysstat c
WHERE a.NAME='db block gets'
AND b.NAME='consistent gets'
AND c.NAME='physical reads' ;
SQL> select sum(pinhits)/sum(pins)*100 from v$librarycache;
SQL> select name,value from v$sysstat where name like '%sort%';
SQL> select name,value from v$sysstat where name in ('redo entries','redo buffer allocation retries');
SQL> select job,what,last_date,next_date,failures,broken from dba_jobs Where schema_user='CAIKE';
重新JOB的命令
exec sys.dbms_job.remove(1);
commit;
exec
sys.dbms_job.isubmit(1,'REFRESH_ALL_SNAPSHOT;',SYSDATE+1/1440,'SYSDATE+4/1440');
commit;
selectA.tablespace_name,(1-(A.total)/B.total)*100 used_percent
from (select tablespace_name,sum(bytes) total
from dba_free_space group by tablespace_name) A,
(select tablespace_name,sum(bytes) total
from dba_data_files group by tablespace_name) B
where A.tablespace_name=B.tablespace_name;
SQL> select index_name,table_name,tablespace_name,status From dba_indexes Where owner='CTAIS2' And status<>'VALID';
SQL> SELECT owner, constraint_name, table_name, constraint_type, status
FROM dba_constraints
WHERE status ='DISABLE' and constraint_type='P';
SQL> SELECT owner, trigger_name, table_name, status FROM dba_triggers WHERE status = 'DISABLED';
如有失效触发器则启用,如:
SQL>alter Trigger TRIGGER_NAME Enable;
SQL> show parameter spfile;
SQL>show parameter statistics_level; #查看awr是否启用
SQL> ALTER SYSTEM SET statistics_level = ALL SCOPE = BOTH; #启动设置参数
SQL> show parameter statistics_level;#查看awr参数
SQL> select * from dba_hist_wr_control; 查看当前的AWR保存策略
SQL> exec DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT (); #手动生成快照
SQL>select * from sys.wrh$_active_session_history 查看历史快照
SQL>@$ORACLE_HOME/rdbms/admin/awrrpt.sql #生成AWR报告(生成整个库)
------------------------------------------------------------------------------
SQL>@$ORACLE_HOME/rdbms/admin/awrgrpt.sql #生成 Oracle RAC AWR 报告
SQL>@$ORACLE_HOME/rdbms/admin/awrrpti.sql #生成 RAC 环境中特定数据库实例的 AWR 报告
SQL>@$ORACLE_HOME/rdbms/admin/awrgrpti.sql #生成 Oracle RAC 环境中多个数据库实例的 AWR 报告
SQL>@$ORACLE_HOME/rdbms/admin/awrsqrpt.sql #生成 SQL 语句的 AWR 报告
SQL>@$ORACLE_HOME/rdbms/admin/awrsqrpi.sql #生成特定数据库实例上某个 SQL 语句的 AWR 报告
SQL>@$ORACLE_HOME/rdbms/admin/awrddrpt.sql #生成单实例 AWR 时段对比报告
切换到主机目录下,查看html文件即可
SQL> select CHECKPOINT_CHANGE# from v$database;
SQL> select name,file#,checkpoint_change# from v$datafile;
select name,checkpoint_change# from v$datafile_header;
SQL> select name,last_change# from v$datafile;
SQL> select userenv ('language') from dual;
SQL>select'
select dbms_metadata.get_ddl('||''''||'TABLE'||''''||','||''''||table_name||''''||') from dual;'||chr(10)||'select '||''''||'/'||''''|| ' from dual;'
from user_tables;
SQL>select dbms_metadata.get_ddl('USER',u.username) from dba_users u;
create public database link HOconnect to SKDATA identified by oracleusing '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.59.249)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = SYS$USERS)))';
SQL> select * from dba_db_links;
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
[oracle@cdb1 ~]$ rman target /
RMAN> show all;
RMAN> crosscheck archivelog all;
RMAN> crosscheck backup;
RMAN> delete expired archivelog all;
RMAN> delete expired backup;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> run{allocate channel d1 type disk;sql 'alter system archive log current';backup format '/home/oracle/rmanbak/lacgsfull_%U' database include current controlfile plus archivelog ;release channel d1;}
RMAN> list backup of database; #查看备份文件
备份脚本:
[oracle@cdb1 rmanbak]$ cat 1.sh
#!/bin/bash
. ~/.bash_profile
echo -------------------------start-----------------------;
daterman target /<
添加定时任务:
[oracle@cdb1 rmanbak]$ crontab -l
0 1 * * * /home/oracle/rmanbak/rmanbak.sh >rmanbak.log 2>&1
[oracle@cdb1 ~]$ cat del_arch.sh
#!/bin/bash
source ~/.bash_profile
deltime=`date +"20%y%m%d%H%M%S"`
rman target / nocatalog msglog /home/oracle/scripts/del_arch_${deltime}.log<
EOF添加定时任务删除
[root@cdb1 ~]# cat /var/spool/cron/oracle
0 1 * * * /home/oracle/rmanbak/rmanbak.sh >rmanbak.log 2>&1
12 00 * * * /home/oracle/del_arch.sh
SQL> select y.ksppstvl value from sys.x$ksppi x, sys.x$ksppcv y where x.inst_id = userenv('Instance') and y.inst_id = userenv('Instance') and x.indx = y.indx and x.ksppinm like lower('recyclebin');