运维脚本
表空间
set linesize 2000;
select * from (
Select a.tablespace_name,
to_char(a.bytes/1024/1024/1024,‘999,999,999.999’) total_bytes_g,
to_char(b.bytes/1024/1024/1024,‘999,999,999.999’) free_bytes_g,
to_char(a.bytes/1024/1024/1024 - b.bytes/1024/1024/1024,‘999,999,999.999’) use_bytes_g ,
to_char((1 - b.bytes/a.bytes)100,‘99.99’) || ‘%’ use
from (select tablespace_name,
sum(bytes) bytes
from dba_data_files
group by tablespace_name) a,
(select tablespace_name,
sum(bytes) bytes
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
union all
select c.tablespace_name,
to_char(c.bytes/1024/1024/1024,‘999,999,999.999’) total_bytes,
to_char( (c.bytes-d.bytes_used)/1024/1024/1024,‘999,999,999.999’) free_bytes,
to_char(d.bytes_used/1024/1024/1024,‘999,999,999.999’) use_bytes,
to_char(d.bytes_used100/c.bytes,‘99.99’) || ‘%’ use
from
(select tablespace_name,sum(bytes) bytes
from dba_temp_files group by tablespace_name) c,
(select tablespace_name,sum(bytes_cached) bytes_used
from v$temp_extent_pool group by tablespace_name) d
where c.tablespace_name = d.tablespace_name
order by TOTAL_BYTES_G desc) ;
备份
set linesize 200
COL in_sec FORMAT a10
COL out_sec FORMAT a10
COL TIME_TAKEN_DISPLAY FORMAT a10
col start_time for a10
col end_time for a10
col INPUT_BYTES for 99999999999999
col OUTPUT_BYTES for 99999999999999
SELECT SESSION_KEY,
OPTIMIZED,
COMPRESSION_RATIO,
INPUT_BYTES,
OUTPUT_BYTES,
INPUT_BYTES_PER_SEC_DISPLAY in_sec,
OUTPUT_BYTES_PER_SEC_DISPLAY out_sec,
start_time,
end_time,
status,
TIME_TAKEN_DISPLAY
FROM V$RMAN_BACKUP_JOB_DETAILS
ORDER BY SESSION_KEY;
锁
SELECT count(*) FROM v$lock;
数据文件自动扩展
select ‘alter database datafile ‘’’||file_name||’’’ autoextend off;’ from dba_data_files where autoextensible=‘YES’;
数据库用户密码过期时间
select username,expiry_date from dba_users;
set linesize 300 \r
col PCT_USED for a15 \r
col PCT_FREE for a15 \r
col tablespace_name for a30 \r
select a.tablespace_name,
round(a.bytes_alloc / 1024 / 1024) Alloc_Mbytes,
round(nvl(b.bytes_free, 0) / 1024 / 1024) Free_Mbytes,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) Used_Mbytes,
round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) || ‘%’ Pct_Free,
100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) || ‘%’ Pct_Used,
round(maxbytes / 1048576) Max_Mbytes
from (select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible, ‘YES’, f.maxbytes, ‘NO’, f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
(select f.tablespace_name, sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
union all
select h.tablespace_name,
round(sum(h.bytes_free + h.bytes_used) / 1048576) Alloc_Mbytes,
round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) /
1048576) Free_Mbytes,
round(sum(nvl(p.bytes_used, 0)) / 1048576) Used_Mbytes,
round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) /
sum(h.bytes_used + h.bytes_free)) * 100) || ‘%’ Pct_Free,
100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) /
sum(h.bytes_used + h.bytes_free)) * 100) || ‘%’ Pct_Used,
round(sum(f.maxbytes) / 1048576) Max_bytes
from sys.v_TEMP_SPACE_HEADER h,
sys.v_Temp_extent_pool p,
dba_temp_files f
where p.file_id(+) = h.file_id
and p.tablespace_name(+) = h.tablespace_name
and f.file_id = h.file_id
and f.tablespace_name = h.tablespace_name
group by h.tablespace_name
ORDER BY PCT_USED;\n