Sei sulla pagina 1di 27

run { allocate channel proddb1 type disk; allocate channel proddb2 type disk; allocate channel proddb3 type

disk; allocate auxiliary channel stddb3 type disk; duplicate target database for standby from active database spfile parameter_value_convert 'stddb3,proddb' set log_archive_config='DG_CONFIG=(stddb1,proddb,stddb2,stddb3)' set db_file_name_convert='/vol1/oradata/proddb','/vol1/oradata/stddb3','/vol1/or adata/stddb3','/vol1/oradata/stddb1','/vol1/oradata/stddb3','/vol1/oradata/stddb 2' set log_file_name_convert='/app/oracle/admin/proddb/flash_recovery_area/PRODDB/o nlinelog', '/app/oracle/admin/stddb3/flash_recovery_area/STDDB3/o nlinelog', '/app/oracle/admin/stddb3/flash_recovery_area/STDDB3/o nlinelog', '/app/oracle/admin/stddb1/flash_recovery_area/STDDB1/o nlinelog' '/app/oracle/admin/stddb3/flash_recovery_area/STDDB3/o nlinelog', '/app/oracle/admin/stddb2/flash_recovery_area/STDDB2/o nlinelog' set DISPATCHERS='(PROTOCOL=TCP)(SERVICE=stddb3XDB)' set control_files='/vol1/oradata/proddb/control01.ctl' set db_recovery_file_dest='/app/oracle/admin/stddb3/flash_recovery_area' set db_recovery_file_dest_size='10248M' nofilenamecheck; }

run { allocate channel proddb1 type disk; allocate channel proddb2 type disk; allocate channel proddb3 type disk; allocate auxiliary channel proddb type disk; duplicate target database for standby from active database spfile parameter_value_convert 'stddb1,proddb' set log_archive_config='DG_CONFIG=(stddb1,proddb,stddb2)' set db_file_name_convert='/vol1/oradata/stddb1','/vol1/oradata/proddb','/vol1/or adata/stddb1','/vol1/oradata/stddb2' set log_file_name_convert='/app/oracle/admin/stddb1/flash_recovery_area/STDDB1/o nlinelog', '/app/oracle/admin/proddb/flash_recovery_area/PRODDB/o nlinelog', '/app/oracle/admin/stddb1/flash_recovery_area/STDDB1/o nlinelog', '/app/oracle/admin/stddb2/flash_recovery_area/STDDB2/o nlinelog' set DISPATCHERS='(PROTOCOL=TCP)(SERVICE=proddbXDB)' set control_files='/vol1/oradata/proddb/control01.ctl' set db_recovery_file_dest='/app/oracle/admin/proddb/flash_recovery_area' set db_recovery_file_dest_size='10248M' nofilenamecheck; }

dgmgrl DGMGRL> connect sys/oracle@proddb DGMGRL> create configuration dg_project as primary database is proddb connect id entifier is proddb; DGMGRL> add database stddb1 as connect identifier is stddb1 maintained as physic al; DGMGRL> add database stddb2 as connect identifier is stddb2 maintained as physic al; DGMGRL> enable configuration; DGMGRL> show configuration; DGMGRL> enable database proddb; DGMGRL> enable database stddb1; DGMGRL> enable database stddb2; DGMGRL> edit database proddb set property FastStartFailoverTarget='stddb1'; DGMGRL> edit database stddb1 set property FastStartFailoverTarget='proddb'; DGMGRL> edit database stddb2 set property FastStartFailoverTarget='proddb'; DGMGRL> edit database proddb set property LogXptMode='SYNC'; DGMGRL> edit database stddb1 set property LogXptMode='SYNC'; DGMGRL> edit database stddb2 set property LogXptMode='SYNC'; DGMGRL> edit configuration SET PROTECTION MODE AS MaxAvailability; DGMGRL> enable fast_start failover; DGMGRL> start observer file='/backup/Proddb.log'; SQL> conn sys/oracle@proddb as sysdba SQL> select name, open_mode, database_role from v$database; SQL> create pfile='/app/oracle/admin/proddb/pfile/initproddb.ora' from spfile SQL> shu immediate; SQL> startup pfile='/app/oracle/admin/stdby/pfile/initstdby_new.ora' nomount; SQL> create spfile from pfile='/app/oracle/admin/stdby/pfile/initstdby_new.ora'; SQL> shu immediate; SQL> startup mount; SQL> alter database flashback on; SQL> archive log list; SQL> alter database recover managed standby database using current logfile disco nnect;

alter system set log_archive_config='DG_CONFIG=(proddb,stddb1,stddb2)' scope=spf ile alter system set db_file_name_convert='/vol1/oradata/proddb','/vol1/oradata/stdd b1','/vol1/oradata/proddb','/vol1/oradata/stddb2' scope=spfile; alter system set log_file_name_convert= '/app/oracle/admin/proddb/flash_recovery_area/PRODDB/onlinelog', '/app/oracle/ad min/stddb1/flash_recovery_area/STDDB1/onlinelog', '/app/oracle/admin/proddb/flash_recovery_area/PRODDB/onlinelog', '/app/oracle/ad min/stddb2/flash_recovery_area/STDDB2/onlinelog' scope=spfile alter system set log_archive_config='DG_CONFIG=(proddb,stddb1,stddb2)' scope=spf ile alter system set db_file_name_convert = '/vol1/oradata/proddb','/vol1/oradata/stddb1', '/vol1/oradata/stddb1','/vol1/oradata/stddb2' scope=spfile; alter system set log_file_name_convert=

