Canalblog
Editer l'article Suivre ce blog Administration + Créer mon blog
Publicité
Blog d'un DBA sur le SGBD Oracle et SQL
5 janvier 2021

RMAN : le contenu des fichiers internes - RMAN: the content of internal files

 

Introduction
J'ai déjà abordé dans deux posts sur RMAN la possibilité donnée par Oracle de connaître de façon intime le fonctionnement de ce logiciel :
- utilisation de la trace 10046 : http://dbaoraclesql.canalblog.com/archives/2020/07/03/38409831.html
- utilisation du mode debug : http://dbaoraclesql.canalblog.com/archives/2020/06/30/38402501.html

Pour ceux que cela intéresse vraiment, il est possible d'explorer encore plus intimement, via des fichiers, le fonctionnement interne de RMAN. 

Mais ne vous faites pas d'illusion, comme dans les posts précédents, que ce soit la trace 10046 ou le mode Debug, ces fichiers sont peu utiles pour une utilisation quotidienne de RMAN et s'adressent plus à des experts de cet outil voir au support Oracle.

 



Points d'attention
N/A.




Base de tests
Une base Oracle 18c multi-tenants.




Exemples

============================================================================================
Les fichiers RMAN
============================================================================================ 
Ces fichiers se trouvent dans $ORACLE_HOME/rdbms/admin.
     [oracle@vbgeneric admin]$ pwd
     /u01/app/oracle/product/12.2/db_1/rdbms/admin

Les fichiers avec rman dans leur nom sont au nombre de six.
     [oracle@vbgeneric admin]$ ls -l *rman*
     -rw-r--r-- 1 oracle oinstall 168007 Jan 26 2017 dbmsrman.sql
     -rw-r--r-- 1 oracle oinstall 6341 Apr 1 2016 dbmsrmansys.sql
     -rw-r--r-- 1 oracle oinstall 29982 Mar 10 2015 dbmsrmanvpc.sql
     -rw-r--r-- 1 oracle oinstall 16100 Mar 30 2009 prgrmanc.sql
     -rw-r--r-- 1 oracle oinstall 9016 Jan 5 2016 rman.pl
     -rw-r--r-- 1 oracle oinstall 147789 Jan 5 2016 rman.pm

Il y en a un autre, de type .bsq, qui est aussi très intéressant : recover.bsq.


Les trois à explorer en priorité sont :

     $ORACLE_HOME/rdbms/admin/recover.bsq
     $ORACLE_HOME/rdbms/admin/dbmsrman.sql
     $ORACLE_HOME/rdbms/admin/dbmsbkrs.sql

Attention, certains sont de taille conséquente : 146 000 lignes pour recover.bsq alors que d'autres sont de taille plus, comment dire, accessible.

     [oracle@vbgeneric admin]$ wc -l recover.bsq
     146767 recover.bsq

     [oracle@vbgeneric admin]$ wc -l *rman*

     4554 dbmsrman.sql
     214 dbmsrmansys.sql
     1045 dbmsrmanvpc.sql
     507 prgrmanc.sql
     295 rman.pl
     4795 rman.pm
     11410 total


recover.bsq
Commençons par recover.bsq dont voici l'en-tête.

     [oracle@vbgeneric admin]$ view recover.bsq
     # Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
     #
     ## ****************************************************************************
     ## * RECOVER.BSQ is now a DERIVED OBJECT. If you are editing *
     ## * .../rdbms/admin/recover.bsq, STOP and edit *
     ## * .../rdbms/src/client/tools/rcvman/recover.txt instead. recover.bsq is *
     ## * derived from recover.txt, and any changes made directly to recover.bsq *
     ## * will be lost. *
     ## ****************************************************************************

Plusieurs tables y sont définies (et pas des vues, même si elles commencent par V$).

     define 'v$controlfile_record_section'
     <<<
     define table v$controlfile_record_section
     (
     TYPE VARCHAR2(128),
     RECORD_SIZE NUMBER,
     RECORDS_TOTAL NUMBER,
     RECORDS_USED NUMBER,
     FIRST_INDEX NUMBER,
     LAST_INDEX NUMBER,
     LAST_RECID NUMBER
     );
     >>>

     define 'v$controlfile'

     <<<
     define table v$controlfile
     (
     STATUS VARCHAR2(7),
     NAME VARCHAR2(513),
     IS_RECOVERY_DEST_FILE VARCHAR2(3),
     BLOCK_SIZE NUMBER,
     FILE_SIZE_BLKS NUMBER
     );
     >>>

