Showing posts with label rman. Show all posts
Showing posts with label rman. Show all posts

Friday, 9 January 2015

How to reuse already restored datafiles when recovering database with datafiles rename

Problem

It happens few times a year I have to prepare some test environments, which are complete copies of production databases. Because in such situation everything is compliant with a production environment, I do not have to deal with architecture change so the best way is simply to make a use of RMAN backups, which are stored on tapes somewhere within a backup system.

The task is then quite easy. I produce something like the following:
CONNECT target /
CONNECT catalog rman/xxx@rman_catalog
SPOOL LOG TO restore_db_20141202.log
RUN {
ALLOCATE CHANNEL t1 TYPE 'SBT_TAPE' FORMAT '<backup file name format>' 
PARMS 'ENV=(<backup system specific options>)';
SET UNTIL TIME "to_date('2014-11-30 00:11:00','yyyy-mm-dd hh24:mi:ss')";
RESTORE CONTROLFILE;
ALTER DATABASE MOUNT;
sql "ALTER DATABASE DISABLE BLOCK CHANGE TRACKING";
SET NEWNAME FOR DATABASE TO NEW;
RESTORE DATABASE;
SWITCH DATAFILE ALL;
SWITCH TEMPFILE ALL;
RECOVER DATABASE DELETE ARCHIVELOG MAXSIZE 90G;
RELEASE CHANNEL t1;
}
As You may see I rename all the database files to something new. I do not do this everytime, but sometimes I have on such new environment differently named mount points or sometimes a production database has some history so not all files are kept on the same mount point, while on test environment this is convenient to calculate whole database size, allocate such amount in one resource and mount it under one location.
In this script this location is not specified explicitly - I 'd rather like to set db_create_file_dest parameter of instance - thus also a possibly newly created files are placed on the same path.

