目录
实例相关
用户权限
内存相关
表相关
分区表/索引
表空间
文件相关
数据文件
undo文件
Temp文件
在线日志
归档日志
备份还原
JOB相关
主备
DSC
ASM
会话相关
锁相关
sql相关
执行计划
系统负载
实例相关
版本
select * from v$version;
select id_code();
字符集
select UNICODE ();
页大小
select SF_GET_PAGE_SIZE();
查看数据库信息:
select name,create_time,arch_mode,status$,role$ from v$database;
查看实例信息:
select name,
instance_name,
host_name,
svr_version,
build_version,
start_time,
status$,
mode$,
oguid
from v$instance;
查看授权信息
SELECT SERIES_NO,
EXPIRED_DATE,
AUTHORIZED_CUSTOMER,
PROJECT_NAME,
CLUSTER_TYPE FROM V$LICENSE;
重新载入授权
CALL P_LOAD_LIC_INFO();
用户权限
查看用户信息
select username,
account_status,
lock_date,
expiry_date,
default_tablespace,
default_index_tablespace,
temporary_tablespace,
created,
profile ,
password_versions
from dba_users;
查看用户锁定、登录信息
select id,lock_time,
locked_status,
lastest_locked,
pwd_policy,
last_login_dtid,
last_login_ip,
failed_attemps
from sysusers;
select b.USERNAME,
a.FAILED_NUM,
A.LOCKED_STATUS,
A.LASTEST_LOCKED,
A.FAILED_ATTEMPS
from sysusers a,
dba_users b
where a.id=b.user_id;
用户资源限制
select
profile,
resource_name,
resource_type,
limit
from dba_profiles;
自定义的Profile
Select uid,pid from sysuserprofiles;
select a.pid profileid,
b.name profile_name,
a.uid userid,
c.name user_name
from SYSUSERPROFILES a,
SYSOBJECTS b,
SYSOBJECTS c
where a.PID = b.id
and a.UID = c.ID;
查看当前用户的权限
select * from session_privs;
查看某个用户的权限
select * from dba_sys_privs t where t.GRANTEE= 'HR';
select * from dba_role_privs t where t.GRANTEE= 'HR';
select * from dba_tab_privs t where t.GRANTEE= 'HR';
select * from dba_col_privs a where a.grantee='HR';
查看用户模式
select * from SYSOBJECTS t where t."TYPE$" ='SCH'; --查看模式
select * from SYSOBJECTS t where t."SUBTYPE$" ='USER'; --查看用户
--查询模式和用户的对应关系:
select a.id scheid,
a.name schename,
b.id userid,
b.name username
from SYS.SYSOBJECTS a,
SYS.SYSOBJECTS b
where a."TYPE$" = 'SCH'
and a.pid = b.id;
查看用户的权限信息:
SELECT * FROM (
SELECT GRANTEE,GRANTED_ROLE PRIVILEGE,'ROLE_PRIVS' PRIVILEGE_TYPE,CASE ADMIN_OPTION WHEN 'Y' THEN 'YES' ELSE 'NO' END ADMIN_OPTION FROM DBA_ROLE_PRIVS
UNION SELECT GRANTEE,PRIVILEGE,'SYS_PRIVS' PRIVILEGE_TYPE,ADMIN_OPTION FROM DBA_SYS_PRIVS
UNION SELECT GRANTEE,PRIVILEGE||' ON '||OWNER||'.'||TABLE_NAME PRIVILEGE,'TABLE_PRIVS' PRIVILEGE_TYPE,GRANTABLE FROM DBA_TAB_PRIVS
)
WHERE GRANTEE IN (SELECT USERNAME FROM ALL_USERS WHERE USERNAME NOT IN ('SYS','SYSDBA','SYSSSO','SYSAUDITOR') )
ORDER BY GRANTEE,PRIVILEGE_TYPE,PRIVILEGE;
内存相关
DM 数据库使用的内存大致等于 BUFFER + MPOOL,一般需关注 v$bufferpool 和 v$mem_pool 相关信息
查看内存池使用情况:
select name, --内存池名称
is_shared, --是否是共享的
is_overflow, --是否用到了备份池
org_size/1024/1024, --内存池初始大小
TOTAL_size/1024/1024, --内存池总大小(包括扩展的)
RESERVED_SIZE/1024/1024, --当前已分配大小(包括扩展的)
DATA_SIZE/1024/1024, --实际有效字节
EXTEND_SIZE, --每次扩展多少
TARGET_SIZE, --目标大小
N_EXTEND_NORMAL , --TARGET范围内累计扩展次数
N_EXTEND_EXCLUSIVE --超过TARGET累计扩展次数
from v$mem_pool
order by TOTAL_size desc;
N_EXTEND_EXCLUSIVE 如果长期大于 0,说明长期从池外扩展,可能存在内存泄露,需要重点关注
若使用到备份池,则需要保持高度关注
通过 v$sysstat 查看内存使用情况
select name ,stat_val/1024.0/1024.0 from v$sysstat where CLASSID=11 ;
memory pool size in bytes:内存池总的大小
memory used bytes:内存池使用的内存大小
memory used bytes from os:内存池从操作系统分配的大小
单个会话内存使用情况
SELECT A.CREATOR ,
B.SQL_TEXT ,
SUM(A.TOTAL_SIZE)/1024.0/1024.0 TOTAL_M, --当前总量(包括扩展)
SUM(A.DATA_SIZE) /1024.0/1024.0 DATA_SIZE_M --实际使用量
FROM V$MEM_POOL A,
V$SESSIONS B
WHERE A.CREATOR = B.THRD_ID
GROUP BY A.CREATOR,
B.SQL_TEXT
ORDER BY TOTAL_M DESC;
内存增长过快
select * from V$MEM_REGINFO ORDER BY REFNUM DESC;
REFNUM 字段值很大,说明存在内存堆积的情况
fname 指定该内存池的内存来源文件
lineno 指定相关内容在文件中的行数
查询内存总量
select
(select sum(n_pages) * page()/1024/1024 from v$bufferpool)||'MB' as BUFFER_SIZE,
(select sum(total_size)/1024/1024 from v$mem_pool)||'MB' as mem_pool,
(select sum(n_pages) * page()/1024/1024 from v$bufferpool)+(select sum(total_size)/1024/1024 from v$mem_pool)||'MB' as TOTAL_SIZE
from dual;
若会话执行的 sql 消耗大量的内存,可以根据以下 sql 找到最占用内存的 sql,再进行 sql 优化
SELECT "SESSID",
MAX_MEM_USED||'KB',
SQL_TXT
FROM V$SQL_STAT
order by MAX_MEM_USED DESC;
Buffer状态
select
name, --缓冲区名称
n_pages, --页数
free, --空闲页数目
N_DISCARD64 --淘汰的页数
from v$bufferpool;
如果 free 项为 0,或者 N_DISCARD64 非零,表示该缓冲区经常淘汰,说明对应的缓冲区参数太小,导致频繁淘汰,需要调整对应的缓冲区的参数。
缓冲区命中率
select name 缓冲池名称,
sum(page_size)*sf_get_page_size 缓冲池大小_G,
sum(rat_hit) /count(*) 命中率
from v$bufferpool
group by name;
缓存池信息
SELECT * FROM V$SCP_CACHE;
查询缓冲区中缓冲项的相关信息
SELECT * FROM V$CACHEITEM;
SELECT SUM(ITEM_SIZE)/1024/1024 缓存池大小_M FROM V$CACHEITEM;
字典缓存
select * from V$DB_CACHE;
表相关
查看表的信息:
select owner,
table_name,
tablespace_name,
status,
num_rows,
LAST_ANALYZED,
partitioned
from dba_tables;
查看字段的信息:
select owner,
table_name,
column_name,
data_type,
data_length
from DBA_TAB_COLUMNS
WHERE OWNER='MOCHA_DB';
表约束信息:
select owner,
constraint_name,
constraint_type,
table_name,
status,
last_change,
index_owner,
index_name
from dba_constraints t
where t.owner='MOCHA_DB';
查询所有表的大小:
-- 查询所有表所占的大小及所在空间
SELECT A.OWNER AS "模式",
A.SEGMENT_NAME AS "表名",
round(A.BYTES/1024/1024,2) AS "大小(MB)",
A.TABLESPACE_NAME AS "所属表空间",
B.COMMENTS AS "表注释"
FROM DBA_SEGMENTS A,
DBA_TAB_COMMENTS B
WHERE A.OWNER=B.OWNER
AND A.SEGMENT_NAME = B.TABLE_NAME
AND A.OWNER='MOCHA_DB'
ORDER BY SEGMENT_NAME ASC;
查看表的定义:
CALL SP_TABLEDEF('MOCHA_DB', 'SUN_SEGMENTS');
根据对象类型、对象名、对象所属模式返回DDL语句:
SELECT SF_DBMS_METADATA_GET_DDL(OBJECT_TYPE=>'TABLE',OBJECT_NAME=>'DICT_AREA',SCHNAME=>'TEST');
查看视图、序列、同义词的定义:
SELECT b.*
FROM SYS.SYSOBJECTS a,
SYS.SYSTEXTS b
WHERE a.ID = b.ID
and a.NAME LIKE 'VIEW_1%';
模糊查看函数名称:
SELECT * FROM V$IFUN WHERE NAME LIKE upper('%table_used_space%');
根据上一步id查询函数参数
SELECT * FROM V$IFUN_ARG WHERE id= V$IFUN.ID ;
分区表/索引
查看有哪些表是分区表:
select owner,
table_name,
partitioning_type,
subpartitioning_type,
partition_count,
status,
def_tablespace_name
from dba_part_tables
where owner='MOCHA_DB';
查看分区表的每个分区:
--98个表分区
SELECT *
FROM DBA_TAB_PARTITIONS
WHERE TABLE_OWNER='MOCHA_DB'
AND TABLE_NAME='SUN_SEGMENTS';
注意:达梦没有dba_part_indexes,只有dba_indexes
查看分区索引:
--98*2个普通分区索引,每个表分区对应两个普通分区索引,查看索引名称
SELECT * FROM DBA_INDEXES A WHERE A.OWNER = 'MOCHA_DB' AND A.TABLE_NAME LIKE 'SUN_SEGMENTS%' AND INDEX_TYPE='NORMAL';
--98个聚簇分区索引,每个表分区默认有一个聚簇分区索引
SELECT * FROM DBA_INDEXES A WHERE A.OWNER = 'MOCHA_DB' AND A.TABLE_NAME LIKE 'SUN_SEGMENTS%' AND INDEX_TYPE='CLUSTER';
--98个分区,根据索引名称,查看每个分区名称
select * from dba_ind_partitions a where a.index_name='IDX_CHECK_DATE';
表空间
查看表空间使用情况
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 2 desc;
临时表空间经常过大,说明内存设置过小或存在大量中间结果集存放,需要视情况进行优化。
可以通过 ini 参数 TEMP_SIZE 配置大小、TEMP_SPACE_LIMIT 设置上限、存储过程 SP_TRUNC_TS_FILE 来收缩 TEMP 表空间文件(生产环境请谨慎使用)。
-- 定义函数,通过页数和显示单位(可选参数MB/GB,默认KB为单位显示)
WITH FUNCTION GET_SIZE_BY_PAGES(NUM_OF_PAGE INT, KB_MB_GB VARCHAR(2) DEFAULT 'KB') RETURN NUMBER(15, 2) AS
V_SIZE_KB NUMBER(15, 2) := ROUND(PAGE() * NUM_OF_PAGE / 1024.00, 2);
BEGIN
IF KB_MB_GB = 'MB' THEN
RETURN V_SIZE_KB / 1024.00;
ELSIF KB_MB_GB = 'GB' THEN
RETURN V_SIZE_KB / 1024.00 / 1024.00;
END IF;
RETURN V_SIZE_KB;
END;
-- 查看每个表空间占用情况和行数
SELECT T.TABLESPACE_NAME,
T.OWNER,
T.TABLE_NAME,
GET_SIZE_BY_PAGES(TABLE_USED_PAGES(T.OWNER, T.TABLE_NAME), 'MB') AS TABLE_USED_SPACE_MB,
GET_SIZE_BY_PAGES(TABLE_USED_PAGES(T.OWNER, T.TABLE_NAME), 'GB') AS TABLE_USED_SPACE_GB,
TABLE_ROWCOUNT(T.OWNER, T.TABLE_NAME) AS TABLE_ROWCOUNT
FROM DBA_TABLES T
WHERE T.OWNER IN ('MOCHA_DB')
ORDER BY TABLE_USED_SPACE_MB DESC, TABLE_ROWCOUNT DESC;
--查看HUGE表
select * from v$huge_tablespace;
文件相关
数据文件
select file_name,
tablespace_name,
round(bytes/1024/1024,2) "BYTES(MB)",
round(maxbytes/1024/1024/1024,2) "MAX_BYTES(GB)",
autoextensible,
increment_by,
status,
online_status
from dba_data_files;
SELECT path,
create_time,
status$,
modify_time,
total_size,
max_size,
free_size,
real_free_size
FROM V$DATAFILE;
表空间和数据文件对应关系
SELECT TS.NAME, DF.PATH FROM V$TABLESPACE AS TS, V$DATAFILE AS DF WHERE TS.ID = DF.GROUP_ID;
undo文件
查看undo相关的参数:
select a.PARA_NAME,
a.PARA_VALUE,
a.PARA_TYPE,
a.DEFAULT_VALUE
from V$DM_INI a
where a.PARA_NAME like '%UNDO%';
查看UNDO数据文件:
select * from dba_data_files where tablespace_name = 'ROLL';
UNDO 日志空间是否增长过快,查看已使用 roll 表空间的大小
select a.tablespace_name space_name ,
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
ORDER BY "使用率" DESC;
查看待 Purge 的事务数( OBJ_NUM )是否在不停的增长
select * from v$purge;
Temp文件
查看临时表空间的参数:
select a.PARA_NAME,
a.PARA_VALUE,
a.PARA_TYPE,
a.DEFAULT_VALUE
from V$DM_INI a
where a.PARA_NAME like '%TEMP%';
查看TEMP文件:
select * from dba_data_files where tablespace_name = 'TEMP'
在线日志
查看在线日志的LSN、DB_MAGIC:
select
CKPT_LSN,
FILE_LSN,
FLUSH_LSN,
CUR_LSN,
NEXT_SEQ,
DB_MAGIC
from v$rlog;
查看在线重做日志文件:
select group_id,
file_id,
path,
create_time,
round(rlog_size/1024/1024,2) as "RLOG_SIZE(MB)"
from v$rlogfile;
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;
查看redo文件的历史状态:
select * from V$RLOG_HISTORY;
查看检查点信息:
select * from V$CKPT;
归档日志
清理归档日志:
SF_ARCHIVELOG_DELETE_BEFORE_TIME
SF_ARCHIVELOG_DELETE_BEFORE_LSN
归档配置信息的查看:
select arch_name,
arch_type,
arch_dest,
arch_file_size,
arch_space_limit,
arch_is_valid,
arch_incoming_path,
arch_curr_dest
from V$DM_ARCH_INI;
归档日志文件的查看:
select * from V$ARCHIVED_LOG ORDER BY FIRST_CHANGE# DESC;
--V$ARCH_FILE中的CLSN和monitor中的CLSN比较可以判断归档是否应用。
select * from V$ARCH_FILE;
备份还原
备份集查看
SELECT BACKUP_TIME,
BACKUP_NAME,
BACKUP_PATH,
CASE TYPE WHEN 1 THEN '增备' ELSE '全备' END AS "type" FROM V$BACKUPSET
ORDER BY BACKUP_TIME DESC;
查看内存中的备份目录
select * from V$BACKUPSET_SEARCH_DIRS;
显示备份集的数据库相关信息
SELECT SF_BAKSET_BACKUP_DIR_ADD('DISK', '/dm/backup');
SELECT BACKUP_PATH, PAGE_SIZE, EXTENT_SIZE, CASE_SENSITIVE FROM V$BACKUPSET_DBINFO WHERE BACKUP_PATH='/dm/backup/tab_bak_01';
显示备份集中数据文件的相关信息
SELECT SF_BAKSET_BACKUP_DIR_ADD('DISK', '/dm/backup');
SELECT FILE_SEQ, TS_ID, FILE_ID, TS_NAME, FILE_NAME FROM V$BACKUPSET_DBF WHERE BACKUPPATH ='/dm/backup/ts_bak_for_dbf';
显示备份集中归档文件的信息
SELECT SF_BAKSET_BACKUP_DIR_ADD('DISK', '/dm/backup');
SELECT BACKUPPATH, FILE_SEQ, BEGIN_LSN, END_LSN FROM V$BACKUPSET_ARCH
WHERE BACKUPPATH='/dm/backup/db_bak_for_arch';
显示备份集的备份片信息
SELECT SF_BAKSET_BACKUP_DIR_ADD('DISK', '/dm/backup');
SELECT BACKUPPATH, BKP_NTH, FILE_NAME, BKP_LEN FROM V$BACKUPSET_BKP WHERE
BACKUPPATH='/dm/backup/db_bak_for_bkp';
显示表备份集中备份表信息,仅表备份有效
SELECT SF_BAKSET_BACKUP_DIR_ADD('DISK', '/dm/backup');
SELECT BACKUPNAME, TABLENAME FROM V$BACKUPSET_TABLE WHERE BACKUPPATH='/dm/backup/tab_bak_for_info';
并行备份中生成的子备份集信息
BACKUP DATABASE BACKUPSET '/dm/backup/db_bak_for_subs' PARALLEL 3;
SELECT SF_BAKSET_BACKUP_DIR_ADD('DISK', '/dm/backup');
SELECT BACKUPPATH, BKP_NUM, DBF_NUM FROM V$BACKUPSET_SUBS;
当前备份任务实时监控信息
BACKUP DATABASE BACKUPSET '/dm/backup/db_bak_for_monitor';
SELECT TOTAL_SIZE, PCNT, CUR_READ, CUR_WRITE FROM V$BACKUP_MONITOR;
当前备份任务待备份数据文件列表
select * from v$backup_files;
最近 100 条备份监控信息
SELECT READ_SIZE, WRITE_SIZE, AVG_READ, AVG_WRITE FROM V$BACKUP_HISTORY;
JOB相关
JOB任务
select * from sysjob.sysjobs;
select * from dba_jobs;
select * from sysjob.SYSJOBSCHEDULES;
正在运行的JOB
select * from dba_jobs_running;
作业步骤信息
select * from sysjobsteps;
作业执行历史
select * from SYSJOB.SYSJOBHISTORIES2;
--查看所有作业信息
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;
主备
V$RECOVER_STATUS:查当前备库恢复的信息
V$RAPPLY_SYS
V$RAPPLY_LOG_TASK 备库日志堆积情况
DSC
显示实例信息
select EP_NAME,EP_SEQNO,EP_GUID,EP_TIMESTAMP,EP_STATUS from V$DSC_EP_INFO;
配置的全局信息
select VERSION,N_GROUP,VTD_PATH,UDP_OGUID,DCR_PATH from V$DCR_INFO;
所有系统中所有的事务以及相关信息,如锁信息等
select * from V$DSC_TRX;
显示事务等待信息
select * from V$DSC_TRXWAIT;
DSC中查v$trxwait查询的结果为空。
ASM
select group_id,
DISK_ID,
DISK_NAME,
DISK_PATH,
CREATE_TIME,
MODIFY_TIME,
status
from v$asmdisk;
select type,path,size_bytes,size_total from v$asmfile;
select GROUP_ID,GROUP_NAME,TOTAL_MB,FREE_MB from v$asmgroup;
会话相关
select * from v$session;
select * from v$session_event;
select * from v$session_stat;
select * from v$session_wait_history;
select *
from V$SESSION_HISTORY a
where a.CREATE_TIME >= to_date('2024-07-21 00:00:00','yyyy-mm-dd hh24:mi:ss')
and a.CREATE_TIME < to_date('2024-07-22 00:00:00','yyyy-mm-dd hh24:mi:ss');
查询会话信息
SELECT STATE,CLNT_IP,CLNT_TYPE,CURR_SCH,USER_NAME,COUNT(*)
COUNTS FROM V$SESSIONS GROUP BY STATE,CLNT_IP,CLNT_TYPE,CURR_SCH,USER_NAME
ORDER BY STATE;
线程信息:
select * from v$threads;
正在等待的线程:
select * from v$latches;
锁相关
查询事务信息:
select * from v$trx;
select * from v$dsc_trx;
查询事务的等待信息:
select * from v$trxwait;
select * from v$dsc_trxwait;
等待事务查询
select
tw.id as trx_id ,
tw.wait_for_id ,
s.sess_id ,
ws.sess_id as wait_for_session,
s.sql_text ,
ws.sql_text as wait_for_sql
from
v$trxwait tw
left join v$sessions s
on
tw.id=s.trx_id
left join v$sessions ws
on
tw.wait_for_id=ws.trx_id;
锁会话查询:
SELECT DS.SESS_ID "被阻塞的会话ID",
DS.SQL_TEXT "被阻塞的SQL",
DS.TRX_ID "被阻塞的事务ID",
DS.CREATE_TIME "开始阻塞时间",
SS.SESS_ID "占用锁的会话ID",
SS.SQL_TEXT "占用锁的SQL",
SS.CLNT_IP "占用锁的IP",
L.wait_for_id "占用锁的事务ID"
FROM V$trxwait L
LEFT JOIN V$SESSIONS DS
ON DS.TRX_ID = L.ID
LEFT JOIN V$SESSIONS SS
ON SS.TRX_ID = L.wait_for_id;
DSC锁会话查询
SELECT DS.SESS_ID "被阻塞的会话ID",
DS.SQL_TEXT "被阻塞的SQL",
DS.TRX_ID "被阻塞的事务ID",
DS.CREATE_TIME "开始阻塞时间",
SS.SESS_ID "占用锁的会话ID",
SS.SQL_TEXT "占用锁的SQL",
SS.CLNT_IP "占用锁的IP",
L.wait_trx_id "占用锁的事务ID"
FROM V$dsc_trxwait L
LEFT JOIN V$SESSIONS DS
ON DS.TRX_ID = L.TRX_ID
LEFT JOIN V$SESSIONS SS
ON SS.TRX_ID = L.wait_trx_id;
“占用锁的会话 ID ”表示该会话占用这个对象的锁,且事务一直没有提交。导致“被阻塞的会话 ID ”无法对该对象上锁。
杀会话
SP_CLOSE_SESSION (19811492152);
查询死锁历史事务信息
select dh.trx_id ,
sh.sess_id,
wm_concat(top_sql_text)
from V$DEADLOCK_HISTORY dh,
V$SQL_HISTORY sh
where dh.trx_id =sh.trx_id
and dh.sess_id=sh.sess_id
group by dh.trx_id,
sh.sess_id;
有事务未提交的表查询
SELECT b.object_name,
c.sess_id,
a.*
FROM v$lock a,
dba_objects b,
v$sessions c
WHERE a.table_id = b.object_id
AND ltype = 'OBJECT'
AND a.trx_id = c.trx_id;
sql相关
最慢的 20 条 SQL 信息
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;
高内存的 20 条 SQL 统计
select * from V$SYSTEM_LARGE_MEM_SQLS order by mem_used_by_k desc;
前 20 条长耗时等待事件信息
SELECT top 20 * FROM V$SYSTEM_EVENT ORDER BY TOTAL_WAITS DESC;
执行计划
系统负载
select * from v$systeminfo;
达梦技术社区:达梦数据库 - 新一代大型通用关系型数据库 | 达梦在线服务平台