'/app/oracle/admin/proddb/flash_recovery_area/PRODDB/onlinelog', '/app/oracle/ad min/stddb1/flash_recovery_area/STDDB1/onlinelog', '/app/oracle/admin/stddb1/flash_recovery_area/STDDB1/onlinelog', '/app/oracle/ad min/stddb2/flash_recovery_area/STDDB2/onlinelog' scope=spfile alter system set log_archive_config='DG_CONFIG=(proddb,stddb1,stddb2)' scope=spf ile alter system set db_file_name_convert = '/vol1/oradata/proddb','/vol1/oradata/stddb2', '/vol1/oradata/stddb2','/vol1/oradata/stddb1' scope=spfile; alter system set log_file_name_convert= '/app/oracle/admin/proddb/flash_recovery_area/PRODDB/onlinelog', '/app/oracle/ad min/stddb2/flash_recovery_area/STDDB2/onlinelog', '/app/oracle/admin/stddb2/flash_recovery_area/STDDB2/onlinelog', '/app/oracle/ad min/stddb1/flash_recovery_area/STDDB1/onlinelog' scope=spfile alter system set log_archive_dest_2='SERVICE=stddb1 LGWR SYNC VALID_FOR=(ONLINE_ LOGFILES, PRIMARY_ROLE) DB_UNIQUE_NAME=stddb1' alter system set log_archive_dest_3='SERVICE=stddb2 LGWR SYNC VALID_FOR=(ONLINE_ LOGFILES, PRIMARY_ROLE) DB_UNIQUE_NAME=stddb2' ALTER SYSTEM SET LOG_ARCHIVE_DEST_4='SERVICE=stddb3 LGWR SYNC VALID_FOR=(ONLINE_ LOGFILES, PRIMARY_ROLE) DB_UNIQUE_NAME=stddb3' ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_4='ENABLE'; On Primary Database ==================== Supplemental logging on the primary database generates additional information in the redo log. That info. Is then used during the redo application process in th e standby database to make sure the correct rows are affected by the generated S QL. To see whether supplemental logging is enabled, start a SQL session and query th e V$DATABASE fixed view. For example, enter: SQL> SELECT SUPPLEMENTAL_LOG_DATA_PK, SUPPLEMENTAL_LOG_DATA_UI FROM V$DATABASE; SUP SUP --- --YES YES If supplemental logging is not enabled, execute the following statements: SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE INDEX) COLUMN S; Database altered.

================================================ alter system set log_archive_dest_3='location=/app/oracle/admin/stddb3/archive v alid_for=(standby_logfiles,standby_role) db_unique_name=standby' scope=spfile; ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_3='ENABLE'; SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = proddb) (ORACLE_HOME = /app/oracle/product/11.2.0/db_1) (SID_NAME = proddb) ) (SID_DESC = (GLOBAL_DBNAME =proddb_DGMGRL) (ORACLE_HOME = /app/oracle/product/11.2.0/db_1) (SID_NAME = proddb) ) (SID_DESC = (GLOBAL_DBNAME = stddb1) (ORACLE_HOME = /app/oracle/product/11.2.0/db_1) (SID_NAME = stddb1) ) (SID_DESC = (GLOBAL_DBNAME = stddb1_DGMGRL) (ORACLE_HOME = /app/oracle/product/11.2.0/db_1) (SID_NAME = stddb1) ) (SID_DESC = (GLOBAL_DBNAME = stddb2) (ORACLE_HOME = /app/oracle/product/11.2.0/db_1) (SID_NAME = stddb2) ) (SID_DESC = (GLOBAL_DBNAME = stddb2_DGMGRL) (ORACLE_HOME = /app/oracle/product/11.2.0/db_1) (SID_NAME = stddb2) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.20.251.61)(PORT = 1521)) ) ADR_BASE_LISTENER = /app/oracle proddb = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL=TCP)(HOST = 172.20.251.61)(PORT=1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = proddb_DGMGRL) ) ) stddb1 =

(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL=TCP)(HOST = 172.20.251.117)(PORT=1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stddb1_DGMGRL) ) ) stddb2 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL=TCP)(HOST = 172.20.251.129)(PORT=1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stddb2_DGMGRL) ) )

orapwd file=orapwproddb password=oracle entries=5 force=y ignorecase=y orapwd file=orapwstddb1 password=oracle entries=5 force=y ignorecase=y # listener.ora ================================================================ SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = testdb) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = testdb) ) (SID_DESC = (GLOBAL_DBNAME = stdby) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = stdby) ) (SID_DESC = (GLOBAL_DBNAME =testdb_DGMGRL) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = testdb) ) (SID_DESC = (GLOBAL_DBNAME = stdby_DGMGRL) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = stdby) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521)) )

ADR_BASE_LISTENER = /app/oracle tnsnames.ora testdb = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL=TCP)(HOST = localhost.localdomain)(PORT=1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = testdb_DGMGRL) ) ) failure of backup command on c3 channel at stdby = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL=TCP)(HOST = localhost.localdomain)(PORT=1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stdby_DGMGRL) ) ) inittestdb.ora ======================================> db_name='testdb' db_unique_name='testdb' db_block_size=8192 sga_max_size=2048M sga_target=1536M db_recovery_file_dest='/app/oracle/admin/testdb/flash_recovery_area' db_recovery_file_dest_size=10G diagnostic_dest='/app/oracle' dispatchers='(PROTOCOL=TCP)(SERVICE=testdbXDB)' remote_login_passwordfile='EXCLUSIVE' undo_tablespace=undotbs1 undo_management=auto control_files='/vol1/oradata/testdb/control01.ora' compatible='11.1.0' log_archive_config='DG_CONFIG=(testdb,stdby)' log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES, ALL_ROLES) DB_UNIQUE_NAME=testdb' log_archive_dest_2='SERVICE=stdby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES, PRIMARY_ROLE) DB_UNIQUE_NAME=stdby' log_archive_dest_state_1='ENABLE' log_archive_dest_state_2='ENABLE' log_archive_format='%s_%t_%r.arc' standby_file_management=auto fal_client=testdb fal_server=stdby db_file_name_convert='/vol1/oradata/testdb','/vol1/oradata/stdby' log_file_name_convert='/app/oracle/admin/testdb/flash_recovery_area/TESTDB/onlin elog','/app/oracle/admin/stdby/flash_recovery_area/STDBY/onlinelog' dg_broker_config_file1='/app/oracle/admin/testdb/dgbroker1/dg1.dat'