Then I run the script and very often I do not have to do anything until the process will end successfully. Yet from time to time shit happens :-( and 9 of 10 cases in our shop it is a temporary problem with the backup system or at least with a communication with it - in case of small databases this would not be a big deal, but first I never met it and second even starting from scratch for a 50G means only a part of an hour.
The real problem is with quite big databases (few TB) and we have one case where it is almost frequent, where the connection to the backup system is done through LAN (in opposition to SAN). Such operation takes at least few days and after few TB restored, while still in a restore phase, we meet a crash.
Some of datafiles are fully restored, some partially, some not at all and yet in v$datafile exist only old file names and for a first sight there is no mapping between newly restored files and metadata content stored within the controlfile.
Below there is a short how to deal with this situation.

Solution

First of all You have to look into views v$datafile_header and v$datafile_copy. The v$datafile_copy should keep names of the newly created files (name is not null and completion_time><some date before running the restore and recover operation>) - then it is easy to create a script, which instead of switching to a new name would switch to the already restored files.
select
'set newname for datafile '||x.file#||' to '||x.descr||';' rman_cmd
from (
select d.file#, 'new' descr from v$datafile d
minus
select c.file#, 'new' descr 
from v$datafile_copy c where c.completion_time > sysdate-5
union all
select c.file#, ''''||c.name||'''' descr 
from v$datafile_copy c where c.completion_time > sysdate-5
) x
order by x.file#
Now we take the above output, paste it into previous script, remove restore controlfile and mount commands and run - the RMAN will check the restored datafiles status, keeps the fully restored intact while restoring those fuzzy or not-yet-restored. And that's it.
Final output will look like this:
CONNECT target /
CONNECT catalog rman/xxx@rman_catalog
SPOOL LOG TO restore_db_20141202.log
RUN {
ALLOCATE CHANNEL t1 TYPE 'SBT_TAPE' FORMAT '<backup file name format>' 
PARMS 'ENV=(<backup system specific options>)';
SET UNTIL TIME "to_date('2014-11-30 00:11:00','yyyy-mm-dd hh24:mi:ss')";

# here changes - while it may seem trivial and unimportant let's look at the file id
# with few thousands of files this saves a lot of work 
SET NEwNAME FOR DATAFILE    1 TO '/{path_to_data}/o1_mf_system_c99zgdp4_.dbf';
SET NEwNAME FOR DATAFILE    2 TO '/{path_to_data}/o1_mf_undotbs1_c99nq5c3_.dbf';
SET NEwNAME FOR DATAFILE    3 TO '/{path_to_data}/o1_mf_sysaux_c99op8h2_.dbf';
SET NEwNAME FOR DATAFILE    4 TO '/{path_to_data}/o1_mf_users_c99ysv13_.dbf';
SET NEwNAME FOR DATAFILE    5 TO new;
SET NEwNAME FOR DATAFILE    6 TO new;
[..]
SET NEwNAME FOR DATAFILE 1419 TO '/{path_to_data}/o1_mf_tstas1_d__c99tghry_.dbf';
SET NEwNAME FOR DATAFILE 1422 TO '/{path_to_data}/o1_mf_tstidx_d_c99zswmb_.dbf';

RESTORE DATABASE;
SWITCH DATAFILE ALL;
SWITCH TEMPFILE ALL;
RECOVER DATABASE DELETE ARCHIVELOG MAXSIZE 90G;
RELEASE CHANNEL t1;
}

Thursday, 27 March 2014

Duplicating with rman

The assumption is to create a copy of the database on the same host in order to run 2 independent database instances. It can be done in many ways:

  • with RMAN 
  • with expdp and standard dump
  • with expdp and transportable tablespaces
  • with cp command and dbnewid tool - look here
I present here one of the possible ways with the RMAN utility:
  1. check if the database is set in ARCHIVELOG
    select log_mode from v$database;
    -- if the answer is NOARCHIVELOG then
    shutdown immediate; 
    startup mount
    alter database archivelog;
    alter database open;
    
  2. prepare auxiliary instance
    • create directories for the clone database
      Here I am not sure entirely at the moment how it works. I provided explicite in the parameter file the value for the control_files and am quite certain that have to create the directory myself. In case of datafiles and redologs, if one first sets new names to new, then the RMAN creates directories according to the OMF methodology.
      mkdir -p /oracle/oradata/NEWSID/controlfile
      mkdir -p /oracle/oradata/NEWSID/datafile #optional
      mkdir -p /oracle/oradata/NEWSID/onlinelog #optional
      
    • create spfile for the clone database (if this is not a standby then the only requirement is DB_NAME)
      export ORACLE_SID=NEWSID
      sqlplus / as sysdba
      
      All the OMF settings indicate the same location - it does not make sense to set both db_create_online_log_dest_1 and db_create_online_log_dest_2 to the same value unless one works on some kind of enterprise class storage.
      create pfile='NEWSID.pfile' from spfile;
      
      *.audit_file_dest='/home/oracle/admin/NEWSID/adump'
      *.compatible='11.2.0.3.0'
      *.control_files='/oracle/oradata/NEWSID/controlfile/control01.ctl'
      *.db_block_size=8192
      *.db_create_file_dest='/oracle/oradata/'
      *.db_create_online_log_dest_1='/oracle/oradata/' 
      *.db_create_online_log_dest_2='/oracle/oradata/'
      *.db_domain=example.com
      *.db_file_multiblock_read_count=16
      *.db_files=800
      *.db_name=NEWSID
      *.diagnostic_dest='/oracle'
      *.job_queue_processes=1000
      *.nls_language='POLISH'
      *.nls_territory='POLAND'
      *.open_cursors=300
      *.pga_aggregate_target=512M
      *.processes=1000
      *.remote_login_passwordfile='EXCLUSIVE'
      *.service_names='NEWSID'
      *.sessions=1105
      *.sga_target=800M
      *.undo_management='AUTO'
      *.undo_tablespace='UNDOTBS1'
      
      create spfile from pfile='NEWSID.pfile';
      
    • copy password file
      cp orapwOLDSID orapwNEWSID
    • add static definition of the clone database to listener.ora
      # static definitions
      SID_LIST_LISTENER =
        (SID_LIST =
          ## this part is not necessary
          (SID_DESC =
            (GLOBAL_DBNAME = OLDSID.dev.example.com)
            (ORACLE_HOME = /oracle/product/11.2.0.2)
            (SID_NAME = OLDSID)
          )
          ## this part is mandatory
          (SID_DESC =
            (GLOBAL_DBNAME = NEWSID.dev.example.com)
            (ORACLE_HOME = /oracle/product/11.2.0.2)
            (SID_NAME = NEWSID)
          )
        )
      
      # listener definition prepared for dynamic registration
      LISTENER=
        (DESCRIPTION=
            (ADDRESS=(PROTOCOL=tcp)(HOST=test-dbcluster-01)(PORT=1521)))
      
      
      After such changes in the listener definition it is not enough simply reload. One have to stop and start the listener.
    • run the clone instance
      startup mount
  3. run the duplicate command in RMAN
    connect target sys/sys01@OLDSID.example.com
    connect auxiliary sys/sys01@NEWSID.example.com
    run {
      ## this setting sets all the files to indicated directory
      ## and changes file names to %U format
      #SET NEWNAME FOR DATABASE TO '/oracle/oradata/%U';
      ## this setting is compatible with the OMF
      SET NEWNAME FOR DATABASE TO NEW; 
      DUPLICATE TARGET DATABASE to transpl
      FROM ACTIVE DATABASE;
    }
    

Thursday, 14 November 2013

The ORA-00001 while resyncing the catalog

Lately I switched over a database to the standby. All went well until I faced the RMAN configuration. Usually there are problems with archived logs, which were backed up on the previous primary node and I usually deal with that calling CROSSCHECK ARCHIVELOG ALL;
This time however I have got the following:


RMAN> resync catalog;

starting full resync of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of resync command on default channel at 10/24/2013 22:57:29
ORA-00001: unique constraint (RMAN.TS_U3) violated

I registered an SR on the MOS, and they stated I probably hit the BUG:12597985 - RMAN RESYNC CATALOG GOT ORA-1 and may install some patch or use workaround in the form:

unregister database;
register database;

I went on with the provided workaround and hit the following:

RMAN> unregister database;

database name is "YYYYYY" and DBID is 688900000

Do you really want to unregister the database (enter YES or NO)? YES
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06004: ORACLE error from recovery catalog database: 
ORA-02292: integrity constraint (RMAN.TSATT_F2) violated - child record found

Now I was informed this time it is a Bug 9799518 RMAN-6004 / ORA-2292 trying to unregister a database from an RMAN catalog and again I can install a patch. I would like to avoid the patch installation, so I did something else. Below the solution:

RMAN> unregister database;

database name is "YYYYYY" and DBID is 688900000

Do you really want to unregister the database (enter YES or NO)? YES
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06004: ORACLE error from recovery catalog database: 
ORA-02292: integrity constraint (RMAN.TSATT_F2) violated - child record found

# here from sqlplus I disabled RMAN.TSATT_F2
# select table_name from dba_constraints where constraint_name='TSATT_F2';
# alter table TSATT modify constraint TSATT_F2 disable;

RMAN> unregister database;

database name is "YYYYYY" and DBID is 688900000

Do you really want to unregister the database (enter YES or NO)? YES
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06004: ORACLE error from recovery catalog database: 
ORA-02292: integrity constraint (RMAN.TSATT_F3) violated - child record found

# here from sqlplus I disabled RMAN.TSATT_F3
# alter table rman.TSATT modify constraint TSATT_F3 disable;

RMAN> unregister database;

database name is "YYYYYY" and DBID is 688900000

Do you really want to unregister the database (enter YES or NO)? YES
database unregistered from the recovery catalog

# here I found the orphaned rows in the TSATT table and delete them - according to the expectations 
# these were the rows making both the constraints unable to be enabled
# after the deletion I enabled the constraints disabled previously
# delete from RMAN.TSATT T where not exists (select 1 from RMAN.CKP C where C.CKP_KEY=T.START_CKP_KEY) ;
# delete from RMAN.TSATT T where not exists (select 1 from RMAN.CKP C where C.C3626503034KP_KEY=T.END_CKP_KEY) ;
# most possibly both queries above would touch the same rows

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

Tuesday, 6 December 2011

BACKUP_TAPE_IO_SLAVES

Initial steps

Since today we start to enable the BACKUP_TAPE_IO_SLAVES parameter.
What has changed:
  • for a while when RMAN runs the RDBMS launches an additional process, which reports in alert.log, for example
    Running KSFV I/O slave I601 os pid=8282
    KSFV I/O slave I601 dp=f2e24c020 exiting
  • this process uses a memory allocated from LARGE_POOL (or SHARED_POOL if the former is not allocated) instead of private memory of the RMAN session process
  • all the RMAN IO operations to SBT device since then are seen as asynchronous ones (of course this is kind of "fake" asynchronous IO similar in shape to the architecture with DBWR_IO_SLAVES set to non-zero value)
  • thus the IO operations are reported in V$BACKUP_ASYNCH_IO (previously V$BACKUP_SYNCH_IO)
  • the following waits have a place here:
    • os thread startup (which is certainly a start of KSFV IO slave)
    • imm op (which is the event specific for RMAN with IO slaves in use)
    • io done (I found that this one is specific for synchronous IO operations, which may mean that this is wait reported by KSFV IO slave and that's why it is "fake" asynchronous IO)
    • control file sequential read
.
For both ways there are in use 4 buffers with 256K each. For relatively short operations (for example frequent backup of archivelogs) there is no difference to be seen.

Update (after 3 years of usage)

This time we go the other way round by switching off this parameter. The main reason is processes Ixxx are not stable. We had it on on 2 kinds of os-es - AIX and Solaris. On Solaris we switched it off after some crash and today (2014.02.12) we experienced a crash on AIX, so eventually we disable it on our machines completely.
And below some details concerned with today's crash:
  • we experienced a number of ORA-7445 errors in a sequence
  • ORA-07445: exception encountered: core dump [PC:0x900000002A3993C] [SIGSEGV]] [ADDR:0x100A10000FDDE0] [PC:0x900000002A3993C] [Address not mapped to object] []
  • call stack:
    skdstdst()+40 -> ksedst1()+104 -> ksedst()+40 -> dbkedDefDump()+2828 -> ksedmp()+76 -> ssexhd()+2448 -> 48bc


Update

Today a colleague of mine found a system, where the backup did not work properly. The launch of backup returned
ORA-17619: max number of processes using I/O slaves in a instance reached
The docs say it happens when there are more than 35 processes, which are controlling some IO slaves. In this particular example there were some backup processes, which lasted for few months already and never completed.

Update

Today (18 Sep 2018) on some db I 've found again ORA-17619. As this article has already few years, forget about it. Googled the net as well as Metalink resources, not much suggestions - finally found this article and checked for open orphaned rman sessions - that's it.
I thought about too many parallel slaves, while in fact this is simply a number of all the sessions opened by rman - somewhere there exists a counter, which counts processes from rman, but they do not need to be parallel (as in PX queries) - they simply exist at the same time.
In this particular example the sessions were opened at the different times across the period of 2 months.
This select may help to choose the old sessions - please note I had to kill those on the OS level, so by looking for SPID in v$process (simple session kill switched sessions in the KILLED status, but they have not gone)
select paddr||' '||logon_time||' '||module||' '||status
  ||' alter system kill session '''||sid||','||serial#||''' immediate;' 
from v$session where program like 'rman%' order by logon_time;
-- one may also further obtain also the PID of an underlying OS process 
select spid from v$process where addr='';