数据库管理员常用&问题排查sql

1.基础篇
Mysql:

select version() from dual;        查看数据库版本

Oracle:

select * from v$version;        --查看数据库版本

SELECT instance_name FROM v$instance;        --获取数据库实例名

select * from dba_directories;         --查询指定的数据库备份位置

select * from v$sql;        --查询最近所有的SQL操作

select * from v$logfile;        --查看oracle日志路径

SELECT status FROM v$instance;        --检查数据库是否挂载

2.排查问题篇
  • 查看并发会话数:

select count(1) as ACTIVE_COUNT from v$session where status = 'ACTIVE' and type = 'USER' and program not like '%PR%';

  • 查看session会话使用率:

select (select count(1) from v$session) as current_cnt,(select value from v$parameter where name = 'sessions') as session_cnt, (select round((select count(1) from v$session)/(select value from v$parameter where name 'sessions')*100) pct from dual)as from dual;

  • 查看表空间使用率:

select tablespace_name,round(used_space * 8192 / 1024 / 1024 , 2) used_space, round(tablespace_size * 8192 / 1024 / 1024 , 2) tablespace_size, round(used_percent, 2) used_percent from dba_tablespace_usage_metrics;

扫描二维码关注公众号,回复: 17409379 查看本文章

持续更新中......

猜你喜欢

转载自blog.csdn.net/hlx2023/article/details/141884365