Thinking Out Loud

January 21, 2012

My Bi-directional Replication Using GoldenGate Adventure, Ep1

Filed under: 11g,GoldenGate — mdinh @ 4:14 pm

I want to share my beginning adventure for configuring bi-directional replication using GoldenGate.

GoldenGate installation will not be covered since it is well documented and blogged about in many sites.

Note: When you see GGSCI>, this means the command was executed in GG Command Interpreter and not OS shell (>).

Prerequisite:

Database in Archive Mode,  alter database add supplemental log data, GoldenGate installed at source and target.

Parameter file:

Changes made based on GG documentation

undo_retention=86400
recyclebin=off

Environment:

Using an OBEY script with ENCRYPTED password to determine environment. More on this later.

> cd /u01/app/ggs/
> ggsci
Oracle GoldenGate Command Interpreter for Oracle
Version 11.1.1.1.2 OGGCORE_11.1.1.1.2_PLATFORMS_111004.2100
Solaris, x64, 64bit (optimized), Oracle 11g on Oct 4 2011 23:54:06
Copyright (C) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
GGSCI 1> obey chk_version.obey
GGSCI 2> dblogin userid gguser, password AACAAAAAAAAAAAJAXHHGIEDCVGTJXDDEPHZEFEMDPEEGEJMH, encryptkey key1
Successfully logged into database.
GGSCI 3> versions
Operating System:
SunOS
Version Generic_141445-09, Release 5.10
Node: <hostname>
Machine: i86pc
Database:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Solaris: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
GGSCI 4> exit

SYSDBA Privilege:

A SQL script was failing because there was no SYSDBA privilege and I was connected as “/ as sysdba”. It turns out that SYS was not in v$pwfile_users.

