Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

Article 1

$
0
0

Scripts to bounce the database to Archivelog mode and Flashback mode



set echo off
set feedb off
set heading off
set verify off
set trimspool on
set lines 200
set define on
SET SERVEROUTPUT ON SIZE 1000000

-- variable sid varchar2
-- col sid new_value sid format a12
-- select sys_context('userenv', 'db_name') sid from dual;
-- select '&&sid' from dual;

define spoolfile=${DBADGM}/tmp/${ORACLE_SID}_bounce_db_alfbon.sql

spool &&spoolfile;

DECLARE
    lv_LOG_MODE     VARCHAR2(12)  := NULL;
    lv_FLASHBACK_ON VARCHAR2(18)  := NULL;
    lv_sql          VARCHAR2(400) := NULL;
BEGIN
    SELECT log_mode, flashback_on
      INTO lv_LOG_MODE, lv_FLASHBACK_ON
    FROM V$DATABASE;

    -- DBMS_OUTPUT.PUT_LINE ('connect / as sysdba');
    IF lv_LOG_MODE='NOARCHIVELOG' AND lv_FLASHBACK_ON='NO' THEN
        DBMS_OUTPUT.PUT_LINE ('shutdown immediate');
        DBMS_OUTPUT.PUT_LINE ('startup mount');
        DBMS_OUTPUT.PUT_LINE ('alter database archivelog;');
        DBMS_OUTPUT.PUT_LINE ('alter database flashback on;' );
        DBMS_OUTPUT.PUT_LINE ('alter database open;');
    ELSIF lv_LOG_MODE='NOARCHIVELOG' AND lv_FLASHBACK_ON='YES' THEN
        DBMS_OUTPUT.PUT_LINE ('shutdown immediate');
        DBMS_OUTPUT.PUT_LINE ('startup mount');
        DBMS_OUTPUT.PUT_LINE ('alter database archivelog;');
        DBMS_OUTPUT.PUT_LINE ('alter database open;');
    ELSIF lv_LOG_MODE='ARCHIVELOG' AND lv_FLASHBACK_ON='NO' THEN
        DBMS_OUTPUT.PUT_LINE ('shutdown immediate');
        DBMS_OUTPUT.PUT_LINE ('startup mount');
        DBMS_OUTPUT.PUT_LINE ('alter database flashback on;' );
        DBMS_OUTPUT.PUT_LINE ('alter database open;');
    ELSE
        DBMS_OUTPUT.PUT_LINE ('@database');
        DBMS_OUTPUT.PUT_LINE ('@dg_database');
    END IF;

    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            RAISE_APPLICATION_ERROR(-20900, SQLERRM);
END;
/

spool off

set termout on
set heading on

@&&spoolfile;
!rm &&spoolfile

undefine spoolfile


Viewing all articles
Browse latest Browse all 1640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>