12c Dataguard: Restore Datafile From Service
12c Dataguard: Recover From Service
12c Multitenant: Super-fast Provisioning Of Standby Databases
Category Archives: Uncategorized
12c Dataguard: Restore Data File From Service
Starting with Oracle Database 12c, in a Data Guard environment, you can restore data files on a primary (standby) database by connecting to a standby (primary) database over the network .
RMAN restores database files, over the network, from the physical standby (primary) database by using the FROM SERVICE clause of the RESTORE command. The FROM SERVICE clause provides the service name of the physical standby (primary) database from which the files must be restored. During the restore operation, RMAN creates backup sets, on the physical standby database (primary), of the files that need to be restored and then transfers these backup sets to the target database over the network.”
Optionally, you can use SECTION SIZE
to restore files from the source database as multisection backup sets. You can also compress the transferred files by specifying the USING COMPRESSED BACKUPSET
.
Prerequisites for restoring Files from remote host :
- The password file on the source database and the target database must be the same.
- The
tnsnames.ora
file in the target database must contain an entry that corresponds to the remote database.
In this post, I will demonstrate restore of a data file on primary from standby using service clause of RMAN Restore command.
Current scenario:
- Primary CDB : Boston
- Physical Standby CDB : London
- PDB : Dev1
– Create a new tablespace called sample in PDB dev1 on primary (boston)
BOSTON>alter session set container=dev1; create tablespace sample datafile '/u01/app/oracle/oradata/boston/dev1/sample01.dbf' size 5m;
– Verify that parameter standby_file_management = auto
on standby database (london)
LONDON>sho parameter standby_file
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
standby_file_management string AUTO
– Verify that datafile for tablespace sample has been created on physical standby (london)
LONDON>select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/london/system01.dbf
/u01/app/oracle/oradata/london/sysaux01.dbf
/u01/app/oracle/oradata/london/undotbs01.dbf
/u01/app/oracle/oradata/london/pdbseed/system01.dbf
/u01/app/oracle/oradata/london/users01.dbf
/u01/app/oracle/oradata/london/pdbseed/sysaux01.dbf
/u01/app/oracle/oradata/london/dev1/system01.dbf
/u01/app/oracle/oradata/london/dev1/sysaux01.dbf
/u01/app/oracle/oradata/london/dev1/SAMPLE_SCHEMA_users01.dbf
/u01/app/oracle/oradata/london/dev1/example01.dbf
/u01/app/oracle/oradata/london/dev1/sample01.dbf
– Create table hr.employees2 in new tablespace sample on primary
BOSTON>sho con_name CON_NAME ------------------------------ DEV1 BOSTON>create table hr.employees2 tablespace sample as select * from hr.employees; select count(*) from hr.employees2; COUNT(*) ---------- 107
– To simulate loss of datafile, rename sample01.dbf to sample01.sav on primary host
BOSTON>!mv /u01/app/oracle/oradata/boston/dev1/sample01.dbf /u01/app/oracle/oradata/boston/dev1/sample01.sav
– Restart primary – error while opening as datafile is missing
BOSTON>conn / as sysdba shu abort; startup Database mounted. ORA-01157: cannot identify/lock data file 12 - see DBWR trace file ORA-01110: data file 12: '/u01/app/oracle/oradata/boston/dev1/sample01.dbf'
– Take the missing datafile offline on primary and then open primary database
BOSTON>alter session set container=dev1; alter tablespace sample datafile offline; alter session set container=cdb$root; alter database open; BOSTON>sho pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 DEV1 MOUNTED BOSTON>alter pluggable database dev1 open;
-- Connect to primary (boston) using RMAN
[oracle@host01 ~]$ . oraenv
ORACLE_SID = [boston] ?
[oracle@host01 ~]$ rman target /
-- Restore datafile from physical standby database (london) over network
RMAN> restore tablespace dev1:sample from service 'london';
Starting restore at 23-JAN-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: using network backup set from service london
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00012 to /u01/app/oracle/oradata/boston/dev1/sample01.dbf
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 23-JAN-15
– Recover the restored tablespace using archivelogs available
locally on primary database (boston)
RMAN> recover tablespace dev1:sample; Starting recover at 23-JAN-15 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:01 Finished recover at 23-JAN-15
– Bring tablespce online
BOSTON>alter session set container=dev1; alter tablespace sample datafile online; select count(*) from hr.employees2; COUNT(*) ---------- 107 Note: As mentioned by a reader, datafile can be restored over network in 11g as well using auxiliary connection (rman target sys/@PRIMARY_db auxiliary sys/@STANDBY_db) as is demonstrated in this post. But this syntax supports only image copy backups and not backupset / compressed backupsets. The restore from service in 12c supports backupset and compressed backupset as well resulting in reduced network traffic. I hope this post was useful. Your comments and suggestions are always welcome.
References:
https://docs.oracle.com/database/121/RCMRF/rcmsynta2008.htm#RCMRF149
http://docs.oracle.com/database/121/BRADV/rcmadvre.htm#BRADV681
——————————————————————————–
Related Links :
Recover Standby Datafile From Primary (11g)
———————
OTNYathra 2015
The Oracle ACE directors and Java champions will be organizing an evangelist event called ‘OTNYathra 2015’ during February 2015. during which a series of 7 conferences will be held across 7 major cities of India in a time period of 2 weeks. This event will bring the Oracle community together, spread the knowledge and increase the networking opportunities in the region. The detailed information about the event can be viewed at http://www.otnyathra.com.
I will be presenting a session on Adaptive Query Optimization on 13th Feb 2015 at FMDI, Sector 17B, IFFCO Chowk , Gurgaon.
Thanks to Sir Murali Vallath and his team for organizing it and giving me an opportunity to present.
Hope to see you there!!
Map OS Groups To Administrative Privileges After Installation
During installing database software, user is prompted to enter names of various operating system groups mapping to various administrative privileges (SYSDBA, SYSOPER, SYSBACKUP, SYSKM, SYSDG). One might map one operating system group to multiple administrative privileges if role separation is not desired. In case the need for role separation arises later, the mapping can be specified by updating $ORACLE_HOME/rdbms/lib/config.c file and then relinking it. This post explains the various steps.
While installing database 12.1.0.2 software on linux, I had not created OS groups corresponding to administrative privileges SYSBACKUP, SYSKM, SYSDG. Now I want OS groups dgdba, backupdba and kmdba to map to SYSDG, SYSBACKUP and SYSKM administrative privileges respectively.
-- Check that groups dgdba, backupdba and kmdba do not exist
[root@host01 etc]# cat /etc/group | grep dba dba:x:501:oracle
– Create groups dgdba, backupdba and kmdba
#groupadd -g 54321 dgdba groupadd -g 54322 backupdba groupadd -g 54323 kmdba
– Check that groups dgdba, backupdba and kmdba have been created
[root@host01 etc]# cat /etc/group | grep dba dba:x:501:oracle dgdba:x:54321: backupdba:x:54322: kmdba:x:54323:
– Create a user test which is a member of dgdba group
[root@host01 /]# useradd test -g oinstall -G dgdba [root@host01 /]# passwd test Changing password for user test. New UNIX password:
– Login as test user
[root@host01 /]# su - test [test@host01 ~]$ . oraenv ORACLE_SID = [test] ? orcl
– As test user try to connect as sysdg – fails as dgdba group
has not been mapped to SYSDG administrative privilege
[test@host01 ~]$ dgmgrl DGMGRL> connect sysdg/xx ORA-01017: invalid username/password; logon denied Warning: You are no longer connected to ORACLE.
– Verify in configuration file that currently OS group dba corresponds to administrative priviliges SYSDBA, SYSKM, SYSDG and SYSBACKUP
[oracle@host01 ~]$ cat $ORACLE_HOME/rdbms/lib/config.c |grep define /* SS_DBA_GRP defines the UNIX group ID for sqldba adminstrative access. */ #define SS_DBA_GRP "dba" #define SS_OPER_GRP "oper" #define SS_ASM_GRP "" #define SS_BKP_GRP "dba" #define SS_DGD_GRP "dba" #define SS_KMT_GRP "dba"
– Edit configuration file so that OS groups dgdba, backupdba and kmdba to map to SYSDG, SYSBACKUP and SYSKM administrative privileges respectively.
[oracle@host01 ~]$ vi $ORACLE_HOME/rdbms/lib/config.c #define SS_DBA_GRP "dba" #define SS_OPER_GRP "oper" #define SS_ASM_GRP "" #define SS_BKP_GRP "backupdba" #define SS_DGD_GRP "dgdba" #define SS_KMT_GRP "kmdba"
– To relink oracle binaries, Shut down all Oracle processes of all instances
a. Shut down the listener.
$ lsnrctl stop
b. Shut down all instances.
$ ps -ef |grep pmon |grep -v grep
oracle 11832 1 0 15:21 ? 00:00:00 ora_pmon_orcl
ORCL> shutdown immediate
— Relink binaries
[oracle@host01 ~]$ cd $ORACLE_HOME/bin; relink all writing relink log to: /u01/app/oracle/product/12.1.0.2/dbhome_1/install/relink.log
– Now as test user connect as sysdg – succeeds
[test@host01 bin]$ dgmgrl
DGMGRL> connect sysdg/xx
Connected as SYSDG.
– Optionally modify existing OS user oracle to become part of new groups
#usermod -a -G dgdba,backupdba,kmdba oracle
[root@host01 /]# su - oracle
[oracle@host01 ~]$ id
uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba),502(oper),503(asmadmin),54321(dgdba),54322(backupdba),54323(kmdba)
Hope it helps!
Your comments and suggestions are always welcome.
References:
https://community.oracle.com/message/12806120?et=watches.email.thread#12806120
https://www.linkedin.com/groups/Map-OS-Groups-Administrative-Privileges-3698383.S.5964260145260216320?view=&item=5964260145260216320&type=member&gid=3698383&trk=eml-b2_anet_digest-hero-1-hero-disc-disc-0&midToken=AQE9SYOdN_UFjg&fromEmail=fromEmail&ut=1fAfQMlI9DO6A1
==============================================================
Related Links:
Oracle Ace Associate
It gives me immense pleasure to share with you the news that
“I am an Oracle Ace Associate“.
Thanks to the “Oracle ACE Program” for accepting me to receive the Oracle ACE Associate award.
My heart is full of gratitude for Sir Murali Vallath who nominated me for this.
Thanks to AIOUG for giving me an opportunity to speak during SANGAM 14 and publishing my white paper on ‘Histograms – Pre-12c and now” in Oracle Connect Issue Dec 2014.
I want to thank my husband for encouraging me, and readers of my blog for their time, comments and suggestions.
Thank you so much!
Oracleinaction.com in 2014 : A review
The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 320,000 times in 2014 with an average of 879 page views per day. If it were an exhibit at the Louvre Museum, it would take about 14 days for that many people to see it.
The busiest day of the year was December 1st with 1,656 views. The most popular post that day was ORACLE CHECKPOINTS.
These are the posts that got the most views on ORACLE IN ACTION in 2014.
- 11g R2 RAC : VOTING DISK DEMYSTIFIED
- ORACLE CHECKPOINTS
- 11g R2 RAC: Highly Available IP (HAIP)
- ORA-01102: cannot mount database in EXCLUSIVE mode
- Undocumented Parameters in Oracle 11g
The blog was visited by readers from 194 countries in all!
Most visitors came from India. The United States & U.K. were not far behind.
Thanks to all the visitors.
Keep visiting and giving your valuable feedback.
Wish you all a Very Happy New Year 2015 !!!!!
Create Histograms On Columns That Already Have One
The default value of METHOD_OPT from 10g onwards is ‘FOR ALL COLUMNS SIZE AUTO’.
The definition of AUTO as per Oracle documentation is :
AUTO: Oracle determines the columns to collect histograms based on data distribution and the workload of the columns.
This basically implies that Oracle will automatically create histograms on those columns which have skewed data distribution and there are SQL statements referencing those columns.
However, this gives rise to the problem is that Oracle generates too many unnecessary histograms .
Let’s demonstrate:
– Create a table with skewed data distribution in two columns
SQL>drop table hr.skewed purge; create table hr.skewed ( empno number, job_id varchar2(10), salary number); insert into hr.skewed select employee_id, job_id, salary from hr.employees;
– On gathering statistics for the table using default options, it can be seen that histogram is not gathered on any column although data
distribution in columns JOB_ID and SALARY is skewed
SQL>exec dbms_stats.gather_table_stats('HR','SKEWED'); col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY NONE SKEWED JOB_ID NONE SKEWED EMPNO NONE
– Let’s now issue some queries querying the table based on the three columns in the table followed by statistics gathering to verify that histograms get automatically created only on columns with skewed data distribution.
– No histogram gets created if column EMPNO is queried which
has data distributed uniformly
SQL>select * from hr.skewed where empno = 100; exec dbms_stats.gather_table_stats('HR','SKEWED'); col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY NONE SKEWED JOB_ID NONE SKEWED EMPNO NONE
– A histogram gets created on JOB_ID column as soon as we search for records with a JOB_ID as data distribution is non-uniform in JOB_ID column
SQL>select * from hr.skewed where job_id = 'CLERK'; exec dbms_stats.gather_table_stats('HR','SKEWED'); col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY NONE SKEWED JOB_ID FREQUENCY SKEWED EMPNO NONE
– A histogram gets created on SALARY column when search is made for employees drawing salary more than 10000 as data distribution is non-uniform in SALARY column.
SQL>select * from hr.skewed where salary < 10000; exec dbms_stats.gather_table_stats('HR','SKEWED'); col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY FREQUENCY SKEWED JOB_ID FREQUENCY SKEWED EMPNO NONE
Thus gathering statistics using default options, manually or as part of the automatic maintenance task, might lead to creation of histograms on all such columns which have skewed data distribution and had been part of the search clause even once. That is, Oracle makes even the histograms you didn’t ask for. Some of the histograms might not be needed by the application and hence are undesirable as computing histograms is a resource intensive operation and moreover they might degrade the performance as a result of their interaction with bind peeking.
Solution
Employ FOR ALL COLUMNS SIZE REPEAT option of METHOD_OPT parameter which prevents deletion of existing histograms and collects histograms only on the columns that already have histograms.
First step is to eliminate unwanted histograms and have histograms only on the desired columns.
Well, there are two options:
OPTION-I: Delete histograms from unwanted columns and use REPEAT option henceforth which Collects histograms only on the columns that already have histograms.
– Delete unwanted histogram for SALARY column
SQL>exec dbms_stats.gather_table_stats('HR','SKEWED', - METHOD_OPT => 'for columns salary size 1'); -- Verify that histogram for salary column has been deleted col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY NONE SKEWED JOB_ID FREQUENCY SKEWED EMPNO NONE
– Issue a SQL with salary column in where clause and verify that gathering stats using repeat option retains histogram on JOB_ID column and does not cause histogram to be created on salary column.
SQL>select * from hr.skewed where salary < 10000; exec dbms_stats.gather_table_stats('HR','SKEWED',- METHOD_OPT => 'for columns salary size REPEAT'); col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY NONE SKEWED JOB_ID FREQUENCY SKEWED EMPNO NONE
OPTION-II: Wipe out all histograms and manually add only the desired ones. Use REPEAT option henceforth which Collects histograms only on the columns that already have one.
– Delete histograms on all columns
SQL>exec dbms_stats.gather_table_stats('HR','SKEWED',-
METHOD_OPT => 'for all columns size 1');
– Verify that histograms on all columns have been dropped
SQL>col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY NONE SKEWED JOB_ID NONE SKEWED EMPNO NONE
– Create histogram only on the desired JOB_ID column
SQL>exec dbms_stats.gather_table_stats('HR','SKEWED',-
METHOD_OPT => 'for columns JOB_ID size AUTO');
– Verify that histogram has been created on JOB_ID
SQL>col table_name for a10
col column_name for a10
select TABLE_NAME,COLUMN_NAME,HISTOGRAM
from dba_tab_columns where table_name = 'SKEWED';
TABLE_NAME COLUMN_NAM HISTOGRAM
---------- ---------- ---------------
SKEWED SALARY NONE
SKEWED JOB_ID FREQUENCY
SKEWED EMPNO NONE
- Verify that gathering stats using repeat option creates histogram only on JOB_ID column on which it already exists
SQL>exec dbms_stats.gather_table_stats('HR','SKEWED',- METHOD_OPT => 'for columns salary size REPEAT'); SQL>col table_name for a10 col column_name for a10 select TABLE_NAME,COLUMN_NAME,HISTOGRAM from dba_tab_columns where table_name = 'SKEWED'; TABLE_NAME COLUMN_NAM HISTOGRAM ---------- ---------- --------------- SKEWED SALARY NONE SKEWED JOB_ID FREQUENCY SKEWED EMPNO NONE
That is, now Oracle will no longer make histograms you didn’t ask for.
– Finally, change the preference for METHOD_OPT parameter of automatic stats gathering job from default value of AUTO to REPEAT so that it will gather histograms only for the columns already having one.
– Get Current value –
SQL> select dbms_stats.get_prefs ('METHOD_OPT') from dual;
DBMS_STATS.GET_PREFS('METHOD_OPT')
-----------------------------------------------------------------------
FOR ALL COLUMNS SIZE AUTO
– Set preference to REPEAT–
SQL> exec dbms_stats.set_global_prefs ('METHOD_OPT','FOR ALL COLUMNS SIZE REPEAT');
– Verify –
SQL> select dbms_stats.get_prefs ('METHOD_OPT') from dual;
DBMS_STATS.GET_PREFS('METHOD_OPT')
-----------------------------------------------------------------------
FOR ALL COLUMNS SIZE REPEAT
From now onwards, gathering of statistics, manually or automatically will not create any new histograms while retaining all the existing ones.
I hope this post is useful.
Happy reading….
References:
https://blogs.oracle.com/optimizer/entry/how_does_the_method_opt
http://www.pythian.com/blog/stabilize-oracle-10gs-bind-peeking-behaviour/
https://richardfoote.wordpress.com/2008/01/04/dbms_stats-method_opt-default-behaviour-changed-in-10g-be-careful/
———————————————————————————————–
Related Links:
———————————————————————————————