标签 进度 下的文章

expdp/impdp/rman会话进度查看

oracle11g使用DBA_DATAPUBMP_JOBS和DBA_DATAPUMP_SESSIONS视图来显示数据泵取作业的信息,
查看expdp进度:

select * from DBA_DATAPUBMP_JOBS;
select * from DBA_DATAPUMP_SESSIONS;
select sid,serial# from v$session s,dba_datapump_sessions d where s.saddr=d.saddr;

查看impdp进度:

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(+);

查看RMAN备份进度:

SELECT SID,OPNAME, SERIAL#, CONTEXT, SOFAR, TOTALWORK,
ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
FROM V$SESSION_LONGOPS
WHERE OPNAME LIKE 'RMAN%'
AND OPNAME NOT LIKE '%aggregate%'
AND TOTALWORK != 0
AND SOFAR <> TOTALWORK
order by "%_COMPLETE"
desc

使用SQL查看SQLServer数据库还原进度

在做数据库备份还原的时候,忘记添加stats关键字了,Messages窗口什么也没有提示。这种情况下,该如何去监控我的备份或者还原数据库进度呢? 其实,这种情况也无需紧张,我们同样有办法来监控数据库备份还原的进度,方法是使用动态管理视图sys.dm_exec_requests配合一些关键信息字段来监控进度。方法如下:

USE master
GO

SELECT 
    req.session_id, 
    database_name = db_name(req.database_id),
    req.status,
    req.blocking_session_id, 
    req.command,
    [sql_text] = Substring(txt.TEXT, (req.statement_start_offset / 2) + 1, (
                (
                    CASE req.statement_end_offset
                        WHEN - 1 THEN Datalength(txt.TEXT)
                        ELSE req.statement_end_offset
                    END - req.statement_start_offset
                    ) / 2
                ) + 1),
    req.percent_complete,
    req.start_time,
    cpu_time_sec = req.cpu_time / 1000,
    granted_query_memory_mb = CONVERT(NUMERIC(8, 2), req.granted_query_memory / 128.),
    req.reads,
    req.logical_reads,
    req.writes,
    eta_completion_time = DATEADD(ms, req.[estimated_completion_time], GETDATE()),
    elapsed_min = CONVERT(NUMERIC(6, 2), req.[total_elapsed_time] / 1000.0 / 60.0),
    remaning_eta_min = CONVERT(NUMERIC(6, 2), req.[estimated_completion_time] / 1000.0 / 60.0),
    eta_hours = CONVERT(NUMERIC(6, 2), req.[estimated_completion_time] / 1000.0 / 60.0/ 60.0),
    wait_type,
    wait_time_sec = wait_time/1000, 
    wait_resource
FROM sys.dm_exec_requests as req WITH(NOLOCK)
    CROSS APPLY sys.dm_exec_sql_text(req.sql_handle) as txt 
WHERE req.session_id>50
    AND command IN ('BACKUP DATABASE', 'BACKUP LOG', 'RESTORE DATABASE', 'RESTORE LOG')

执行以后会显示备份还原进度,
a26dd79b1a9e1b048a8d4e492e31ba36.png
结果中有非常多重要的字段信息,比如:


Command: 表示命令种类,此处表示备份数据库命令

sql_text: 语句详细信息,此处展示了完整的T-SQL语句

percent_complete: 进度完成百分比,此处已经完成了59.67%

start_time:进程开始执行时间

eta_completion_time:进程预计结束时间

等等。这种方法除了可以监控数据库备份还原进度外,还可以获取更多的进程信息,是比较推荐的方法。

提示: 这种方法不仅仅是可以用来监控你的备份还原进程,任何其他的用户进程都可以使用类似的方法来监控,你只需要把WHERE语句稍作修改即可。比如:想要监控某一个进程的进度情况,你只需要把WHERE语句修改为WHERE req.session_id=xxx即可。
VIA:http://mysql.taobao.org/monthly/2018/04/06/

最新

分类

归档

评论

其它