ExaGridDba

database startup trigger branches depending on resetlogs

Nov 2nd, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 3.87 KB | None | 0 0
  1. This logon TRIGGER branches depending ON whether the CURRENT database OPEN was normal OR reset logs.
  2.  
  3. This port IS IN response TO "Know if database has been activated by failover or switchover"
  4. BY Franck Pachot
  5. https://community.oracle.com/message/13385190
  6.  
  7. CREATE OR REPLACE TRIGGER dbstartup_trig
  8. after startup ON database
  9. DECLARE
  10.         l_resetlogs_startup_time        dba_hist_database_instance.startup_time%TYPE;
  11.         l_startup_time                  dba_hist_database_instance.startup_time%TYPE;
  12.         l_first_change# NUMBER;
  13.         l_first_time    DATE;
  14.         l_sequence#     NUMBER;
  15.         l_msg clob;
  16.  
  17.         FUNCTION ts ( p_ts IN TIMESTAMP ) RETURN VARCHAR2
  18.         IS
  19.         BEGIN
  20.                 RETURN TO_CHAR( p_ts ,'yyyy-mm-dd hh24:mi:ss.ff3' );
  21.         END ts;
  22. BEGIN
  23.         alertlog_pkg.printf( 'systimestamp=%s', ts( SYSTIMESTAMP ) );
  24.  
  25.         SELECT MIN(startup_time), MAX(startup_time)
  26.         INTO l_resetlogs_startup_time, l_startup_time
  27.         FROM dba_hist_database_instance
  28.         WHERE startup_time > ( SELECT resetlogs_time FROM v$database );
  29.  
  30.         alertlog_pkg.printf( 'l_resetlogs_startup_time=%s', ts( l_resetlogs_startup_time ) );
  31.         alertlog_pkg.printf( 'startup_time=%s', ts( l_startup_time ) );
  32.  
  33.         IF l_startup_time = l_resetlogs_startup_time
  34.         THEN
  35.                 alertlog_pkg.printf( 'started up with resetlogs' );
  36.         ELSE
  37.                 alertlog_pkg.printf( 'started up without resetlogs' );
  38.         END IF;
  39.  
  40.         SELECT MAX( sequence# ), MAX ( first_change# ), MAX ( first_time )
  41.         INTO l_sequence#, l_first_change#, l_first_time
  42.         FROM v$log;
  43.  
  44.         alertlog_pkg.printf( 'sequence#=%s', l_sequence# );
  45.         alertlog_pkg.printf( 'first_change#=%s', l_first_change# );
  46.         alertlog_pkg.printf( 'first_time=%s', ts( l_first_time ) );
  47.  
  48.  
  49. END dbstartup_trig;
  50. /
  51.  
  52. Normal OPEN AND resetlogs OPEN:
  53.  
  54.  
  55. SQL*Plus: RELEASE 12.1.0.2.0 Production ON Mon Nov 2 22:04:39 2015
  56.  
  57. Copyright (c) 1982, 2014, Oracle.  ALL rights reserved.
  58.  
  59.  
  60. Connected TO:
  61. Oracle Database 12c Enterprise Edition RELEASE 12.1.0.2.0 - 64bit Production
  62. WITH the Partitioning, Automatic Storage Management, OLAP, Advanced Analytics
  63. AND REAL Application Testing options
  64.  
  65. SQL> shutdown IMMEDIATE
  66. Database closed.
  67. Database dismounted.
  68. ORACLE instance shut down.
  69. SQL> startup
  70. ORACLE instance started.
  71.  
  72. Total System Global Area 6190792704 bytes
  73. Fixed Size                  2938064 bytes
  74. Variable Size            1191185200 bytes
  75. Database Buffers         4982833152 bytes
  76. Redo Buffers               13836288 bytes
  77. Database mounted.
  78. Database opened.
  79. SQL> @ flashback.db.TO.rp.SQL
  80.  
  81. no rows selected
  82.  
  83. flashback database IS enabled
  84.  
  85. no rows selected
  86.  
  87. a guaranteed restore point EXISTS
  88.  
  89. NAME
  90. --------------------------------------------------------------------------------
  91. RP_20151102_2100
  92.  
  93. RP_20151102_2100
  94. ORACLE instance started.
  95.  
  96. Total System Global Area 6190792704 bytes
  97. Fixed Size                  2938064 bytes
  98. Variable Size            1191185200 bytes
  99. Database Buffers         4982833152 bytes
  100. Redo Buffers               13836288 bytes
  101. Database mounted.
  102. old   1: flashback database TO restore point &&rpname
  103. NEW   1: flashback database TO restore point RP_20151102_2100
  104.  
  105. Flashback complete.
  106.  
  107.  
  108. Database altered.
  109.  
  110. TRIGGER output after normal OPEN:
  111.  
  112. Mon Nov 02 22:06:24 2015
  113. SYSTIMESTAMP=2015-11-02 22:06:23.553
  114. l_resetlogs_startup_time=2015-11-02 21:02:01.000
  115. startup_time=2015-11-02 22:05:56.000
  116. started up without resetlogs
  117. sequence#=2
  118. first_change#=33762826
  119. first_time=2015-11-02 22:04:33.000
  120.  
  121. TRIGGER output after OPEN resetlogs:
  122.  
  123. Mon Nov 02 22:08:08 2015
  124. SYSTIMESTAMP=2015-11-02 22:08:08.282
  125. l_resetlogs_startup_time=2015-11-02 22:07:21.000
  126. startup_time=2015-11-02 22:07:21.000
  127. started up WITH resetlogs
  128. sequence#=1
  129. first_change#=33753627
  130. first_time=2015-11-02 22:07:08.000
Advertisement
Add Comment
Please, Sign In to add comment