Oracle归档配置及检查

  • 配置归档位置到 USE_DB_RECOVERY_FILE_DEST,并设置存储大小

    startup mount;
    !mkdir /db/archivelog
    ALTER SYSTEM SET db_recovery_file_dest_size=100G SCOPE=BOTH;
    ALTER SYSTEM SET db_recovery_file_dest='/db/archivelog' SCOPE=BOTH;
    ALTER SYSTEM SET log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST' scope=both;
    ALTER DATABASE ARCHIVELOG;

    select name,value from vparameter where name like 'db_recovery_file_dest' or name='log_archive_dest' or name='log_archive_dest_1' or name='log_archive_dest_2' union select name,to_char(value/1024/1024/1024)||' GB' from vparameter where name='db_recovery_file_dest_size' order by name;

  • 查看归档占用空间及归档个数

    set line 900 COLSEP '|' pagesize 50
    col name for a40
    col value for a100
    !clear
    select * from v$flash_recovery_area_usage;
    archive log list;

  • 24小时的归档数量检查
复制代码
set line 900 COLSEP '|' pagesize 50
col Data for a10
col day format a10
col total format 99999
col h00 format 9999
col h01 format 9999
col h02 format 9999
col h03 format 9999
col h04 format 9999
col h04 format 9999
col h05 format 9999
col h06 format 9999
col h07 format 9999
col h08 format 9999
col h09 format 9999
col h10 format 9999
col h11 format 9999
col h12 format 9999
col h13 format 9999
col h14 format 9999
col h15 format 9999
col h16 format 9999
col h17 format 9999
col h18 format 9999
col h19 format 9999
col h20 format 9999
col h21 format 9999
col h22 format 9999
col h23 format 9999
col h24 format 9999
break on report
compute max of "total" on report
compute max of "h00" on report
compute max of "h01" on report
compute max of "h02" on report
compute max of "h03" on report
compute max of "h04" on report
compute max of "h05" on report
compute max of "h06" on report
compute max of "h07" on report
compute max of "h08" on report
compute max of "h09" on report
compute max of "h10" on report
compute max of "h11" on report
compute max of "h12" on report
compute max of "h13" on report
compute max of "h14" on report
compute max of "h15" on report
compute max of "h16" on report
compute max of "h17" on report
compute max of "h18" on report
compute max of "h19" on report
compute max of "h20" on report
compute max of "h21" on report
compute max of "h22" on report
compute max of "h23" on report
compute max of "Avg" on report
compute sum of NUM on report
compute sum of GB on report
compute sum of MB on report
compute sum of KB on report
SELECT thread#,TRUNC(first_time) "Date",TO_CHAR(first_time, 'Dy') "Day",COUNT(1) "Total",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '00', 1, 0)) "h00",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '01', 1, 0)) "h01",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '02', 1, 0)) "h02",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '03', 1, 0)) "h03",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '04', 1, 0)) "h04",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '05', 1, 0)) "h05",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '06', 1, 0)) "h06",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '07', 1, 0)) "h07",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '08', 1, 0)) "h08",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '09', 1, 0)) "h09",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '10', 1, 0)) "h10",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '11', 1, 0)) "h11",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '12', 1, 0)) "h12",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '13', 1, 0)) "h13",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '14', 1, 0)) "h14",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '15', 1, 0)) "h15",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '16', 1, 0)) "h16",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '17', 1, 0)) "h17",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '18', 1, 0)) "h18",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '19', 1, 0)) "h19",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '20', 1, 0)) "h20",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '21', 1, 0)) "h21",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '22', 1, 0)) "h22",
SUM(DECODE(TO_CHAR(first_time, 'hh24'), '23', 1, 0)) "h23",
ROUND(COUNT(1) / 24, 2) "Avg" FROM gv$log_history WHERE thread# = inst_id GROUP BY thread#,TRUNC(first_time), TO_CHAR(first_time, 'Dy') ORDER BY 1;
  • 每天的归档数量及大小
复制代码
set line 900 COLSEP '|' pagesize 50
compute max of "NUM" on report
compute max of "GB" on report
compute max of "MB" on report
compute max of "KB" on report
select THREAD#, trunc(completion_time) as "DATE",count(1) num,trunc(sum(blocks*block_size)/1024/1024/1024) as GB,trunc(sum(blocks*block_size)/1024/1024) as MB,
round(sum(blocks*block_size)/1024,0) as KB from v$archived_log where first_time > trunc(sysdate-10) and dest_id = (select dest_id from V$ARCHIVE_DEST_STATUS 
where status='VALID' and type='LOCAL') group by thread#, trunc(completion_time) order by 2,1;

年归档数量及大小

复制代码
set line 900 COLSEP '|' pagesize 50
select round(min(sum(blocks*block_size)/1024/1024/1024)) MIN_Gb,round(max(sum(blocks*block_size)/1024/1024/1024)) MAX_Gb,
round(avg(sum(blocks*block_size)/1024/1024/1024)) AVG_Gb from (select a.THREAD#,trunc(first_time) as logtime,a.BLOCKS,
a.BLOCK_SIZE from v$archived_log a where a.DEST_ID = 1 and a.FIRST_TIME between sysdate-365 and sysdate) group by 
logtime order by logtime desc;

月归档数量

复制代码
set line 900 COLSEP '|' pagesize 100
select a_date,a_count from (select to_char(first_time,'YYYY-MM-DD') a_date,count(*) a_count 
from gv$log_history group by to_char(first_time,'YYYY-MM-DD') order by 1 ) where rownum<=31;
相关推荐
柃歌22 分钟前
【LeetCode Solutions】LeetCode 176 ~ 180 题解
数据结构·数据库·sql·算法·leetcode
一眼青苔1 小时前
如何在MySQL中实现类似Redis的PING命令的功能来检测连接状态?
数据库·redis·mysql
奔驰的小野码1 小时前
SpringAI实现AI应用-使用redis持久化聊天记忆
java·数据库·人工智能·redis·spring
hweiyu002 小时前
MySQL性能分析工具:SHOW PROCESSLIST
数据库·mysql
vvilkim3 小时前
SQL语言基础:从入门到掌握结构化查询语言
数据库·sql·oracle
Navicat中国4 小时前
Navicat BI 数据分析功能上线 | 数据洞察新方法
数据库·人工智能·信息可视化·数据挖掘·数据分析·navicat·bi
AI大模型顾潇5 小时前
[特殊字符] Milvus + LLM大模型:打造智能电影知识库系统
数据库·人工智能·机器学习·大模型·llm·llama·milvus
阿里云云原生5 小时前
阿里云 SLS 多云日志接入最佳实践:链路、成本与高可用性优化
数据库·阿里云·云计算
kaixiang3006 小时前
sqli-labs靶场18-22关(http头)
数据库