DBA performance optimization commonly used SQL statements

 Sometimes the table space utilization is too low, we can slim down the table space and improve the space utilization and backup efficiency during recovery.

1. Table space usage

--1. oracle查询表空间使用率

SELECT a.tablespace_name,
ROUND (a.total_size) "total_size(MB)",
ROUND (a.total_size) - ROUND (b.free_size, 3) "used_size(MB)",
ROUND (b.free_size, 3) "free_size(MB)",
ROUND (b.free_size / total_size * 100, 2) || '%' free_rate
FROM ( SELECT tablespace_name, SUM (bytes) / 1024 / 1024 total_size
FROM dba_data_files
GROUP BY tablespace_name) a,
( SELECT tablespace_name, SUM (bytes) / 1024 / 1024 free_size
FROM dba_free_space
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name(+);


-- 2.更为直观的看法
select
  b.file_name 物理文件名,
  b.tablespace_name 表空间,
  b.bytes/1024/1024 大小M,
  (b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,
  substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 利用率
  from dba_free_space a,dba_data_files b
  where a.file_id=b.file_id
  group by b.tablespace_name,b.file_name,b.bytes
  order by b.tablespace_name;

--如果表空间不足,为表空间添加数据文件
--app_data表空间名称,添加数据文件名根据业务表空间命名规则命名

ALTER TABLESPACE app_data ADD DATAFILE '\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF' SIZE 10000M;

2. Oracle, query the data file corresponding to the table space, the corresponding relationship between users and table space

select tablespace_name,file_id,file_name from dba_data_files order by file_id;

 

Guess you like

Origin blog.csdn.net/weixin_41086692/article/details/103028007