Most of the SQL used sys_context(‘userenv’,'ISDBA’), but one was using v$pwfile_users.

> grep -i PWFILE_USERS *.sql
marker_remove.sql: FROM v$pwfile_users
> grep ISDBA *.sql
ddl_remove.sql: SELECT sys_context('userenv','ISDBA') INTO :isdba FROM DUAL; -- use network method for isdba determination
ddl_setup.sql:-- FP 17971: use ISDBA as well to determine dba privs
ddl_setup.sql: SELECT sys_context('userenv','ISDBA') INTO :isdba FROM DUAL; -- use network method for isdba determination
remove_seq.sql: SELECT sys_context('userenv','ISDBA') INTO :isdba FROM DUAL; -- use network
sequence.sql: SELECT sys_context('userenv','ISDBA') INTO :isdba FROM DUAL; -- use network method for isdba determination

CREATE USER (gguser) with DDL Replication Configuration:

GRANT CREATE SESSION,ALTER SESSION to gguser identified by oracle_4u;
GRANT CONNECT,SELECT ANY DICTIONARY,FLASHBACK ANY TABLE,SELECT ANY TABLE to gguser;
GRANT SELECT on dba_clusters to gguser;
GRANT EXECUTE on DBMS_FLASHBACK to gguser;
GRANT SELECT ANY TRANSACTION to gguser;
GRANT EXECUTE on utl_file TO gguser;
EXEC dbms_goldengate_auth.grant_admin_privilege('gguser');
@@sequence
@@marker_setup.sql
@@ddl_setup.sql
@@role_setup.sql
@@ddl_enable.sql
@@ddl_pin gguser
alter user gguser default tablespace ggs_data;
revoke unlimited tablespace from gguser;
alter user gguser quota unlimited on ggs_data;

No DBA role was granted to GGUSER and it turns out that GGUSER had DBA role from marker_setup.sql: GRANT CONNECT, RESOURCE, DBA TO &gg_user;

Create ENCKEYS file in GG_HOME:

ENCKEYS is a file containing key values used to encrypt password. In the example: keygen is used to create 2 keys having 128 bit.

keygen 128 2 > ENCKEYS

Add KeyName to ENCKEYS  file:

Open ENCKEYS to add KeyName. You can provide any KeyName for the KeyValue. In the example, the KeyValue were named key1 and key2.

## KeyName KeyValue
key1 0x59038C335C69746FE0CA751368AB294E
key2 0x38374124C2D3AD74DFB443065D08160F

Generate Encrypted Password:

GGSCI> encrypt password oracle_4u, encryptkey key1
AACAAAAAAAAAAAJAXHHGIEDCVGTJXDDEPHZEFEMDPEEGEJMH

Test Encrypted Password:

It’s now possible to use encrypted versus plain text password.

GGSCI 1> dblogin userid gguser, password oracle_4u
Successfully logged into database.
GGSCI 2> dblogin userid gguser, password AACAAAAAAAAAAAJAXHHGIEDCVGTJXDDEPHZEFEMDPEEGEJMH,encryptkey key1
Successfully logged into database.

OBEY script:

In GoldenGate, an obey script is equivalent to a SQL script. One caveat is when an obey script calls another obey script, allownested  must be used.

Here is an example of a nested obey script.

> cat add_config_ggs01.obey
dblogin userid gguser, password AACAAAAAAAAAAAJAXHHGIEDCVGTJXDDEPHZEFEMDPEEGEJMH, encryptkey key1
allownested
versions
obey add_eggs01.obey
obey add_rggs02.obey
exit

January 19, 2012

Rotate Alert Log 11g

Filed under: 11g,oracle — mdinh @ 5:14 am

Tested on Solaris 10

> cat rotate_alert.sh
#!/bin/sh

DN=`dirname $0`
BN=`basename $0`

. /home/oracle/.common.conf > /dev/null
month=`date “+%m”`
for sid in `ps -eo args|grep ora_smon|grep -v grep|awk -F_ ‘{print $3}’`
do
ORACLE_SID=$sid
. oraenv
diag_trace=`$ORACLE_HOME/bin/sqlplus -SL / <<EOF
set echo off ver off feedb off head off pages 0
select value from v\\$diag_info where name=’Diag Trace’;
exit;
EOF
`
alert_log=$diag_trace/alert_$sid.log
mv $alert_log $alert_log.$month
gzip -f $alert_log.$month
touch ${alert_log}
done
exit

NOTE: there is a back-tick (`) in the line after EOF

December 31, 2011

Happy New Year

Filed under: Uncategorized — mdinh @ 6:07 pm

An amazing photo at 500px: http://500px.com/photo/4039804

December 14, 2011

datapump transform

Filed under: 11g,oracle — mdinh @ 3:36 am

I know there are many blogs out there on datapump; however, I wanted to just to create a quick post on parallel datapump and transform.

The requirement is to parallel export and import and to migrate indexes to a new tablespace as part of a DW migration.

Export parameter:

DIRECTORY=data_pump_local
DUMPFILE=mdinh%U.dmp
SCHEMAS=mdinh
PARALLEL=12
METRICS=y
LOGFILE=expdp_mdinh.log
EXCLUDE=grant,statistics
REUSE_DUMPFILES=Y
FLASHBACK_SCN=10535801779818

Import parameter (NO TRANSFORM):

DIRECTORY=data_pump_local
DUMPFILE=mdinh%U.dmp
SCHEMAS=mdinh
PARALLEL=12
METRICS=y
LOGFILE=impdp_mdinh.log
INCLUDE=constraint,index
SQLFILE=mdinh_notransform.sql

> cat mdinh_notransform.sql

-- CONNECT OPS$ORACLE
ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
-- new object type path: SCHEMA_EXPORT/TABLE/INDEX/INDEX
-- CONNECT MDINH
CREATE UNIQUE INDEX "MDINH"."PKP" ON "MDINH"."P" ("ID")
 PCTFREE 10 INITRANS 2 MAXTRANS 255
 TABLESPACE "USER_DATA" PARALLEL 1 ;
ALTER INDEX "MDINH"."PKP" NOPARALLEL;
CREATE INDEX "MDINH"."X" ON "MDINH"."F" ("ID")
 PCTFREE 10 INITRANS 2 MAXTRANS 255
 STORAGE( INITIAL 1048576)
 TABLESPACE "USER_DATA" PARALLEL 1 ;
ALTER INDEX "MDINH"."X" NOPARALLEL;
-- new object type path: SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
-- CONNECT OPS$ORACLE
ALTER TABLE "MDINH"."P" ADD CONSTRAINT "PKP" PRIMARY KEY ("ID") RELY USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255  TABLESPACE "USER_DATA" ENABLE;
-- new object type path: SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
ALTER TABLE "MDINH"."F" ADD CONSTRAINT "F1" FOREIGN KEY ("ID")
 REFERENCES "MDINH"."P" ("ID") RELY DISABLE;

Import parameter (TRANSFORM):

DIRECTORY=data_pump_local
DUMPFILE=mdinh%U.dmp
SCHEMAS=mdinh
PARALLEL=12
METRICS=y
LOGFILE=impdp_mdinh.log
INCLUDE=constraint,index
SQLFILE=mdinh_transform.sql
TRANSFORM=STORAGE:n:index
TRANSFORM=STORAGE:n:constraint
REMAP_TABLESPACE=user_data:user_index

> cat mdinh_transform.sql

-- CONNECT OPS$ORACLE
ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
-- new object type path: SCHEMA_EXPORT/TABLE/INDEX/INDEX
-- CONNECT MDINH
CREATE UNIQUE INDEX "MDINH"."PKP" ON "MDINH"."P" ("ID")
 PCTFREE 10 INITRANS 2 MAXTRANS 255
 TABLESPACE "USER_INDEX" PARALLEL 1 ;
ALTER INDEX "MDINH"."PKP" NOPARALLEL;
CREATE INDEX "MDINH"."X" ON "MDINH"."F" ("ID")
 PCTFREE 10 INITRANS 2 MAXTRANS 255
 TABLESPACE "USER_INDEX" PARALLEL 1 ;
ALTER INDEX "MDINH"."X" NOPARALLEL;
-- new object type path: SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
-- CONNECT OPS$ORACLE
ALTER TABLE "MDINH"."P" ADD CONSTRAINT "PKP" PRIMARY KEY ("ID") RELY USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255  TABLESPACE "USER_INDEX" ENABLE;
-- new object type path: SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
ALTER TABLE "MDINH"."F" ADD CONSTRAINT "F1" FOREIGN KEY ("ID")
 REFERENCES "MDINH"."P" ("ID") RELY DISABLE;

Did you notice the storage clause in the mdinh_notransform.sql?


REFERENCE: Data Pump Import: TRANSFORM

October 28, 2011

11.2.0.3 Silent Install and Database Creation using OMF

Filed under: 11g,oracle — mdinh @ 2:06 am

Performing Silent Install

Operating System:

> uname -an
SunOS <hostname> 5.10 Generic_142909-17 sun4u sparc SUNW,Sun-Fire-880

oraInst.loc:

> cat /var/opt/oracle/oraInst.loc
inventory_loc=/u01/app/11.2.0.3/oraInventory
inst_group=dba

Response File:

> cat /home/mdinh/ora_stage/11.2.0.3/patchset/database/response/swonly.rsp
#------------------------------------------------------------------------------
# Do not change the following system generated value.
#------------------------------------------------------------------------------
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=dba
INVENTORY_LOCATION=/u01/app/11.2.0.3/oraInventory
SELECTED_LANGUAGES=en
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/dbhome_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=true
# oracle.rdbms.partitioning:11.2.0.3.0 - Oracle Partitioning
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.3.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
oracle.installer.autoupdates.option=SKIP_UPDATES

Shell Script:

> cat swonly.sh
#!/bin/sh -x
/home/mdinh/ora_stage/11.2.0.3/patchset/database/runInstaller -debug -silent -force -responseFile /home/mdinh/ora_stage/11.2.0.3/patchset/database/response/swonly.rsp
exit

Execute as Root:

/u01/app/oracle/product/11.2.0.3/dbhome_1/root.sh -bindir /opt/oracle/bin
Check /u01/app/oracle/product/11.2.0.3/dbhome_1/install/root_<hostname>_2011-10-26_11-33-40.log

Creating database using Oracle Managed Files (OMF)

I have not been able to figure out why the directory for the database files  is created in UPPERCASE.

Hence, the pre-created directory will need to be in UPPERCASE as well.

Create directories:

mkdir -p /u01/app/oracle/admin/DEVDB01/adump
mkdir -p /oracle/oradata/DEVDB01/arch/

Create init.ora:

> cat initdevdb01.ora
audit_file_dest='/u01/app/oracle/admin/DEVDB01/adump'
audit_sys_operations=FALSE
audit_trail=NONE
compatible=11.2.0.3
control_files='/oracle/oradata/DEVDB01/control01.dbf','/oracle/oradata/DEVDB01/control02.dbf'
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_name=devdb01
diagnostic_dest='/u01/app/oracle'
fast_start_mttr_target=300
job_queue_processes=20
log_archive_dest_1='LOCATION=/oracle/oradata/DEVDB01/arch'
log_archive_format='arc_%d_%t_%r_%s.dbf'
open_cursors=1000
pga_aggregate_target=1G
processes=200
remote_login_passwordfile=EXCLUSIVE
sec_case_sensitive_logon=FALSE
session_cached_cursors=500
sga_max_size=2G
sga_target=2G
timed_statistics=TRUE
undo_management=AUTO
undo_retention=60000
undo_tablespace=undotbs1
workarea_size_policy=AUTO

Create database:

startup nomount;
create database
maxlogfiles 8
maxlogmembers 4
maxdatafiles 1024
character set AL32UTF8
national character set AL16UTF16
logfile group 1 size 256M,group 2 size 256M,group 3 size 256M,group 4 size 256M
default temporary tablespace temp tempfile size 1024M
undo tablespace undotbs1 datafile size 1024M;

@?/rdbms/admin/catalog.sql;
@?/rdbms/admin/catproc.sql;
@?/rdbms/admin/catblock.sql;
@?/rdbms/admin/catoctk.sql;
@?/rdbms/admin/catio.sql
@?/rdbms/admin/dbmsiotc.sql
@?/rdbms/admin/dbmsotrc.sql
@?/rdbms/admin/dbmspool.sql
@?/rdbms/admin/userlock.sql

shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
conn system
@?/sqlplus/admin/pupbld.sql

Create and Set DEFAULT tablespace:

CREATE TABLESPACE user_data DATAFILE SIZE 256M AUTOEXTEND ON NEXT 256M MAXSIZE 8G;
ALTER DATABASE DEFAULT TABLESPACE user_data;

COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A30
COLUMN description FORMAT A50
SET LINESIZE 200
SELECT * FROM database_properties WHERE property_name like '%TABLESPACE';

SQL> SELECT * FROM database_properties WHERE property_name like '%TABLESPACE';

PROPERTY_NAME                  PROPERTY_VALUE                 DESCRIPTION
------------------------------ ------------------------------ --------------------------------------------------
DEFAULT_TEMP_TABLESPACE        TEMP                           Name of default temporary tablespace
DEFAULT_PERMANENT_TABLESPACE   USER_DATA                      Name of default permanent tablespace

Directory Structures:

> ls -l /oracle/oradata/DEVDB01/
total 68432
drwxr-xr-x   2 oracle   dba         1024 Oct 27 09:03 arch
-rw-r-----   1 oracle   dba      17481728 Oct 27 18:57 control01.dbf
-rw-r-----   1 oracle   dba      17481728 Oct 27 18:57 control02.dbf
drwxr-x---   2 oracle   dba         1024 Oct 27 09:42 datafile
drwxr-x---   2 oracle   dba         1024 Oct 26 13:41 onlinelog

October 16, 2011

Shell and SQL Script

Filed under: oracle — mdinh @ 10:36 pm

A quick note on separating SQL from shell script.

If I have a shell script name longops.sh, then it will call longops.sql.

Don’t embed SQL in shell script so that SQL script can be executed independently.

> cat longops.sh
#!/bin/sh
. /home/oracle/.common.conf > /dev/null
DN=`dirname $0`
BN=`basename $0`

sql=`echo $BN|cut -d'.' -f1`.sql
for sid in `ps -eo args|grep ora_smon|grep -v grep|awk -F_ '{print $3}'`
do
  OUTF=/tmp/longops.${sid}.html
  rm -f $OUTF
  ORACLE_SID=$sid
  . oraenv
  $ORACLE_HOME/bin/sqlplus -SL > /dev/null / << END
    spool $OUTF
    prompt From: oracle@mail.com
    prompt To: dba@mail.com
    prompt Subject: WARNING ${BN}: $ORACLE_SID - SQL running over one hour
    prompt Content-type: text/html
    prompt MIME-Version: 1.0
    set markup html on entmap off table 'BORDER="2"'
    @${sql}
    spool off
    exit
END
  if [ "$?" -ne "0" ]; then
    mailx -s "FAILED: $BN $*" $EMAIL < /dev/null
  exit 1
  fi
  if [ `grep -ic MACHINE $OUTF` != 0 ]; then
    /usr/sbin/sendmail -t < $OUTF
  fi
done
exit

> cat longops.sql
ALTER SESSION SET NLS_DATE_FORMAT='Dy, DD-Mon-YYYY HH24:MI:SS';
SELECT s.sid, s.serial#,
       s.username,  s.osuser, s.machine, s.program,
       s.sql_id, s.sql_exec_start, s.logon_time,
       ROUND (s.last_call_et/3600,3) last_call_hr,
       ROUND ((SYSDATE-s.SQL_EXEC_START)*24,3) exec_start_hr,
       CASE WHEN s.state != 'WAITING' THEN 'WORKING' ELSE 'WAITING' END AS state,
       CASE WHEN s.state != 'WAITING' THEN 'On CPU / runqueue' ELSE event END AS sw_event
FROM   v$session s
WHERE  s.type = 'USER' AND s.status = 'ACTIVE' AND ROUND (s.last_call_et/3600)>1
ORDER BY s.last_call_et DESC;

October 8, 2011

Create Standby Database from Active Database

Filed under: 11g,oracle — mdinh @ 2:45 pm

This is just another post on how to create standby database from active database. By the way, I do love Oracle’s technology most of the time.

This option was primarily chosen because the database size was ~400GB and there is no storage available to create backup for standby database.

The process took almost 6 hours and was running while I was sleeping :)

Recovery Manager: Release 11.2.0.2.0 - Production on Fri Oct 7 21:49:57 2011
Finished Duplicate Db at 08-OCT-2011 03:31:22

Configuration:

PRIMARY pfile
> more initdb08.ora
ifile=/home/oracle/pfile/initprodoltp_common.ora
_log_deletion_policy=ALL
event="10298 trace name context forever, level 32"
*.audit_file_dest="/u01/app/oracle/admin/db08/adump"
*.control_files=/oracle/oradata/db08/control01.ctl,/oracle/oradata/db08/control02.ctl
*.db_16k_cache_size=2G
*.db_32k_cache_size=2G
*.db_cache_size=2G
*.db_name="db08"
*.db_unique_name="lax_db08"
*.fal_client=lax_db08
*.fal_server=phx_db08
*.log_archive_config="DG_CONFIG=(lax_db08,phx_db08)"
*.log_archive_dest_1="LOCATION=/oracle/oradata/db08/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=lax_db08"
*.log_archive_dest_2='SERVICE=phx_db08 LGWR ASYNC COMPRESSION=ENABLE REOPEN=15 NET_TIMEOUT=30 MAX_FAILURE=10 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=phx_db08'
*.shared_pool_reserved_size=512M
*.shared_pool_size=3G

STANDBY pfile
> more initdb08.ora
ifile=/home/oracle/pfile/initdr_common.ora
_log_deletion_policy=ALL
event="10298 trace name context forever, level 32"
*.audit_file_dest='/u01/app/oracle/admin/db08/adump'
*.control_files='/oracle/oradata/db08/control01.ctl','/oracle/oradata/db08/control02.ctl'#Restore Controlfile
*.db_16k_cache_size=512M
*.db_32k_cache_size=512M
*.db_cache_size=512M
*.db_name='db08'
*.db_unique_name='phx_db08'
*.fal_client='phx_db08'
*.fal_server='lax_db08'
*.log_archive_config='DG_CONFIG=(lax_db08,phx_db08)'
*.log_archive_dest_1='LOCATION=/oracle/oradata/db08/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=phx_db08'
*.log_archive_dest_2='SERVICE=lax_db08 LGWR ASYNC REOPEN=15 NET_TIMEOUT=30 MAX_FAILURE=10 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=lax_db08'
*.shared_pool_size=256M

RMAN rcv
> cat db08.crstby.rcv
connect target;
connect auxiliary sys/password@phx_db08;
run {
DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;}
exit

I manually created the parameter and password file at the STANDBY, opted not to use spfile.

From STANDBY, start listener and database (nomount)

From PRIMARY, execute RMAN using RCV

> rman log=’db08.crstby.log’ cmdfile=’db08.crstby.rcv’

Snippets from the log file:

RMAN> connect target;
2> connect auxiliary *
3> run {
4> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;}
5> exit
connected to target database: DB08 (DBID=1578229963)
connected to auxiliary database: DB08 (not mounted)

Starting Duplicate Db at 07-OCT-2011 21:50:02
using target database control file instead of recovery catalog
contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/u01/app/oracle/product/11.2.0.2/dbhome_1/dbs/orapwdb08' auxiliary format
 '/u01/app/oracle/product/11.2.0.2/dbhome_1/dbs/orapwdb08'   ;
}
executing Memory Script
contents of Memory Script:
{
   backup as copy current controlfile for standby auxiliary format  '/oracle/oradata/db08/control01.ctl';
   restore clone controlfile to  '/oracle/oradata/db08/control02.ctl' from
 '/oracle/oradata/db08/control01.ctl';
}
executing Memory Script
contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script
contents of Memory Script:
{
   set newname for tempfile  1 to
 "/oracle/oradata/db08/temp01.dbf";
   set newname for tempfile  2 to
 "/oracle/oradata/db08/temp02.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/oracle/oradata/db08/system01.dbf";
   set newname for datafile  2 to
 "/oracle/oradata/db08/undotbs01.dbf";
   set newname for datafile  3 to
 "/oracle/oradata/db08/sysaux01.dbf";
   set newname for datafile  4 to
 "/oracle/oradata/db08/undotbs02.dbf";
   set newname for datafile  5 to
 "/oracle/oradata/db08/ctxsys01.dbf";
~~~~
   backup as copy reuse
   datafile  1 auxiliary format
 "/oracle/oradata/db08/system01.dbf"   datafile
 2 auxiliary format
 "/oracle/oradata/db08/undotbs01.dbf"   datafile
 3 auxiliary format
 "/oracle/oradata/db08/sysaux01.dbf"   datafile
 4 auxiliary format
 "/oracle/oradata/db08/undotbs02.dbf"   datafile
 5 auxiliary format
 "/oracle/oradata/db08/ctxsys01.dbf"   datafile
   sql 'alter system archive log current';
}
executing Memory Script
Starting backup at 07-OCT-2011 21:50:45
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
Finished backup at 08-OCT-2011 03:24:14

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75240.dbf" auxiliary format
 "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75240.dbf"   archivelog like
 "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75241.dbf" auxiliary format
 "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75241.dbf"   archivelog like
 "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75242.dbf" auxiliary format
~~~
   catalog clone archivelog  "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75240.dbf";
   catalog clone archivelog  "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75241.dbf";
   catalog clone archivelog  "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75242.dbf";
   catalog clone archivelog  "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75243.dbf";
   catalog clone archivelog  "/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75244.dbf";
   switch clone datafile all;
}
executing Memory Script
Starting backup at 08-OCT-2011 03:24:21
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=75240 RECID=135728 STAMP=763941140
channel ORA_DISK_2: starting archived log copy
input archived log thread=1 sequence=75241 RECID=135729 STAMP=763941998
channel ORA_DISK_3: starting archived log copy
input archived log thread=1 sequence=75242 RECID=135730 STAMP=763942998
channel ORA_DISK_4: starting archived log copy
input archived log thread=1 sequence=75243 RECID=135731 STAMP=763944071
Finished backup at 08-OCT-2011 03:26:56

cataloged archived log
archived log file name=/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75240.dbf RECID=1 STAMP=763961217

cataloged archived log
archived log file name=/oracle/oradata/db08/arch/arc_5e11e0cb_1_598985931_75241.dbf RECID=2 STAMP=763961218
contents of Memory Script:
{
   set until scn  10533738778008;
   recover
   standby
   clone database
    delete archivelog
   ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 08-OCT-2011 03:27:19
using channel ORA_AUX_DISK_1
using channel ORA_AUX_DISK_2
using channel ORA_AUX_DISK_3
using channel ORA_AUX_DISK_4

starting media recovery
media recovery complete, elapsed time: 00:03:08
Finished recover at 08-OCT-2011 03:30:49
Finished Duplicate Db at 08-OCT-2011 03:31:22

Recovery Manager complete.

July 6, 2011

Renaming Interval Partitions

Filed under: 11g,oracle — mdinh @ 3:56 am

I wrote a stored procedure to RENAME USER system generated name for interval partition tables and LOCAL indexes.

One pertinent information on >>Interval Partitioning

  • Can only partition on one key column and must be NUMBER or DATE type

>>NUMTOYMINTERVAL must resolve to the following values: ’YEAR’,'MONTH’
>>NUMTODSINTERVAL must resolve to the following values: ’DAY’,'HOUR’,'MINUTE’,'SECOND’

Download stored procedure and test case >>interval_part.sql

System generated partitions.

Renamed partitions.

UPDATED: Add parameter p_table to package.

Update ONE table: exec mdinh_pkg.ren_interval_part(‘day’);

Update ALL tables: exec mdinh_pkg.ren_interval_part;

June 25, 2011

fuser – identify users of files and devices

Filed under: solaris — mdinh @ 4:22 am

I learned about fuser when I had deleted 64GB file from /tmp but the space was never reclaimed.

This shows you alert log is being opened in another session using vi.

> ll
total 28992
drwxr-xr-x  25 root     root        8192 Oct 23  2010 ..
-rw-r--r--   1 root     sys           60 Oct 23  2010 csn.6249
-rw-r--r--   1 root     root          76 Oct 23  2010 iconf_entries.6185
drwxrwxrwt   2 root     root         117 Oct 29  2010 .oracle
drwxrwxrwt   4 root     sys          536 Jun 24 21:05 .
-rw-r-----   1 oracle   dba      14785325 Jun 24 21:05 alert_dbtest.log

> ps -afe|grep alert_dbtest.log
  oracle 11589 16520   0 21:05:58 pts/8       0:00 grep alert_dbtest.log
  oracle 10555 19200   0 21:05:47 pts/6       0:01 vi alert_dbtest.log

I am now going to delete alert log file.

> rm alert_dbtest.log

> ll
total 112
drwxr-xr-x  25 root     root        8192 Oct 23  2010 ..
-rw-r--r--   1 root     sys           60 Oct 23  2010 csn.6249
drwxrwxrwt   2 root     root         117 Oct 29  2010 .oracle
drwxr-xr-x   2 oracle   dba          117 Nov  1  2010 hsperfdata_oracle
drwxrwxrwt   4 root     sys          463 Jun 24 21:06 .

Who’s got the file opened?

> ps -o pid,args -p "$(fuser /tmp 2>/dev/null)"
  PID COMMAND
10555 vi alert_dbtest.log
16520 -bash
19200 -bash

> kill -9 10555

Note:  tested on Solaris 10

Great reference here as well Less known Solaris Features: fuser

June 15, 2011

Have you seen ? CONSTRAINT_TYPE ?

Filed under: 11g,oracle — mdinh @ 4:00 am

When I was testing DBMS_REDEFINITION to convert a non-partitioned table to a partitioned table, I came across constraint_type “?” from TOAD.

WTH! I have must have done something wrong.

It turns out that TOAD used the following SQL to determine constraint_type and does not label non-constraints:

SELECT CN.NAME constraint_name, c.type#, decode(c.type#, 1, 'Check', 2, 'Primary Key', 3, 'Unique Key',
       4, 'Referential Integrity', 5, 'Check Option on a View', 6, 'Read Only Option on a View', 7,'Check', '?') constraint_type
FROM   SYS.CDEF$ C, SYS.CON$ CN, SYS.OBJ$ O, SYS.USER$ U, SYS.CON$ RC, SYS.USER$ RU, SYS.OBJ$ RO
WHERE  C.CON# = CN.CON#
AND    C.OBJ# = O.OBJ#
AND    O.OWNER# = U.USER#
AND    C.RCON# = RC.CON#(+)
AND    RC.OWNER# = RU.USER#(+)
AND    C.ROBJ# = RO.OBJ#(+)
AND    U.NAME = 'SCOTT'
AND    O.NAME = 'SH'
AND    c.type# not in (8, 12)
order by 1;

Notice how TOAD purposely left out  cdef$.type# 8 & 12, but forgot about the others.

Querying dba_contraints shows different results:

SQL> select CONSTRAINT_NAME,CONSTRAINT_TYPE from dba_constraints where OWNER='SCOTT' and TABLE_NAME='SH';

no rows selected

SQL>

Here’s how I was able to find the definition for the various cdef$.type#

From ORCLE_HOME/rdbms/admin -

> grep 'cdef\$' *.sql
catmeta.sql:          oi.obj# = cdef$.enabled and
catmeta.sql:          bitand(cdef$.defer,8) = 8 and                  /* system generated */
catmeta.sql:          cdef$.type# = 3 and

This hinted me to look at catmeta.sql and found this

  type_num      number,                                  /* constraint type: */
                            /* 1 = table check, 2 = primary key, 3 = unique, */
                             /* 4 = referential, 5 = view with CHECK OPTION, */
                                                 /* 6 = view READ ONLY check */
               /* 7 - table check constraint associated with column NOT NULL */
                                   /* 8 - hash expressions for hash clusters */
                                         /* 9 - Scoped REF column constraint */
                                    /* 10 - REF column WITH ROWID constraint */
                                  /* 11 - REF/ADT column with NOT NULL const */
                                 /* 12 - Log Groups for supplemental logging */
                                    /* 14 - Primary key supplemental logging */
                                     /* 15 - Unique key supplemental logging */
                                    /* 16 - Foreign key supplemental logging */
                                     /* 17 - All column supplemental logging */

Here is a little testing I did to confirm  cdef$.type# = 17 (All column supplemental logging)

SQL> SELECT CN.NAME constraint_name, c.type#, decode(c.type#, 1, 'Check', 2, 'Primary Key', 3, 'Unique Key',
  2         4, 'Referential Integrity', 5, 'Check Option on a View', 6, 'Read Only Option on a View', 7,'Check', '?') constraint_type
  3  FROM   SYS.CDEF$ C, SYS.CON$ CN, SYS.OBJ$ O, SYS.USER$ U, SYS.CON$ RC, SYS.USER$ RU, SYS.OBJ$ RO
  4  WHERE  C.CON# = CN.CON#
  5  AND    C.OBJ# = O.OBJ#
  6  AND    O.OWNER# = U.USER#
  7  AND    C.RCON# = RC.CON#(+)
  8  AND    RC.OWNER# = RU.USER#(+)
  9  AND    C.ROBJ# = RO.OBJ#(+)
 10  AND    U.NAME = 'SCOTT'
 11  AND    O.NAME = 'SH'
 12  AND    c.type# not in (8, 12)
 13  order by 1;

no rows selected

SQL> alter table scott.sh add supplemental log data (all) columns;

Table altered.

SQL> SELECT CN.NAME constraint_name, c.type#, decode(c.type#, 1, 'Check', 2, 'Primary Key', 3, 'Unique Key',
  2         4, 'Referential Integrity', 5, 'Check Option on a View', 6, 'Read Only Option on a View', 7,'Check', '?') constraint_type
  3  FROM   SYS.CDEF$ C, SYS.CON$ CN, SYS.OBJ$ O, SYS.USER$ U, SYS.CON$ RC, SYS.USER$ RU, SYS.OBJ$ RO
  4  WHERE  C.CON# = CN.CON#
  5  AND    C.OBJ# = O.OBJ#
  6  AND    O.OWNER# = U.USER#
  7  AND    C.RCON# = RC.CON#(+)
  8  AND    RC.OWNER# = RU.USER#(+)
  9  AND    C.ROBJ# = RO.OBJ#(+)
 10  AND    U.NAME = 'SCOTT'
 11  AND    O.NAME = 'SH'
 12  AND    c.type# not in (8, 12)
 13  order by 1;

CONSTRAINT_NAME                     TYPE# CONSTRAINT_TYPE
------------------------------ ---------- --------------------------------
SYS_C0010094                           17 ?

SQL>

Guess I can close the SR now.

Next Page »

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.