dg_broker_config_file2='/app/oracle/admin/testdb/dgbroker2/dg2.dat' db_flashback_retention_target=1440 dg_broker_start=TRUE [oracle@localhost ~]$ sqlplus /nolog SQL> conn sys/systestdb@testdb as sysdba SQL> startup pfile='/app/oracle/admin/testdb/pfile/inittestdb.ora' nomount; SQL> create spfile from pfile='/app/oracle/admin/testdb/pfile/inittestdb.ora'; SQL> shu immediate; SQL> startup nomount; SQL> @/app/oracle/admin/testdb/create_db.sql; ******************************************************************************** ********************create database testdb user sys identified by systestdb user system identified by systestdb controlfile reuse force logging archivelog datafile '/vol1/oradata/testdb/system01.dbf' size 400M reuse autoextend on next 10240K maxsize unlimited sysaux datafile '/vol1/oradata/testdb/sysaux01.dbf' size 300M reuse autoextend o n next 5M maxsize 2048M default tablespace users datafile '/vol1/oradata/testdb/users01.dbf' size 20M re use autoextend on maxsize unlimited default temporary tablespace temp tempfile '/vol1/oradata/testdb/temp01.dbf' siz e 20M reuse autoextend on maxsize unlimited undo tablespace undotbs1 datafile '/vol1/oradata/testdb/undotbs01.dbf' size 50M reuse autoextend on maxsize unlimited logfile group 1 size 10M, group 2 size 10M, group 3 size 10M extent management local maxlogfiles 32 maxlogmembers 4 maxdatafiles 20show parameter log_archive_dest maxinstances 1; ******************************************************************************** ********************SQL> @?/rdbms/admin/catalog.sql SQL> @?/rdbms/admin/catproc.sql SQL> conn system/oracle@proddb SQL> @?/sqlplus/admin/pupbld.sql SQL> conn sys/oracle@proddb as sysdba SQL> shu immediate; SQL> startup mount; SQL> alter database flashback on; SQL> alter database open; SQL> archive log list; SQL> create tablespace tbsrman datafile '/vol1/oradata/proddb/tbsrman01.dbf' siz e 50M autoextend on next 1M maxsize unlimited extent management local segment sp ace management auto; SQL> alter database add standby logfile group 4 size 10M; SQL> alter database add standby logfile group 5 size 10M; SQL> alter database add standby logfile group 6 size 10M; SQL> alter database add standby logfile group 7 size 10M; SQL> alter database enable block change tracking using file '/app/oracle/admin/p roddb/flash_recovery_area/block_change_tracking.log'; SQL> create user rman identified by rman default tablespace tbsrman; SQL> grant connect, resource, recovery_catalog_owner to rman;

SQL> host rman RMAN> connect target sys/oracle@proddb RMAN> connect catalog rman/rman@proddb RMAN> create catalog tablespace 'TBSRMAN'; RMAN> register database; RMAN> resync catalog; RMAN> configure controlfile autobackup on; RMAN> configure backup optimization on;show parameter log_archive_dest RMAN> create script fullbackup { allocate channel c1 type disk; allocate channel c2 type disk; allocate channel c3 type disk; backup full tag weekly_backup database format '%U'; sql 'alter system archive log current'; backup archivelog all delete input; } RMAN> run {execute script fullbackup ;} [oracle@localhost ~]$ export ORACLE_SID=stdby [oracle@localhost ~]$ export ORACLE_HOME=/app/oracle/product/11.1.0/db_1 [oracle@localhost ~]$ sqlplus /nolog initstdby.ora ======================================> db_name='testdb' SQL> conn sys/systestdb@stdby as sysdba SQL> startup pfile='/app/oracle/admin/stdby/pfile/initstdby.ora' nomount; SQL> host rman RMAN> c sys/systestdb@testdb RMAN> connect auxiliary sys/systestdb@stdby RMAN> run { allocate channel testdb1 type disk; allocate channel testdb2 type disk; allocate channel testdb3 type disk; allocate auxiliary channel stdby1 type disk; duplicate target database for standby from active database spfile parameter_value_convert 'stdby','testdb' set log_archive_config='DG_CONFIG=(testdb,stdby)' set db_file_name_convert='/vol1/oradata/testdb','/vol1/oradata/stdby' set log_file_name_convert='/app/oracle/admin/testdb/flash_recovery_area/TESTDB/o nlinelog','/app/oracle/admin/stdby/flash_recovery_area/STDBY/onlinelog' set db_unique_name='stdby' set control_files='/vol1/oradata/stdby/control01.ctl' set db_recovery_file_dest='/app/oracle/admin/stdby/flash_recovery_area' set db_recovery_file_dest_size='10248M' nofilenamecheck; } ******************************************************************************** * Production database : proddb Calalog database : oeldb Standby database : stdby connect target sys/oracle@proddb connect catalog rman/rman@oeldb

connect auxiliary sys/oracle@stdby run { allocate channel proddb1 type disk; allocate channel proddb2 type disk; allocate channel proddb3 type disk; allocate auxiliary channel stdby1 type disk; duplicate target database for standby from active database spfile parameter_value_convert 'stdby','proddb' set log_archive_config='DG_CONFIG=(proddb,stdby)' set db_file_name_convert='/vol1/oradata/proddb','/vol1/oradata/stdby' set log_file_name_convert='/oracle/admin/proddb/flash_recovery_area/PRODDB/onlin elog','/oracle/admin/stdby/flash_recovery_area/STDBY/onlinelog' set db_unique_name='stdby' set control_files='/vol1/oradata/stdby/control01.ctl' set db_recovery_file_dest='/oracle/admin/stdby/flash_recovery_area' set db_recovery_file_dest_size='10248M' nofilenamecheck; } ******************************************************************************** * [oracle@localhost stdby]$ sqlplus /nolog SQL> conn sys/systestdb@stdby as sysdba SQL> select name, open_mode, database_role from v$database; SQL> create pfile='/app/oracle/admin/stdby/pfile/initstdby_new.ora' from spfile SQL> shu immediate; SQL> startup pfile='/app/oracle/admin/stdby/pfile/initstdby_new.ora' nomount; SQL> create spfile from pfile='/app/oracle/admin/stdby/pfile/initstdby_new.ora'; SQL> shu immediate; SQL> startup mount; SQL> alter database flashback on; SQL> archive log list; SQL> alter database recover managed standby database using current logfile disco nnect; SQL> alter system set "_log_deletion_policy"=ALL scope=spfile sid='*'; ******************************************************************************** ********************compatible='11.1.0' control_files='/vol1/oradata/stdby/control01.ctl' db_block_size=8192 db_file_name_convert='/vol1/oradata/testdb','/vol1/oradata/stdby' db_name='testdb' db_recovery_file_dest='/app/oracle/admin/stdby/flash_recovery_area' db_recovery_file_dest_size=10737418240 db_unique_name='stdby' diagnostic_dest='/app/oracle' dispatchers='(PROTOCOL=TCP)(SERVICE=stdbyXDB)' fal_client='STDBY' fal_server='TESTDB' log_archive_config='DG_CONFIG=(testdb,stdby)' log_archive_dest_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES, ALL_ROLES) DB_UNIQUE_NAME=stdby' log_archive_dest_2='SERVICE=testdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES, PRIMAR Y_ROLE) DB_UNIQUE_NAME=testdb' log_archive_dest_state_1='ENABLE' log_archive_dest_state_2='ENABLE' log_archive_format='%s_%t_%r.arc' log_file_name_convert='/app/oracle/admin/testdb/flash_recovery_area/TESTDB/onlin elog','/app/oracle/admin/testdb/flash_recovery_area/STDBY/onlinelog'