Y sont définies aussi de nombreuses procédures, qui peuvent appeler les packages internes RMAN comme sys.dbms_backup_restore ou d'autres, non RMAN, comme krmicd.

     procedure getFileRestored(proxy IN boolean) IS
          firstcall boolean := TRUE;
          ftype binary_integer;
          thread binary_integer;
          sequence number;
          resetscn number;
          resetstamp number;
          fno binary_integer;
          callagain binary_integer;
          fname varchar2(1024);
     begin
          loop
               callagain := sys.dbms_backup_restore.fetchFileRestored(
                    firstcall => firstcall,
                    proxy => proxy,
                    ftype => ftype,
                    fno => fno,
                    thread => thread,
                    sequence => sequence,
                    resetscn => resetscn,
                    resetstamp => resetstamp,
                    fname => fname
                    );
               exit when callagain = 0;
               firstcall := FALSE;
               krmicd.fileRestored(ftype => ftype,
                    fno => fno,
                    thread => thread,
                    sequence => sequence,
                    resetscn => resetscn,
                    resetstamp => resetstamp,
                    fname => fname);
          end loop;
     end;


dbmsrman.sql
Dans dbmsrman.sql est défini le package dbms_rcvman (rcv pour ReCoVer), celui qu'Oracle utilise avec dbms_backup_restore pour les opérations RMAN; je ne mets ici qu'une petite partie du fichier.

     [oracle@vbgeneric admin]$ view dbmsrman.sql

La création du package; je n'en mets pas plus, à vous de voir si cela vous intéresse.

     create or replace package dbms_rcvman IS
     ...

Plusieurs types sont définis pour les opérations RMAN.
     TYPE restoreRange_t IS RECORD
     (
     lowTime DATE,
     highTime DATE,
     startScn NUMBER,
     lowScn NUMBER,
     highScn NUMBER,
     lowDbIncKey NUMBER,
     highDbIncKey NUMBER,
     lowRlgScn NUMBER,
     highRlgScn NUMBER,
     lowRlgTime DATE,
     highRlgTime DATE,
     rcvStartScn NUMBER,
     rcvStartTime DATE,
     isValidRange BOOLEAN,
     cfBkupFound BOOLEAN,
     con_id NUMBER
     );

On y trouve aussi plusieurs fonctions et procédures, avec parfois des commentaires.

     PROCEDURE setDatabase(
     db_name IN varchar2
     ,reset_scn IN number
     ,reset_time IN date
     ,db_id IN number
     ,db_unique_name IN varchar2 default NULL
     ,site_aware IN boolean default FALSE
     ,dummy_instance IN boolean default FALSE
     ,ors_instance IN boolean default FALSE);
     -- Return the db_unique_name associated with the db_id if there is one
     -- db_unique_name. If there is more than one db_unique_name, then raise
     -- too_many_rows error. If there is no row, then return NULL.

     FUNCTION getDbUniqueName(

     db_id IN number)
     RETURN varchar2;

     PROCEDURE getAlBackupHistory(

     backedUpDev IN varchar2
     ,first IN boolean
     ,bhistoryRec OUT NOCOPY bhistoryRec_t
     ,doingCmd IN varchar2 DEFAULT NULL
     ,keepTag IN varchar2 DEFAULT NULL
     ,toDest1 IN varchar2 DEFAULT NULL
     ,toDest2 IN varchar2 DEFAULT NULL
     ,toDest3 IN varchar2 DEFAULT NULL
     ,toDest4 IN varchar2 DEFAULT NULL);


dbmsbkrs.sql
Le fichier dbmsbkrs.sql lui, contient la définition du package dbms_backup_restore; il a aussi énormément de commentaires de la part des développeurs Oracle, dont certaines précieux, mais là, à vous de les trouver :-)

     create or replace
     PACKAGE dbms_backup_restore IS
     ...
     --***************
     -- Introduction
     --***************
     -- This package contains the interface to the kernel for creating and
     -- restoring backups of datafiles and archived logs. Backups can exist on
     -- sequential media such as tape. The kernel will read and write backups,
     -- but it is the responsibility of the caller to catalog the names of the
     -- backups.
     ...

