一、基础运维命令
select sys_context('USERENV','CURRENT_USER');
select sys_context('USERENV','SID');
select * from v$sessions where state='ACTIVE';
SELECT * FROM V$ARCH_STATUS;
SELECT DISTINCT TYPE FROM V$PARAMETER;
SELECT TOP 5 NAME,VALUE FROM V$PARAMETER;
SELECT TOP 5 PARA_NAME,PARA_VALUE FROM V$DM_INI;
SELECT A.ID,A.NAME,A.TYPE,A.VALUE,A.SYS_VALUE,A.FILE_VALUE
FROM SYS."V$PARAMETER" A WHERE A.NAME='COMPATIBLE_MODE';
#修改状态为2
SP_SET_PARA_VALUE(2,'COMPATIBLE_MODE',2);
WITH TRX_TAB AS
(SELECT O1.NAME,L1.TRX_ID FROM V$LOCK L1,SYSOBJECTS O1 WHERE L1.TABLE_ID=O1.ID AND O1.ID<>0),
TRX_SESS AS (
SELECT L.TRX_ID WT_TRXID, L.ROW_IDX BLK_TRXID,L.BLOCKED,(SELECT NAME TABLE_NAME FROM TRX_TAB A WHERE A.TRX_ID=L.TRX_ID) WT_TABLE,
S1.SESS_ID WT_SESS,S2.SESS_ID BLK_SESS,
S1.USER_NAME WT_USER_NAME,S2.USER_NAME BLK_USER_NAME,S1.SQL_TEXT,S1.CLNT_IP,DATEDIFF(SS, S1.LAST_SEND_TIME, SYSDATE) SS
FROM V$LOCK L,V$SESSIONS S1,V$SESSIONS S2
WHERE L.TRX_ID=S1.TRX_ID AND L.ROW_IDX=S2.TRX_ID)
SELECT SYSDATE STATTIME,* FROM TRX_SESS where BLOCKED=1;
SELECT TOP 20 START_TIME,TIME_USED/1000 TIME_USED,TOP_SQL_TEXT FROM V$SQL_HISTORY ORDER BY TIME_USED DESC;
SELECT * FROM V$SYSTEM_LONG_EXEC_SQLS ORDER BY EXEC_TIME DESC;
select t.segment_name,
t.segment_type,
t.tablespace_name,
t.owner,
t.bytes,
t.bytes/1024 byte_kb,
t.bytes/1024 byte_mb
from dba_segments t
where t.owner = 'SYSDBA' -- 用户/模式名
and t.SEGMENT_TYPE = 'TABLE'
order by t.bytes desc;
select t.owner, t.table_name, t.tablespace_name, t.num_rows, t.last_analyzed
from dba_tables t
where t.owner = 'SYSDBA' -- 用户/模式名
order by t.num_rows desc;
select * from V$SYSSTAT where classid in (11,5) order by classid desc;
SELECT
A.FILE_ID ,
A.PATH ,
A.CLIENT_PATH,
A.RLOG_SIZE ,
B.FREE_SPACE ,
B.TOTAL_SPACE,
B.CUR_FILE
from
(
select * from V$RLOGFILE where true
) A,
(
select * from V$RLOG where true
) B;
SELECT a.tablespace_name "表空间名称",
total / (1024 * 1024) "表空间大小(M)",
free / (1024 * 1024) "表空间剩余大小(M)",
(total - free) / (1024 * 1024 ) "表空间使用大小(M)",
total / (1024 * 1024 * 1024) "表空间大小(G)",
free / (1024 * 1024 * 1024) "表空间剩余大小(G)",
(total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)",
round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free
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;
select * from V$DATAFILE;
begin
for rec in (select owner,table_name from all_tables where owner not in ('SYS','SYSAUDITOR','SYSSSO','CTISYS')) loop
call SP_TAB_STAT_INIT(rec.owner,rec.table_name);
end loop;
end;
/
select owner,table_name,tablespace_name,status,num_rows from all_tables where owner not in ('SYS','SYSAUDITOR','SYSSSO','CTISYS')
order by owner,num_rows desc;
SELECT
TS.NAME,
DF.PATH
FROM
V$TABLESPACE AS TS,
V$DATAFILE AS DF
WHERE
TS.ID = DF.GROUP_ID;
SELECT a.tablespace_name "表空间名称",
total / (1024 * 1024) "表空间大小(M)",
free / (1024 * 1024) "表空间剩余大小(M)",
(total - free) / (1024 * 1024 ) "表空间使用大小(M)",
total / (1024 * 1024 * 1024) "表空间大小(G)",
free / (1024 * 1024 * 1024) "表空间剩余大小(G)",
(total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)",
round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free
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;
select * from V$DEADLOCK_HISTORY;
查看 DBLINK 信息
select * from DBA_DB_LINKS;
SELECT A.ID,A.NAME,A."ENABLE",A.USERNAME,A.CREATETIME,A.MODIFYTIME,A.DESCRIBE,
B.LAST_DATE||' '||B.LAST_SEC LAST_TIME,B.NEXT_DATE||' '||B.NEXT_SEC NEXT_TIME,B.WHAT
FROM SYSJOB.SYSJOBS A,SYSJOB.USER_JOBS B
WHERE A.ID=B.JOB;
SELECT * FROM SYSJOB.SYSJOBSCHEDULES;
同步逻辑是几乎一样,区别主要在于事务分发即读写分离分发比例,读写分离集群可通过配置dm_svc.conf实现事务分发,数据守护没有
cat /etc/dm_svc.conf
##以#开头的行表示是注释
##全局配置区
TIME_ZONE=(480) #指明客户端的默认时区 +480东八区
LANGUAGE=(en)
DMRW=(192.168.40.130:5236,192.168.40.140:5236)
##服务配置
[DMRW]
LOGIN_MODE=(1) #0:优先连接 PRIMARY 模式的库,NORMAL 模式次之,最后选择 STANTBY 模式;1:只连接主库;2:只连接备库;3:优先连接 STANDBY 模式的库,PRIMARY 模式次之,最后选择 NORMAL 模式;4:优先连接 NORMAL 模式的库,PRIMARY 模式次之,最后选择 STANDBY 模式。
RW_SEPARATE=(1) #是否启用读写分离。0:不启用;1:启用;2:启用,备库由客户端进行选择,且只会选择服务名中配置的节点。
RW_PERCENT=(30) #读写分离分发比例,有效值范围 0~100,主库占所有事物数的比例
SWITCH_TIMES=(60) #以服务名连接数据库时,若未找到符合条件的库成功建立连接,将尝试遍历服务名中库列表的次数。
SWITCH_INTERVAL=(1000) #在服务器之间切换的时间间隔,单位为毫秒
cat /etc/dm_svc.conf
##以#开头的行表示是注释#
##全局配置区
TIME_ZONE=(480)
LANGUAGE=(cn)
DMHA=(192.168.40.150:5236,192.168.40.160:5236)
##服务配置
[DMHA]
LOGIN_MODE=(1) #0:优先连接 PRIMARY 模式的库,NORMAL 模式次之,最后选择 STANTBY 模式;1:只连接主库;2:只连接备库;3:优先连接 STANDBY 模式的库,PRIMARY 模式次之,最后选择 NORMAL 模式;4:优先连接 NORMAL 模式的库,PRIMARY 模式次之,最后选择 STANDBY 模式。
SWITCH_TIMES=(60) #以服务名连接数据库时,若未找到符合条件的库成功建立连接,将尝试遍历服务名中库列表的次数。
SWITCH_INTERVAL=(1000) #在服务器之间切换的时间间隔,单位为毫秒
即时归档
[dmdba@~]$ vi /dmdb8/dmdata/DAMENG/dmarch.ini
ARCH_WAIT_APPLY = 0 #0:高性能 1:事务一致
[ARCHIVE_LOCAL]
ARCH_TYPE = LOCAL #本地归档类型
ARCH_DEST = /dmdb8/dmarch/DAMENG #本地归档存放路径
ARCH_FILE_SIZE = 1024 #单个归档大小,单位 MB
ARCH_SPACE_LIMIT = 51200 #归档上限,单位 MB
[ARCHIVE_TIMELY1]
ARCH_TYPE = TIMELY #即时归档类型
ARCH_DEST = top02 #即时归档目标实例名
[dmdba@~]$ vi /dmdb8/dmdata/DAMENG/dmarch.ini
ARCH_WAIT_APPLY = 0 #0:高性能 1:事务一致
[ARCHIVE_LOCAL]
ARCH_TYPE = LOCAL #本地归档类型
ARCH_DEST = /dmdb8/dmarch/DAMENG #本地归档存放路径
ARCH_FILE_SIZE = 1024 #单个归档大小,单位 MB
ARCH_SPACE_LIMIT = 51200 #归档上限,单位 MB
[ARCHIVE_REALTIME1]
ARCH_TYPE = REALTIME #实时归档类型
ARCH_DEST = top02 #实时归档目标实例名