remote_login_passwordfile='EXCLUSIVE' sga_max_size=2048M sga_target=1536M standby_file_management='AUTO' undo_management='auto' undo_tablespace='undotbs1' db_flashback_retention_target=1440 dg_broker_config_file1='/app/oracle/admin/stdby/dgbroker1/dg1.bat' dg_broker_config_file2='/app/oracle/admin/stdby/dgbroker2/dg2.bat' dg_broker_start=true ******************************************************************************** ******************** [oracle@localhost ~]$ export ORACLE_SID=testdb [oracle@localhost ~]$ export ORACLE_HOME=/app/oracle/product/11.1.0/db_1 [oracle@localhost ~]$ dgmgrl -logfile /oracle/admin/dgmgrl.log sys/systestdb@tes tdb DGMGRL> connect sys/systestdb@testdb DGMGRL> create configuration dg_project as primary database is testdb connect id entifier is testdb; DGMGRL> add database stdby as connect identifier is stdby maintained as physical ; DGMGRL> enable configuration; DGMGRL> enable database testdb; DGMGRL> enable database stdby; DGMGRL> show configuration; DGMGRL> edit database proddb set property FastStartFailoverTarget='stddb1'; DGMGRL> edit database stddb1 set property FastStartFailoverTarget='stddb2'; DGMGRL> edit configuration set property FastStartFailoverThreshold=45; DGMGRL> edit configuration set property FastStartFailoverLaglimit=60; DGMGRL> edit database proddb set property LogXptMode='SYNC'; DGMGRL> edit database stdby set property LogXptMode='SYNC'; DGMGRL> edit configuration SET PROTECTION MODE AS MaxAvailability; DGMGRL> enable fast_start failover; DGMGRL> show site proddb DGMGRL> show site stdby DGMGRL> start observer; DGMGRL> show configuration; DGMGRL> switchover to stdby; [oracle@oel5 ~]$ export ORACLE_SID=stdby [oracle@oel5 ~]$ export ORACLE_HOME=/app/oracle/product/11.1.0/db_1 [oracle@oel5 ~]$ dgmgrl DGMGRL> connect sys/systestdb@stdby DGMGRL> switchover to testdb; [oracle@oel5 ~]$ export ORACLE_SID=stdby [oracle@oel5 ~]$ export ORACLE_HOME=/app/oracle/product/11.1.0/db_1 [oracle@oel5 ~]$ dgmgrl DGMGRL> connect sys/systestdb@stdby DGMGRL> disable fast_start failover; DGMGRL> convert database 'stdby' to snapshot standby; DGMGRL> convert database 'stdby' to physical standby; DGMGRL> show configuration; DGMGRL> enable fast_start failover; DGMGRL> show configuration; backup controlfile : ================================================================STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "proddb" NORESETLOGS FORCE LOGGING

NOARCHIVELOG MAXLOGFILES 32 MAXLOGMEMBERS 4 MAXDATAFILES 100 MAXINSTANCES 1 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/vol1/oradata/proddb/redo01a.log', '/vol1/oradata/proddb/redo01b.log' ) SIZE 50M, GROUP 2 ( '/vol1/oradata/proddb/redo02a.log', '/vol1/oradata/proddb/redo02b.log' ) SIZE 50M, GROUP 3 ( '/vol1/oradata/proddb/redo03a.log', '/vol1/oradata/proddb/redo03b.log' ) SIZE 50M DATAFILE '/vol1/oradata/proddb/system01.dbf', '/vol1/oradata/proddb/sysaux01.dbf', '/vol1/oradata/proddb/undotbs01.dbf', '/vol1/oradata/proddb/users01.dbf' CHARACTER SET US7ASCII ; RECOVER DATABASE ALTER DATABASE OPEN; -- Commands to add tempfiles to temporary tablespaces. -- Online tempfiles have complete space information. -- Other tempfiles may require adjustment. ALTER TABLESPACE TEMP ADD TEMPFILE '/vol1/oradata/proddb/temp01.dbf' SIZE 262144 00 REUSE AUTOEXTEND ON NEXT 1048576 MAXSIZE 32767M; -- End of tempfile additions. --Set #2. RESETLOGS case --- The following commands will create a new control file and use it -- to open the database. -- Data used by Recovery Manager will be lost. -- The contents of online logs will be lost and all backups will -- be invalidated. Use this only if online logs are damaged. -- After mounting the created controlfile, the following SQL -- statement will place the database in the appropriate -- protection mode: -- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "PRODDB" RESETLOGS FORCE LOGGING NOARCHIVELOG MAXLOGFILES 32 MAXLOGMEMBERS 4 MAXDATAFILES 100 MAXINSTANCES 1 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/vol1/oradata/proddb/redo01a.log', '/vol1/oradata/proddb/redo01b.log' ) SIZE 50M, GROUP 2 (

'/vol1/oradata/proddb/redo02a.log', '/vol1/oradata/proddb/redo02b.log' ) SIZE 50M, GROUP 3 ( '/vol1/oradata/proddb/redo03a.log', '/vol1/oradata/proddb/redo03b.log' ) SIZE 50M -- STANDBY LOGFILE DATAFILE '/vol1/oradata/proddb/system01.dbf', '/vol1/oradata/proddb/sysaux01.dbf', '/vol1/oradata/proddb/undotbs01.dbf', '/vol1/oradata/proddb/users01.dbf' CHARACTER SET US7ASCII ; -- Commands to re-create incarnation table -- Below log names MUST be changed to existing filenames on -- disk. Any one log file from each branch can be used to -- re-create incarnation records. -- ALTER DATABASE REGISTER LOGFILE '/oracle/admin/proddb/flash_recovery_area/PRO DDB/archivelog/2011_07_23/o1_mf_1_1_%u_.arc'; -- Recovery is required if any of the datafiles are restored backups, -- or if the last shutdown was not normal or immediate. RECOVER DATABASE USING BACKUP CONTROLFILE -- Database can now be opened zeroing the online logs. ALTER DATABASE OPEN RESETLOGS; -- Commands to add tempfiles to temporary tablespaces. -- Online tempfiles have complete space information. -- Other tempfiles may require adjustment. ALTER TABLESPACE TEMP ADD TEMPFILE '/vol1/oradata/proddb/temp01.dbf' SIZE 26214400 REUSE AUTOEXTEND ON NEXT 1048576 MAXSIZE 32767M; -- End of tempfile additions. SQL> show parameter shared_ NAME -----------------------------------max_shared_servers shared_memory_address shared_server_sessions shared_servers TYPE ----------integer integer integer integer VALUE ---------------------0 1