C'est ici qu'on définit les procédures de restauration des backups :-)

     --********************************
     -- Restoration from Backup Piece--
     --*******************************--
     -- The third phase of a restore conversation is to read the pieces that
     -- make up the backup set and write the output files specified in the second
     -- phase. It is impossible to check for errors such as specifying a file
     -- that is not in the backup set until the first piece is read. Errors while
     -- processing a backup piece do not terminate the conversation. If the error
     -- can be repaired (e.g. the correct file is found or the hardware is
     -- fixed), the piece may be successfully reread and restored. However if the
     -- conversation is terminated, the entire backup set must be reread in a new
     -- restore conversation.

     PROCEDURE restoreBackupPiece( handle IN varchar2

     ,done OUT boolean
     ,params IN varchar2 default NULL
     ,fromdisk IN boolean default FALSE );

     PROCEDURE applyBackupPiece( handle IN varchar2

     ,done OUT boolean
     ,params IN varchar2 default NULL );

     -- These procedures read one backup piece and write its contents to the

     -- files in the restore list.
     -- restoreBackupPiece creates files from complete backups.
     -- applyBackupPiece applies incremental backups to existing datafiles.
     --
     -- As soon as each target file is complete, records will be created in
     -- the appropriate controlfile tables. Records may be created in the
     -- following tables, depending on the type of restore conversation:
     --
     -- V$DATAFILE_COPY
     -- V$COPY_CORRUPTION
     -- V$ARCHIVED_LOG
     -- If this was the last piece containing data required to restore the
     -- requested objects, then the "done" parameter is set to TRUE and the
     -- conversation is over. All resources allocated for the conversation are
     -- released.
     --
     -- Input parameters:
     -- handle
     -- The handle of the backup piece to restore from.
     -- params
     -- This string is simply passed to the sequential file open OSD. It is
     -- completely port and device specific.
     -- fromdisk
     -- TRUE if the backuppiece is from device disk. Used to dynamically
     -- allocate a disk context in SBT channel
     -- Output parameters:
     -- done
     -- TRUE if all requested objects have been completely restored, FALSE
     -- otherwise. Note that the restore may complete before we reach
     -- the last piece of the backup set. It is an error to call any of
     -- these procedures after "done" is set to TRUE.
     -- Exceptions:
     ...
     -- DATABASE-NOT-MOUNTED (ora-1507)
     -- The database is not mounted.
     -- DEVICE-NOT-ALLOCATED (ora-19569)
     -- This session does not have a device allocated.
     -- NO-FILES (ora-19581)
     -- No files have been specified for restoration so there is nothing
     -- to restore.
     ...
     -- RECORD-NOT-FOUND (ora-xxxx)
     -- One of the files specified in the list of files to restore is not
     -- in the backup set. For applying offline ranges in a controlfile
     -- this error is returned when there is no offline range for the file.
     -- This error is only returned on the first piece of a backup set.
     -- WRONG-RESETLOGS
     -- Atempting to apply an incremental backup to a datafile with a
     -- different resetlogs time stamp. This error will not occur when
     -- applying a controlfile if the datafile is checkpointed cleanly
     -- at the beginning SCN of the offline range.

Tiens, si je veux supprimer des fichiers, c'est la procédure deleteFile qui sera appelée.

     --***************************
     -- Miscellaneous Procedures
     --***************************
     PROCEDURE deleteFile( fname IN varchar2 );
     -- Delete a file from the operating system. The operating system is called
     -- to delete the file name given. The effect of processes that already have
     -- the file open may differ between platforms. Note that this has no effect
     -- on the state of the database or controlfile. There are no checks to insure
     -- that the file is not part of the database. This may be done at any time.
     --
     -- WARNING! This procedure should not be used to delete files that are named
     -- by controlfile entries. Use deleteDataFile, or deleteRedoLog. Those
     -- routines will mark the controlfile entries as obsolete so that they no
     -- longer appear in V$ tables.
     --
     -- Input parameters:
     -- fname
     -- Name of the operating system file to delete
     -- Exceptions:
     -- FNAME-NOT-SPECIFIED (ora-19634)
     -- The fname must be specified and may not be null.
     -- DELETE-ERROR
     -- An error was reported by the OSD to delete the file.



Bon je m'arrête là, le contenu de ces fchiers est trop pointu MAIS les commentaires, dans dbmsbkrs.sql, peuvent vous aider à mieux comprendre comment fonctionne RMAN.

Publicité
Publicité
Commentaires
Blog d'un DBA sur le SGBD Oracle et SQL
Publicité
Archives
Blog d'un DBA sur le SGBD Oracle et SQL
  • Blog d'un administrateur de bases de données Oracle sur le SGBD Oracle et sur les langages SQL et PL/SQL. Mon objectif est de vous faire découvrir des subtilités de ce logiciel, des astuces, voir même des surprises :-)
  • Accueil du blog
  • Créer un blog avec CanalBlog
Visiteurs
Depuis la création 340 939
Publicité