1、查询数据库版本:
查询数据库大版本号:
Select * from v$version;
查询小版本号:
Select id_code;
2、表空间相关信息查询
查询数据文件和联机日志文件信息
select b.tablespace_name, b.file_name, b.bytes/1024/1024 size_m from dba_data_files b union all select 'RLOG', a.path, a.rlog_size/1024/1024 from v$rlogfile a;
查询表空间占用率
select b.file_name, b.tablespace_name, b.bytes/1024/1024 size_m, (b.bytes-(nvl(a.bytes,0)))/1024/1024 used_m, round((b.bytes-(nvl(a.bytes,0)))/(b.bytes)*100,2) usedrate from dba_free_space a,dba_data_files b where a.file_id(+) = b.file_id and a.tablespace_name(+) = b.tablespace_name order by b.tablespace_name;
3、模式相关信息查询
查看模式和用户的对应关系
select a.NAME schname, a.ID schid, b.id userid, b.NAME username from sysobjects a, sysobjects b where a."TYPE$"='SCH' and a.pid = b.id;
查看模式下所有对象信息
select a.object_name, a.object_id, a.object_type, a.created, a.status from dba_objects a where a.owner='DMHR'; -- 用户/模式名
批量禁用某个用户/模式下所有外键约束
将查询出的拷贝执行即可禁用外键约束。
select 'alter table '|| t.owner||'.'||t.table_name ||' disable constraint '||t.constraint_name||';' from dba_constraints t where t.owner = 'DMHR' -- 用户/模式名 and t.constraint_type = 'R';
查看系统外键约束的引用关系
查询某个用户或模式下外键约束的引用关系:
select t1.owner,t1.table_name, t2.table_name as "TABLE_NAME(R)", t1.constraint_name, t1.r_constraint_name as "CONSTRAINT_NAME(R)", a1.column_name, a2.column_name as "COLUMN_NAME(R)"from dba_constraints t1, dba_constraints t2, dba_cons_columns a1, dba_cons_columns a2where t1.owner = t2.owner and a1.owner = a2.OWNER and t1.owner = 'DMHR' and t1.r_constraint_name = t2.constraint_name and t1.constraint_name = a1.constraint_name and t1.r_constraint_name = a2.constraint_name;
4、作业相关
查看系统中的作业信息:
select t.job, t.schema_user, t.last_date, t.last_sec, t.next_date, t.next_sec, t."INTERVAL", t.broken, t.failures,t.what from dba_jobs t;
运行作业
call dbms_job.run(1637544901); --参数为jobid
历史作业运行情况
select * from sysjob.SYSJOBHISTORIES2;
命令行查看作业运行状态及日志
select * from sysjob.sysjobs;
select * from sysjob.sysjobhistories;
select * from sysjob.sysjobschedules;
select * from sysjob.sysjobsteps;
5、会话/事务相关
查看会话信息
select t.SESS_ID, t.SQL_TEXT, t.STATE, t.TRX_ID, t.THRD_ID from v$sessions t;
查看当前会话
select sessid;
事务等待
使用如下sql查询数据库中的事务等待信息,如果为空,则表示当前无事务等待。
select * from v$trxwait;
或
select b.name, t.* from v$lock t, SYSOBJECTS b where t.BLOCKED = 1 and t.TABLE_ID = b.ID;
某个会话的历史sql信息
select * from V$SQL_HISTORY t where T.SESS_ID = '140577090115912';
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
达梦数据发布上市后首份财报:2024年营收10.4亿、净利3.6亿,销售平均薪酬 101 万、研发 36 万
通讯员
234次阅读
2025-04-15 12:09:47
国产数据库图谱又上新|82篇精选内容全览达梦数据库
墨天轮编辑部
225次阅读
2025-04-23 12:04:21
全国首部图数据库国家标准发布!达梦数据深度参与!
达梦数据
167次阅读
2025-04-02 09:34:13
达梦数据携手中国移动建成国内最大分布式数据库集群
通讯员
153次阅读
2025-04-02 15:10:38
达梦数据库快速上手指南
孙莹
152次阅读
2025-04-10 23:35:47
国产数据库必修课已上新|达梦数据库,从入门到实战
墨天轮-雪宝君
150次阅读
2025-04-28 14:25:11
达梦中国数据库产业基地竣工,光谷崛起“数据之弧”
通讯员
146次阅读
2025-04-23 09:41:05
SQLark V3.4 更新 | 新增 PostgreSQL 数据库支持、SQL 常用代码段、表设计器体验升级,超多新功能等你来探索!
达梦产品与服务
124次阅读
2025-04-17 09:38:11
SQLark 数据生成 | 外键、自增列、check约束、虚拟列都能自动识别!
达梦产品与服务
101次阅读
2025-04-11 10:41:05
【喜报】您有一件邮件请查收!恭喜您通过达梦DCA/DCP考试~
云贝19941464235
79次阅读
2025-04-02 10:47:26