SQL> alter system set shared_servers=10 scope=both; System altered. SQL> alter system set max_shared_servers=30 scope=both; System altered. SQL> alter system set shared_server_sessions=100 scope=both; System altered. SQL> alter system set sessions=300 scope=spfile; SQL> show parameter shared_ NAME -----------------------------------max_shared_servers shared_memory_address TYPE ----------integer integer VALUE -----------------------------30 0

shared_server_sessions shared_servers SQL> show parameter dispa

integer integer

100 10

NAME TYPE VALUE ------------------------------------ ----------- -----------------------------dispatchers string (PROTOCOL=TCP) (SERVICE=rmandb XDB) max_dispatchers integer SQL> alter system set max_dispatchers=10 scope=both; System altered. SQL> alter system set dispatchers="(ADDRESS=(PROTOCOL=TCP)(HOST=oel5.4)(PORT=152 1))(DISPATCHERS=3)" scope=both; System altered. Shared Side =====================> 1. 2. 3. 4. Connection should be 'rmandb_s' alias for rmandb it should be connected to 'rmandb' it should use 'lsnr2' listener and port '1526' using shared connection

SQL> alter system set dispatchers="(ADDRESS=(PROTOCOL=TCP)(HOST=oel5.4)(PORT=152 6)(SERVICE=rmandb))(DISPATCHERS=3)" scope=both; System altered. SQL> alter system set local_listener="(ADDRESS=(PROTOCOL=TCP)(HOST=oel5.4)(PORT= 1526))" scope=both; System altered. SQL> conn sys/oracle@rmandb_s as sysdba Connected. '/app/oracle/admin/testdb/flash_recovery_area/TESTDB/onlinelog','/app/oracle/adm in/stdby/flash_recovery_area/STDBY/onlinelog' SQL> shu immediate; ORA-00106: cannot startup/shutdown database when connected to a dispatcher SQL> conn sys/oracle as sysdba SQL> startup; SQL> conn sys/oracle@rmandb_s as sysdba listener.ora : ============================ SID_LIST_LSNR2 = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = rmandb) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = rmandb) ) ) LSNR2 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1526))

) tnsnames.ora: ================================ RMANDB_S = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1526)) ) (CONNECT_DATA = (SERVER = SHARED) (SERVICE_NAME = rmandb) ) ) SQL> conn sys/oracle@rmandb_s as sysdba Connected. LSNRCTL> status lsnr2 Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oel5.4)(PORT=1526))) STATUS of the LISTENER -----------------------Alias lsnr2 Version TNSLSNR for Linux: Version 11.1.0.7.0 - Production Start Date 28-JUL-2011 11:48:38 Uptime 0 days 0 hr. 4 min. 10 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /app/oracle/product/11.1.0/db_1/network/admin/listener .ora Listener Log File /app/oracle/diag/tnslsnr/oel5/lsnr2/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oel5.4)(PORT=1526))) Services Summary... Service "rmandb" has 2 instance(s). Instance "rmandb", status UNKNOWN, has 1 handler(s) for this service... Instance "rmandb", status READY, has 2 handler(s) for this service... Service "rmandbXDB" has 1 instance(s). Instance "rmandb", status READY, has 1 handler(s) for this service... Service "rmandb_XPT" has 1 instance(s). Instance "rmandb", status READY, has 2 handler(s) for this service... The command completed successfully LSNRCTL> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Dedicated Connection : ============================================== SQL> conn sys/oracle@rmandb as sysdba Connected. 1. 2. 3. 4. Connection should be 'rmandb' alias for rmandb it should be connected to 'rmandb' it should use 'lsnr2' listener and port '1526' using dedicated connection

listener.ora : ============================ SID_LIST_LSNR2 =

(SID_LIST = (SID_DESC = (GLOBAL_DBNAME = rmandb) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = rmandb) ) ) LSNR2 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1526)) ) tnsnames.ora: ================================ RMANDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1526)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = rmandb) ) ) It connecting the below combinations : ===================================== SQL> conn sys/oracle@oel5.4:1526/rmandb as sysdba Connected. SQL> conn sys/oracle@oel5.4:1521/rmandb as sysdba Connected. SQL> conn sys/oracle@rmandb_s as sysdba Connected. SQL> conn sys/oracle@rmandb as sysdba Connected. listener.ora ======================================== SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = rmandb) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = rmandb) ) ) SID_LIST_LSNR2 = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = rmandb) (ORACLE_HOME = /app/oracle/product/11.1.0/db_1) (SID_NAME = rmandb) ) ) LISTENER = (DESCRIPTION =

(ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1521)) ) LSNR2 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1526)) ) RMANDB_S = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1526)) ) (CONNECT_DATA = (SERVER = SHARED) (SERVICE_NAME = rmandb) ) ) RMANDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1526)) (ADDRESS = (PROTOCOL = TCP)(HOST = oel5.4)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = rmandb) ) ) Note : Only 'lsnr2' is running for above 4 combinations and 'listener' is not ru nning ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Interval Partitioning Interval partitioning is an extension of range partitioning, where the system is able to create new partitions as they are required. The PARTITION BY RANGE clau se is used in the normal way to identify the transition point for the partition, then the new INTERVAL clause used to calculate the range for new partitions whe n the values go beyond the existing transition point. The following code shows an example of a table using interval partitioning. SQL> conn scott/tiger@testdb; SQL> 2 3 4 5 6 7 8 9 10 CREATE TABLE INTERVAL_TAB ( ID NUMBER, CODE VARCHAR2(20), DESCP VARCHAR2(20), CREATED_D DATE) PARTITION BY RANGE (CREATED_D) INTERVAL (NUMTOYMINTERVAL(1,'MONTH')) ( PARTITION PART_01 VALUES LESS THAN (TO_DATE('01-NOV-2007','DD-MON-YYYY')) );

Table created. Querying the USER_TAB_PARTITIONS view shows there is only a single partition.

SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'INTERVAL_TAB'); PL/SQL procedure successfully completed. SQL> COLUMN table_name FORMAT A20 SQL> COLUMN partition_name FORMAT A20 SQL> COLUMN high_value FORMAT A40 SQL> SELECT table_name, partition_name, high_value, num_rows 2 FROM user_tab_partitions 3 ORDER BY table_name, partition_name; Provided we insert data with a created_date value less than '01-NOV-2007' the da ta will be placed in the existing partition and no new partitions will be create d. SQL> INSERT INTO interval_tab VALUES (1, 'ONE', 'One', TO_DATE('16-OCT-2007', 'D D-MON-YYYY')); 1 row created. SQL> INSERT INTO interval_tab VALUES (2, 'TWO', 'Two', TO_DATE('31-OCT-2007', 'D D-MON-YYYY')); 1 row created. SQL> COMMIT; Commit complete. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'INTERVAL_TAB'); PL/SQL procedure successfully completed. SQL> SELECT table_name, partition_name, high_value, num_rows 2 FROM user_tab_partitions 3 ORDER BY table_name, partition_name; If we add data beyond the range of the existing partition, a new partition is cr eated. SQL> INSERT INTO interval_tab VALUES (3, 'THREE', 'Three', TO_DATE('01-NOV-2007' , 'DD-MON-YYYY')); 1 row created. SQL> INSERT INTO interval_tab VALUES (4, 'FOUR', 'Four', TO_DATE('30-NOV-2007', 'DD-MON-YYYY')); 1 row created. SQL> COMMIT; Commit complete. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'INTERVAL_TAB'); PL/SQL procedure successfully completed. SQL> SELECT table_name, partition_name, high_value, num_rows 2 FROM user_tab_partitions 3 ORDER BY table_name, partition_name;

If we insert data for two months after the current largest transition point, onl y the required partition is created, not the intervening partitions. SQL> INSERT INTO interval_tab VALUES (5, 'FIVE', 'Five', TO_DATE('01-JAN-2008', 'DD-MON-YYYY')); 1 row created. SQL> INSERT INTO interval_tab VALUES (4, 'FOUR', 'Four', TO_DATE('31-JAN-2008', 'DD-MON-YYYY')); 1 row created. SQL> COMMIT; Commit complete. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'INTERVAL_TAB'); PL/SQL procedure successfully completed. SQL> SELECT table_name, partition_name, high_value, num_rows 2 FROM user_tab_partitions 3 ORDER BY table_name, partition_name; TABLE_NAME PARTITION_NAME -------------------- -------------------HIGH_VALUE NUM_ROWS ---------------------------------------- ---------INTERVAL_TAB PART_01 TO_DATE(' 2007-11-01 00:00:00', 'SYYYY-M 2 M-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA INTERVAL_TAB SYS_P21 TO_DATE(' 2007-12-01 00:00:00', 'SYYYY-M M-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA INTERVAL_TAB SYS_P22 2

TABLE_NAME PARTITION_NAME -------------------- -------------------HIGH_VALUE NUM_ROWS ---------------------------------------- ---------TO_DATE(' 2008-02-01 00:00:00', 'SYYYY-M 2 M-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA Notice that a partition to hold January 2008 data has not been created. If we in sert data for this time period, the missing partition is created. SQL> INSERT INTO interval_tab VALUES (7, 'SEVEN', 'Seven', TO_DATE('01-DEC-2007' , 'DD-MON-YYYY')); 1 row created. SQL> INSERT INTO interval_tab VALUES (8, 'EIGHT', 'Eight', TO_DATE('31-DEC-2007' , 'DD-MON-YYYY'));

1 row created. SQL> COMMIT; Commit complete. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'INTERVAL_TAB'); PL/SQL procedure successfully completed. SQL> SELECT table_name, partition_name, high_value, num_rows 2 FROM user_tab_partitions 3 ORDER BY table_name, partition_name; TABLE_NAME PARTITION_NAME -------------------- -------------------HIGH_VALUE NUM_ROWS ---------------------------------------- ---------INTERVAL_TAB PART_01 TO_DATE(' 2007-11-01 00:00:00', 'SYYYY-M 2 M-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA INTERVAL_TAB SYS_P21 TO_DATE(' 2007-12-01 00:00:00', 'SYYYY-M M-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA INTERVAL_TAB SYS_P22 2

TABLE_NAME PARTITION_NAME -------------------- -------------------HIGH_VALUE NUM_ROWS ---------------------------------------- ---------TO_DATE(' 2008-02-01 00:00:00', 'SYYYY-M 2 M-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA INTERVAL_TAB SYS_P23 TO_DATE(' 2008-01-01 00:00:00', 'SYYYY-M M-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 2

The following restrictions apply to interval partitioned tables: Interval partitioning is restricted to a single partition key that must be a num erical or date range. At least one partition must be defined when the table is created. Interval partitioning is not supported for index-organized tables. You cannot create a domain index on an interval partitioned table. Interval partitioning can be used as the primary partitioning mechanism in compo site partitioning, but it can't be used at the subpartition level. A MAXVALUE partition cannot be defined for an interval partitioned table. NULL values are not allowed in the partition column. Global Index : SQL> CREATE INDEX PARENT_LOCAL_IDX ON PARENT_TAB(CREATED_D) GLOBAL PARTITION BY RANGE (CREATED_D) ( PARTITION LOCAL_1 VALUES LESS THAN (TO_DATE('01-AUG-2011','DD-MON-YYYY')) TABLESP ACE USERS,

PARTITION LOCAL_2 VALUES LESS THAN (MAXVALUE) TABLESPACE USERS); Index created. Local Index : SQL> CREATE INDEX PARENT_LOCAL_IDX ON PARENT_TAB(CREATED_D) LOCAL ( PARTITION LOCAL_1 TABLESPACE USERS, PARTITION LOCAL_2 TABLESPACE USERS); Index created. Reference Partitioning Reference partitioning allows tables related by foreign keys to be logically equ i-partitioned. The child table is partitioned using the same partitioning key as the parent table without having to duplicate the key columns. Partition mainten ance operations performed on the parent table are reflected on the child table, but no partition maintenance operations are allowed on the child table. The following code contains a partitioned parent table and a dependent reference partitioned child table. CREATE TABLE PARENT_TAB ( ID NUMBER NOT NULL, CODE VARCHAR2(20) NOT NULL, DESCP VARCHAR2(50), CREATED_D DATE, CONSTRAINT PARENT_TAB_PK PRIMARY KEY (ID) ) PARTITION BY RANGE (CREATED_D) ( PARTITION PART_2011 VALUES LESS THAN (TO_DATE('01-AUG-2011','DD-MON-YYYY')), PARTITION PART_2012 VALUES LESS THAN (TO_DATE('01-AUG-2012','DD-MON-YYYY')) ); Table created. CREATE TABLE CHILD_TAB ( ID NUMBER NOT NULL, PARENT_TAB_ID NUMBER NOT NULL, CODE VARCHAR2(20) NOT NULL, DESCP VARCHAR2(50), CREATED_D DATE, CONSTRAINT CHILD_TAB_PK PRIMARY KEY (ID), CONSTRAINT CHILD_PARENT_TAB_FK FOREIGN KEY (PARENT_TAB_ID) REFERENCES PARENT_TAB (ID) ) PARTITION BY REFERENCE (CHILD_PARENT_TAB_FK); Table created. Child records that foreign key to rows in the first partition of the parent tabl e should be placed in the first partition of the child table. So we insert two r ows into the first partition and one row into the second of the parent table.

We then insert three rows into the child table, with one foreign keyed to a row in the first partition and two foreign keyed to a row in the second partition of the master table. SQL> INSERT INTO parent_tab VALUES (1, 'ONE', '1 ONE', SYSDATE); 1 row created. SQL> INSERT INTO parent_tab VALUES (2, 'TWO', '2 TWO', SYSDATE); 1 row created. SQL> INSERT INTO parent_tab VALUES (3, 'THREE', '3 THREE', ADD_MONTHS(SYSDATE,12 )); 1 row created. SQL> INSERT INTO child_tab VALUES (1, 1, 'ONE', '1 1 ONE', SYSDATE); 1 row created. SQL> INSERT INTO child_tab VALUES (2, 3, 'TWO', '2 3 TWO', SYSDATE); 1 row created. SQL> INSERT INTO child_tab VALUES (3, 3, 'THREE', '3 3 THREE', SYSDATE); 1 row created. SQL> COMMIT; Commit complete. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'PARENT_TAB'); PL/SQL procedure successfully completed. SQL> EXEC DBMS_STATS.gather_table_stats(USER, 'CHILD_TAB'); PL/SQL procedure successfully completed. We now expect the parent table to have 2 records in the 2011 partition and 1 in the 2012 partition, while the child table should have 1 row in the 2011 partitio n and 2 rows in the 2012 partition. The following query confirms out expectation . SQL> SQL> SQL> 2 3 4 COLUMN table_name FORMAT A25 COLUMN partition_name FORMAT A20 SELECT table_name, partition_name, num_rows FROM user_tab_partitions WHERE TABLE_NAME IN ('PARENT_TAB','CHILD_TAB') ORDER BY table_name, partition_name; PARTITION_NAME NUM_ROWS -------------------- ---------PART_2011 PART_2012 PART_2011 PART_2012

TABLE_NAME ------------------------CHILD_TAB CHILD_TAB PARENT_TAB PARENT_TAB

1 2 2 1

The following conditions and restrictions apply to reference partitioning: The child table must specify a referential integrity constraint defined on the t able being created. This constraint must be in ENABLE VALIDATE NOT DEFERRABLE st ate (the default) and refer to a primary or unique key on the parent table. The foreign key columns referenced in constraint must be NOT NULL. The constraint cannot use the ON DELETE SET NULL clause. The parent table referenced must be an existing partitioned table. All partition

ing methods except interval partitioning are supported. The foreign key cannot contain any virtual columns. The referenced primary key or unique constraint on the parent table cannot conta in any virtual columns. Reference partitioning cannot be used for index-organized tables, external table s, or domain index storage tables. A chain of reference partitioned tables can be created, but constraint used can' t be self-referencing. The ROW MOVEMENT setting for both tables must match. Reference partitioning cannot be specified in a CREATE TABLE ... AS SELECT state ment. Transport Tablespace Using Cross Platform Transportable Tableaspace Linuxdb : Linux Opearating System tengr2 : Windows 2000 Opearting System ============================================================ LINUXDB>select a.platform_id,a.platform_name,endian_format from v$transportable_platform a, V$database b where a.platform_id=b.platform_id; PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT ====================================================== 10 Linux IA (32-bit) Little LINUXDB>exec dbms_tts.transport_set_check ('USERS',TRUE); LINUXDB>alter tablespace users read only; LINUXDB>create or replace directory dumplocation as '/oracle/product/102/db_1/li nuxdb/oradata'; LINUXDB>grant read,write on directory dumplocation to scott; LINUXDB>grant read,write on directory dumplocation to system; LINUXDB>host expdp system/manager dumpfile=users.dmp logfile=users.log directory =dumplocation transport_full_check=y transport_tablespaces=users SQL> select a.platform_id,a.platform_name,endian_format 2 from v$transportable_platform a, V$database b 3 where a.platform_id=b.platform_id; PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT ========================================================== 7 Microsoft Windows IA (32-bit) Little SQL> SQL> SQL> SQL> conn sys/systengr2 as sysdba create or replace directory data_dump_dir as 'D:\oradata\tengr2'; grant read,write on directory data_dump_dir to scott; grant read,write on directory data_dump_dir to system;

Note : Copy the dumpfile (users.dmp) & datafile (users01.dbf) Connected to 192.168.1.4. 220 linuxdb FTP server (Version 5.60) ready. User (192.168.1.4:(none)): oracle 331 Password required for oracle. Password: 230 User oracle logged in. ftp> bin 200 Type set to I. ftp> lcd d:\oradata\tengr2

Local directory now D:\oradata\tengr2. ftp> cd /oracle/product/102/db_1/linuxdb/oradata 250 CWD command successful. ftp> mget users.dmp 200 Type set to I. mget users.dmp? y 200 PORT command successful. 150 Opening BINARY mode data connection for users.dmp (126976 bytes). 226 Transfer complete. ftp: 126976 bytes received in 0.02Seconds 7936.00Kbytes/sec. ftp> mget users01.dbf 200 Type set to I. mget users01.dbf? y 200 PORT command successful. 150 Opening BINARY mode data connection for users01.dbf (134225920 bytes). 226 Transfer complete. ftp: 134225920 bytes received in 11.67Seconds 11499.82Kbytes/sec. ftp> SQL> host impdp system/manager dumpfile=users.dmp logfile=users1.log directory=data_dump_dir transport_datafiles='D:\oradata\tengr2\users01.dbf' SQL> connect scott/tiger SQL> select table_name from user_tables; SQL> select * from org; LINUXDB>alter tablespace users read write; Multi-Column Statistics Individual column statistics are fine for working out the selectivity of a speci fic column in a where clause, but when the where clause includes multiple column s from the same table, the individual column statistics provide no indication of the relationship between the columns. This makes working out the selectivity of the column group very difficult. Oracle uses workload analysis to generate column groups, but they can also be ma nipulated manually using the DBMS_STATS package. The CREATE_EXTENDED_STATS proce dure is used to explicitly create multi-column statistics. -- Create a columnn group based on EMP(JOB,DEPTNO). DECLARE l_cg_name VARCHAR2(30); BEGIN l_cg_name := DBMS_STATS.create_extended_stats(ownname => 'SCOTT', tabname => 'EMP', extension => '(JOB,DEPTNO)'); END; / PL/SQL procedure successfully completed. The column group name is returned using the SHOW_EXTENDED_STATS_NAME function. -- Display the name of the columnn group. SELECT DBMS_STATS.show_extended_stats_name(ownname => 'SCOTT', tabname => 'EMP', extension => '(JOB,DEPTNO)') AS cg_na me FROM dual;

CG_NAME -----------------------------SYS_STU3VG629OEYG6FN0EKTGV_HQ6 1 row selected. SQL> Manually created column groups can be deleted edure. -- Drop the columnn group. BEGIN dbms_stats.drop_extended_stats(ownname => tabname => extension => END; / PL/SQL procedure successfully completed. SQL> Setting the METHOD_OPT parameter to "FOR ALL COLUMNS SIZE AUTO" allows the GATHE R_% procedures to gather statistics on all existing column groups for the specif ied object. BEGIN DBMS_STATS.gather_table_stats( 'SCOTT', 'EMP', method_opt => 'for all columns size auto'); END; / Alternatively, set the METHOD_OPT parameter to "FOR COLUMNS (column-list)" and t he group will automatically be created during the statistics gathering. BEGIN DBMS_STATS.gather_table_stats( 'SCOTT', 'EMP', method_opt => 'for columns (job,mgr)'); END; / The [DBA ALL USER]_STAT_EXTENSIONS views display information about the multi-col umn statistics. COLUMN extension FORMAT A30 SELECT extension_name, extension FROM dba_stat_extensions WHERE table_name = 'EMP'; EXTENSION_NAME -----------------------------SYS_STU3VG629OEYG6FN0EKTGV_HQ6 SYS_STULPA1A#B6YL4KQ59DQO3OADQ EXTENSION -----------------------------("JOB","DEPTNO") ("JOB","MGR") using the DROP_EXTENDED_STATS proc

'SCOTT', 'EMP', '(JOB,DEPTNO)');

COLUMN col_group FORMAT A30 SELECT e.extension col_group, t.num_distinct, t.histogram FROM dba_stat_extensions e JOIN dba_tab_col_statistics t ON e.extension_name= t.column_name AND t.table_name = 'EMP'; COL_GROUP NUM_DISTINCT HISTOGRAM ------------------------------ ------------ --------------("JOB","DEPTNO") 9 FREQUENCY

("JOB","MGR") 2 rows selected. Streams :

8 FREQUENCY

6(i).Grant privilege to strmadmin in DB3 database: SQL> conn sys/sysdb3@db3 as sysdba SQL> grant connect,resource,dba to strmadmin; SQL> grant execute on dbms_file_transfer to strmadmin; SQL>begin dbms_streams_auth.grant_admin_privilege( grantee =>'strmadmin', grant_privileges=>true); end; 7(i). Create database link to strmadmin in DB3 database: SQL> conn strmadmin/strmadmin@db3 SQL>create database link db4 connect to strmadmin identified by strmadmin using 'db4'; 8(i). Creating Procedure for STRMADMIN schema in DB3 database: SQL> conn strmadmin/strmadmin@db3 SQL>declare cscn NUMBER; BEGIN DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_name=>'capture_queue', queue_user=>'STRMADMIN'); DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_name=>'apply_queue', queue_user=>'STRMADMIN'); DBMS_APPLY_ADM.CREATE_APPLY( queue_name => 'strmadmin.apply_queue', apply_name => 'apply_scott_emp', apply_captured => FALSE); DBMS_STREAMS_ADM.ADD_TABLE_RULES( table_name => 'scott.emp', streams_type => 'apply', streams_name => 'apply_scott_emp', queue_name => 'strmadmin.apply_queue', source_database => 'db4'); DBMS_STREAMS_ADM.ADD_TABLE_PROPAGATION_RULES( table_name => 'scott.emp', streams_name => 'send_scott_emp', source_queue_name => 'strmadmin.capture_queue', destination_queue_name => 'strmadmin.apply_queue@db4', source_database => 'db3', queue_to_queue => TRUE); DBMS_STREAMS_ADM.ADD_TABLE_RULES(

table_name => 'scott.emp', streams_type => 'sync_capture', streams_name => 'sync_capture', queue_name => 'strmadmin.capture_queue'); cscn :=DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER(); DBMS_APPLY_ADM.SET_TABLE_INSTANTIATION_SCN@db4( source_object_name =>'scott.emp', source_database_name => 'db3', instantiation_scn => cscn); DBMS_APPLY_ADM.START_APPLY( apply_name => 'apply_scott_emp'); END; / PL/SQL procedure successfully completed. 8(ii). Creating Procedure for STRMADMIN schema in DB4 database: SQL> conn strmadmin/strmadmin@db4 SQL>declare cscn NUMBER; BEGIN DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_name=>'capture_queue', queue_user=>'STRMADMIN'); DBMS_STREAMS_ADM.SET_UP_QUEUE( queue_name=>'apply_queue', queue_user=>'STRMADMIN'); DBMS_APPLY_ADM.CREATE_APPLY( queue_name => 'strmadmin.apply_queue', apply_name => 'apply_scott_emp', apply_captured => FALSE); DBMS_STREAMS_ADM.ADD_TABLE_RULES( table_name => 'scott.emp', streams_type => 'apply', streams_name => 'apply_scott_emp', queue_name => 'strmadmin.apply_queue', source_database => 'db3'); DBMS_STREAMS_ADM.ADD_TABLE_PROPAGATION_RULES( table_name => 'scott.emp', streams_name => 'send_scott_emp', source_queue_name => 'strmadmin.capture_queue', destination_queue_name => 'strmadmin.apply_queue@db3', source_database => 'db4', queue_to_queue => TRUE); DBMS_STREAMS_ADM.ADD_TABLE_RULES( table_name => 'scott.emp', streams_type => 'sync_capture', streams_name => 'sync_capture', queue_name => 'strmadmin.capture_queue'); cscn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER(); DBMS_APPLY_ADM.SET_TABLE_INSTANTIATION_SCN@db3( source_object_name =>'scott.emp', source_database_name => 'db4',

instantiation_scn => cscn); DBMS_APPLY_ADM.START_APPLY( apply_name => 'apply_scott_emp'); END; / PL/SQL procedure successfully completed.

Potrebbero piacerti anche