Monday, December 29, 2014

Setup Streams Between Two Oracle Databases

The example in this article illustrates the replication of a source database ( DB10GSR1 ) to a destination database ( DB10GSR2 )

1.            Set up ARCHIVELOG mode.
2.            Set up the Streams administrator.
3.            Set initialization parameters.
4.            Create a database link.
5.            Set up source and destination queues.
6.            Set up supplemental logging at the source database.
7.            Configure the capture process at the source database.
8.            Configure the propagation process.
9.            Create the destination table.
10.          Grant object privileges.
11.          Set the instantiation system change number (SCN).
12.          Configure the apply process at the destination database.
13.          Start the capture and apply processes.


1.            Set up ARCHIVELOG mode. The Streams capture process reads information from the redo log files of the database.
2.            Set up the Streams administrator. Don't use this account for any other purpose, and don't use the SYS or the SYSTEM user as the Streams administrator.The Streams administrator creates some tables in its default tablespace.

CREATE TABLESPACE streams_tbs DATAFILE '/u01/app/oracle/product/10.1.0/db_1/oradata/db10gsr1/streams_tbs.dbf' SIZE 25M;

Now create the Streams administrator user in the database, as follows:
CREATE USER strmadmin
IDENTIFIED BY strmadmin
DEFAULT TABLESPACE streams_tbs
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON streams_tbs;

Now grant the CONNECT, RESOURCE , and DBA roles to the Streams administrator:
GRANT CONNECT, RESOURCE, DBA TO strmadmin;

Use the GRANT_ADMIN_PRIVILEGE procedure in the DBMS_STREAMS_AUTH package to grant the required privileges to the Streams administrator:
BEGIN
  DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
    grantee => 'strmadmin',   
    grant_privileges => true);
END;
/

Note that Streams does not require you to use the following roles, but granting these roles can assist with administration:
GRANT SELECT_CATALOG_ROLE TO strmadmin;
GRANT SELECT ANY DICTIONARY TO strmadmin;

Complete the preceding steps to set up a Streams administrator on each of the databases participating in the Streams data sharing environment. In this example, these steps need to be executed on both the DB10GSR1 and the DB10GSR2 databases.

3.            Set initialization parameters. Set specific initialization parameters at the databases participating in the Streams data sharing. Table 1 describes these initialization parameters and the values they must be set to.

PARAMETER                       SOURCE               DESTINATION
GLOBAL_NAMES              TRUE                     TRUE
COMPATIBLE                     10.1.0                    10.1.0
JOB_QUEUE_PROCESSES             2 (or above)       N/A
STREAMS_POOL_SIZE    200MB (Min)      200MB (Min)


4.            Create a database link. You need to create a database link from the source database to the destination database. In this example, you will create a database link from DB10GSR1 to DB10GSR2 .

                CONNECT strmadmin/strmadmin@DB10GSR1
                CREATE DATABASE LINK DB10GSR2
                  CONNECT TO strmadmin
                IDENTIFIED BY strmadmin
                USING 'DB10GSR2';

5.            Set up source and destination queues. The data moves from the source to the destination database through queues. Use the SET_UP_QUEUE procedure in the DBMS_STREAMS_ADM package to set up the queues. By default, this procedure creates a queue table named streams_queue_table and a queue named streams_queue . You can override these names by specifying the queue_table and queue_name parameters of the procedure SET_UP_QUEUE . The default names work well, unless you want to create multiple queues and multiple queue tables. For the purpose of the replication example in this article, you will accept the default names, by executing the procedure as follows:
               
                EXEC DBMS_STREAMS_ADM.SET_UP_QUEUE();

Execute this procedure on both the source and the destination databases. When you execute it on the source database ( DB10GSR1 ), it creates a source queue, and when you execute it on the destination database ( DB10GSR2 ), it creates a destination queue. Because you are choosing to accept the default queue name, the names of the source and destination queues will be the same. In a later step, you will associate these two queues with the propagation process.

6.            Set up supplemental logging at the source database on the tables being changed.

                ALTER TABLE emp
                ADD SUPPLEMENTAL LOG DATA
                  (PRIMARY KEY, UNIQUE) COLUMNS;

7.            Configure the capture process at the source database. The capture process initiates replication, by capturing the changes in the source database. It then formats each change into an LCR and enqueues the LCRs. Create a capture process to extract the changes from the redo logs. You can configure a capture process to run on the source database called a local capture or remotely on another database called a downstream capture. While creating a capture process, you add rules to specify which changes to capture and which ones to discard. The rules are combined into rule sets. The capture process can have a positive rule set and a negative rule set. For a replication capture process to work, you need to add a positive rule set that specifies that the data manipulation language (DML) changes as well as the data definition language (DDL) changes be captured. Do this by using the ADD_TABLE_RULES procedure of the DBMS_STREAMS_ADM package:

BEGIN
  DBMS_STREAMS_ADM.ADD_TABLE_RULES(
    table_name     => 'scott.emp',  
    streams_type   => 'capture',
    streams_name   => 'capture_stream',
    queue_name     =>
           'strmadmin.streams_queue',
    include_dml    => true,
    include_ddl    => true,
    inclusion_rule => true);
END;
/

This procedure call creates the local Streams capture process, named capture_stream . Note that you can use the optional parameter source_database to specify another database for a downstream capture. If you omit this parameter (as in this example) or set the parameter value to NULL, the procedure will create a local capture process.
The streams_type parameter indicates that this procedure will create a capture process. (Note that the same procedure will later be used to create an apply process.) The inclusion_rule parameter with the value set to true means that this procedure will create a positive rule set for the capture process. The true value for the include_dml parameter means that a rule will be created for DML changes, and a true value for the include_ddl parameter means that a rule will be created for DDL changes. The table_name parameter indicates that these rules are associated with the EMP table in the SCOTT schema. You can also set up rules for a schema or for the entire database, using the ADD_SCHEMA_RULES and ADD_GLOBAL_RULES procedures, respectively. See the PL/SQL Packages and Types Reference manual for more information on these packages.
The queue, streams_queue , specified in this procedure call was created by the SET_UP_QUEUE procedure call in Step 5 .
8.            Configure the propagation process. Once the changes are captured and enqueued, propagate the changes to the destination database. To do so, you create a propagation process and associate the source queue with the destination queue. You create the source and destination queues (each named the default streams_queue ) in the source and destination databases, respectively, in Step 5 by calling the SET_UP_QUEUE procedure.
The procedure in Listing 1 creates a propagation process and adds rules to the positive rule set of that process.
This procedure call creates a propagation process, named DB10GSR1_to_DB10GSR2 , for which the source queue is the streams_queue in the DB10GSR1 database and the destination queue is the streams_queue in the DB10GSR2 database. This procedure also adds DML and DDL rules to the positive rule set.

9.            Create the destination table. Before you can start replicating the DDL and DML changes on a source table to the destination database, the table must exist in the destination database. If the table doesn't already exist in the destination database, you have several options for creating the object in the destination database, such as using Data Pump, export/import, RMAN, transportable tablespaces, and so on.

10.          Grant object privileges. On the destination database, the Streams administrator applies the changes captured from the source database. To be able to apply the changes to the destination tables, the Streams administrator must have the required privileges on the relevant objects. For example, if the changes need to be applied to the EMP table of the SCOTT schema, you need to execute the following after connecting to the destination ( DB10GSR2 ) database:
GRANT ALL ON scott.emp TO strmadmin;

Because you set up the Streams administrator with the DBA role in this example (in Step 2 ), you can choose to skip this step. But it is a good idea to explicitly grant the required object privileges to the Streams administrator.

11.          Set the instantiation System Change Number (SCN). Now you need to set the instantiation SCN for the table from the source database you want to replicate. This ensures that the changes in the source table captured before the instantiation SCN is set will not be applied at the destination database. The procedure in Listing 2 sets the instantiation SCN for the EMP table in the destination database, by fetching the current SCN from the source database. Execute the procedure in Listing 2 by connecting to the source database ( DB10GSR1 ) as the Streams administrator.
Listing 2 shows how the GET_SYSTEM_CHANGE_NUMBER procedure of the package DBMS_FLASHBACK returns the current SCN of the source database. This SCN is used to set the instantiation SCN for the EMP table of the SCOTT schema in the destination database. Note that the SET_TABLE_INSTANTIATION_SCN procedure of the DBMS_APPLY_ADM package is called via the DB10GSR2 database link, which means that although this procedure is being called while you are connected to DB10GSR1 , it will be executed in the DB10GSR2 database.
If the table didn't previously exist in the destination database and you use export/import, Data Pump, or transportable tablespaces to copy it, the instantiation SCN will be set automatically for the table.

12.          Configure the apply process at the destination database. Now you create an apply process and associate the destination queue with it. You also add rules for the apply process. You achieve this by calling the ADD_TABLE_RULES procedure of the DBMS_STREAMS_ADM package:

BEGIN
  DBMS_STREAMS_ADM.ADD_TABLE_RULES(
    table_name      => 'scott.emp',
    streams_type    => 'apply',
    streams_name    => 'apply_stream',
    queue_name      =>
            'strmadmin.streams_queue',
    include_dml     => true,
    include_ddl     => true,
    source_database => 'DB10GSR1',
    inclusion_rule  => true);
END;
/

This procedure creates an apply process (as indicated by the streams_type parameter) for the EMP table in the SCOTT schema. The apply process, named apply_stream , is associated with the streams_queue . The apply process also adds DML and DDL rules to the positive rule set (as indicated by the parameter inclusion_rule ).

Note that earlier you used DBMS_STREAMS_ADM.ADD_TABLE_RULES to create (and add rules for) a capture process ( Step 7 ).

13.          Start the capture and apply processes. Now that you have configured all necessary objects and processes, all you need to do is start the capture and apply processes. To start the capture process, connect to the source database and execute the START_CAPTURE procedure of the DBMS_CAPTURE_ADM package:
BEGIN
  DBMS_CAPTURE_ADM.START_CAPTURE(
    capture_name  => 
               'capture_stream');
END;
/

BEGIN
  DBMS_CAPTURE_ADM.STOP_CAPTURE(
    capture_name  => 
               'capture_stream');
END;
/

select capture_name ,STATUS from  dba_capture;


Similarly, to start the apply process, connect to the destination database and execute the START_APPLY process of the DBMS_APPLY_ADM package. However, before you do that, best practices recommend that you set the disable_on_error parameter of the apply process to n , so that the apply process will continue even if it encounters some errors.
BEGIN
  DBMS_APPLY_ADM.SET_PARAMETER(
    apply_name  => 'apply_stream',
    parameter   => 'disable_on_error',
    value       => 'n');
END;
/

BEGIN
  DBMS_APPLY_ADM.START_APPLY(
    apply_name  => 'apply_stream');
END;
/

BEGIN
  DBMS_APPLY_ADM.STOP_APPLY(
    apply_name  => 'apply_stream');
END;
/
Now the Streams replication environment is ready, and DML and DDL changes in the SCOTT.EMP table in the source database will be replicated in the corresponding table in the destination database.

Conclusion
Oracle Streams can capture, propagate, and apply changes in the database automatically, including both DML and DDL changes. Applications requiring replication, data warehouses, database migrations, and database upgrades can all benefit from Oracle Streams.



Monday, December 22, 2014

Create Standby using RMAN Duplicate.

Environment Setup

OS Version: Red Hat Enterprise Linux Server release 5.8 (Tikanga)
Database Version: 10.2.0.1.0
Primary - 192.168.1.10 - server1.oracleadmin.com - db10gp
Standby - 192.168.1.11 - server2.oracleadmin.com - db10gs

Changes in primary

1. Create password file if not present.
orapwd file=orapwdb10gp password=suresh force=y

2. Enable Force logging
SQL>
ALTER DATABASE FORCE LOGGING;
SELECT force_logging FROM v$database;

3. Create standby logfiles
SQL>
col MEMBER format a60
select * from v$logfile;

SQL>
select bytes/1024/1024 "LogSize(MB)" from v$log;

SQL>
ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 '/u01/app/oracle/product/10.2.0/oradata/db10gp/redo04.log' SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 '/u01/app/oracle/product/10.2.0/oradata/db10gp/redo05.log' SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 6 '/u01/app/oracle/product/10.2.0/oradata/db10gp/redo06.log' SIZE 50M;

SQL>
col MEMBER format a60
select * from v$logfile;

4. Enable archive log mode.
SQL>
archive log list;

SQL>
startup mount;
alter database archivelog;
alter database open;

5. Create latest pfile
SQL>
create pfile from spfile;


6. Add standby parameters

vi initdb10gp.ora

# Standby parameters -------------------------------------------------------------------------
db_unique_name='db10gp'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(db10gp,db10gs)'
LOG_ARCHIVE_DEST_2='SERVICE=db10gs LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db10gs'
LOG_ARCHIVE_DEST_STATE_2=ENABLE
# Standby role parameters --------------------------------------------------------------------
*.fal_server=db10gs
*.fal_client=db10gp
*.standby_file_management=auto
*.db_file_name_convert='/u01/app/oracle/product/10.2.0/oradata/db10gs/','/u01/app/oracle/product/10.2.0/oradata/db10gp/','/u01/app/oracle/admin/db10gs/','/u01/app/oracle/admin/db10gp/'
*.log_file_name_convert='/u01/app/oracle/product/10.2.0/oradata/db10gs/','/u01/app/oracle/product/10.2.0/oradata/db10gp/'
# ---------------------------------------------------------------------------------------------

7. Clean shut down the database
SQL>
shutdown immediate;

8. Startup using new file in nomount state
SQL>
startup nomount pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initdb10gp.ora'

9. create spfile from pfile
SQL>
create spfile from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initdb10gp.ora';

10. Restart the datasbase using spfile.
SQL>
shutdown immediate;

SQL>
startup;
show parameter log_archive_dest

11. create listener.ora, sqlnet.ora, tnsnames.ora

[oracle@server1 admin]$ cat listener.ora
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    )
  )

[oracle@server1 admin]$ cat sqlnet.ora
NAMES.DIRECTORY_PATH = (TNSNAMES)

[oracle@server1 admin]$ cat tnsnames.ora
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521)(IP = FIRST))
    )
  )

DB10GP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = db10gp.oracleadmin.com)
      (INSTANCE_NAME = db10gp)
    )
  )

DB10GS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.11)(PORT = 1521))
    (CONNECT_DATA =
      (INSTANCE_NAME = db10gs)
      (SERVICE_NAME = db10gs.oracleadmin.com) (UR=A)
    )
  )

12. Start the listner and check the status

lsnrctl start
lsnrctl status

13. Remove old backups/archive logs and Take full backup of primary database using RMAN

mkdir -p /u01/app/oracle/backup
cd /u01/app/oracle/backup
chmod 777 -R /u01/app/oracle/backup


rman target /

RMAN>
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/u01/app/oracle/backup/%d_%u_%s_%p.bkp';
crosscheck backup;
delete noprompt expired backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all backed up 1 times to DEVICE TYPE disk;
backup database plus archivelog;
backup current controlfile for standby format '/u01/app/oracle/backup/standbycontrol.ctl';
backup spfile format '/u01/app/oracle/backup/spfiledb10gp_%s.ora';
exit

standby
--------
[server2] >
14. Ensure database binaries are installed
echo $ORACLE_HOME

15. Create backup location same as primary
mkdir -p /u01/app/oracle/backup
cd /u01/app/oracle/backup
chmod 777 /u01/app/oracle/backup/*

16. Copy the backup from primary to standby in same location
scp /u01/app/oracle/backup/*.* server2:/u01/app/oracle/backup/

17. Create necessary directories

mkdir -p /u01/app/oracle/admin/db10gs/adump
mkdir -p /u01/app/oracle/admin/db10gs/bdump
mkdir -p /u01/app/oracle/admin/db10gs/cdump
mkdir -p /u01/app/oracle/admin/db10gs/udump
mkdir -p /u01/app/oracle/product/10.2.0/oradata/db10gs

18. Copy the parameter file and password file from primary to standby.
scp /u01/app/oracle/product/10.2.0/db_1/dbs/initdb10gp.ora server2:/u01/app/oracle/product/10.2.0/db_1/dbs/

19. Edit parameter file for standby

cd /u01/app/oracle/product/10.2.0/db_1/dbs
mv initdb10gp.ora  initdb10gs.ora
vi initdb10gs.ora

> *.audit_file_dest='/u01/app/oracle/admin/db10gs/adump'
> *.background_dump_dest='/u01/app/oracle/admin/db10gs/bdump'
> *.control_files='/u01/app/oracle/product/10.2.0/oradata/db10gs/control01.ctl','/u01/app/oracle/product/10.2.0/oradata/db10gs/control02.ctl','/u01/app/oracle/product/10.2.0/oradata/db10gs/control03.ctl'
> *.core_dump_dest='/u01/app/oracle/admin/db10gs/cdump'
> *.user_dump_dest='/u01/app/oracle/admin/db10gs/udump'
> db_unique_name='db10gs'
> LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/flash_recovery_area/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=db10gs'
> LOG_ARCHIVE_DEST_2='SERVICE=db10gp LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db10gp'
> *.fal_server=db10gp
> *.fal_client=db10gs
> *.db_file_name_convert='/u01/app/oracle/product/10.2.0/oradata/db10gp/','/u01/app/oracle/product/10.2.0/oradata/db10gs/','/u01/app/oracle/admin/db10gp/','/u01/app/oracle/admin/db10gs/'
> *.log_file_name_convert='/u01/app/oracle/product/10.2.0/oradata/db10gp/','/u01/app/oracle/product/10.2.0/oradata/db10gs/'


diff initdb10gp.ora initdb10gs.ora | grep ">"

vi /etc/oratab
db10gs:/u01/app/oracle/product/10.2.0/db_1:N

20. Set env and startup standby database using nomount.
SQL>
startup nomount pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initdb10gs.ora';
exit

21. Create listener.ora, sqlnet.ora, tnsnames.ora

[oracle@server2 admin]$ cat listener.ora
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.11)(PORT = 1521))
    )
  )

[oracle@server2 admin]$ cat sqlnet.ora
NAMES.DIRECTORY_PATH = (TNSNAMES)

[oracle@server2 admin]$ cat tnsnames.ora
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.11)(PORT = 1521)(IP = FIRST))
    )
  )

DB10GS =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.11)(PORT = 1521))
    (CONNECT_DATA =
      (INSTANCE_NAME = db10gs)
      (SERVICE_NAME = db10gs.oracleadmin.com) (UR=A)
    )
  )

DB10GP =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    (CONNECT_DATA =
      (INSTANCE_NAME = db10gp)
      (SERVICE_NAME = db10gp.oracleadmin.com)
    )
  )

22. Start the listner and check the status

lsnrctl start
lsnrctl status

23. Connect to rman target as primary and standby as auxiliary

rman target sys/suresh@db10gp auxiliary /
RMAN>
CATALOG START WITH '/u01/app/oracle/backup';
duplicate target database for standby;
exit

24. Standby database should be in mount status
SQL>
select INSTANCE_NAME,status from v$instance;

25. create spfile
SQL>
show parameter spfile
create spfile from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initdb10gs.ora';

25. Shutdown and start standby database.
SQL>
shutdown immediate;
startup nomount
alter database mount standby database;
select name,DB_UNIQUE_NAME,DATABASE_ROLE,open_mode from v$database;

26. Start Managed Recovery Process and check status.
SQL>
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE disconnect from session;
select process, status from v$managed_standby;
!ps -ef | grep mrp

27. Check archive logs in primary and standby are in sync
SQL>
archive log list

28. Check archived logs applied at standby
SQL>
SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

Graceful Switchover & Switchback

Steps to be performed on Primary

1. Check switchover status
SQL>
select  switchover_status FROM v$database;

2. If SWITCHOVER_STATUS=TO STANDBY
SQL>
alter database commit to switchover to physical standby ;

3. If SWITCHOVER_STATUS=SESSIONS ACTIVE
SQL>
alter database commit to switchover to physical standby with session shutdown;

4. Shutdown and start as standby
shutdown immediate
startup nomount ;
alter database mount standby database;
alter system set log_archive_dest_state_2 = defer;


Steps to be performed on Standby Database                                 

5. Check switchover status
SQL>
select  switchover_status FROM v$database;

6. If SWITCHOVER_STATUS=TO PRIMARY
SQL>
alter database commit to switchover to primary;

7. If SWITCHOVER_STATUS=SESSIONS ACTIVE
SQL>
alter database commit to switchover to primary with session shutdown;

8. Shutdown and start as standby
SQL>
shutdown immediate;
startup ;

9. Start MRP on New Standby (Old Primary)              
SQL>
alter database recover managed standby database disconnect from session;

10. Enable log_archive_dest_state_2 in new Primary (Old Standby)              
SQL>
alter system set log_archive_dest_state_2 = enable;

SQL > alter system archive log current;


FAILOVER Steps (Primary failed)

shut immediate;
lsnrctl stop

At standby 

1. Check archive gap
SQL>
SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

2. Copy the required archivelog and register
SQL>
alter database register physical logfile '/u01/app/oracle/flash_recovery_area/1_111_892560559.arc';

3. Stop the redo apply process in standby database.
SQL>
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

4. Finish to apply archive logs copied from primary.
SQL>
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;

5. Activate standby
SQL>
ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;

6. Switch standby database to primary database.
SQL>
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;

7. Open database.
SQL>
ALTER DATABASE OPEN;
select name,DB_UNIQUE_NAME,DATABASE_ROLE,open_mode from v$database;


Upgrade 10201 to 10204

Shutdown all running components

$ isqlplusctl stop
$ emctl stop dbconsole
$ lsnrctl stop
$ sqlplus / as sysdba
SQL> shutdown immediate

Update Binaries

$ cd /home/oracle
$ unzip p6810189_10204_Linux-x86.zip
$ cd Disk1/
$ ./runInstaller

Post upgrade steps

SQL> startup upgrade
SQL> spool pre_upgrade.log
SQL> @utlu102i.sql
SQL> spool upgrade.log
SQL> @catupgrd.sql
SQL> spool off
SQL> shutdown immediate

SQL> startup
SQL> conn / as sysdba
SQL> spool recompile.log
SQL> @utlrp.sql
SQL> spool off


#Check the all components are upgraded.

SQL>
set lines 10000
set pages 1000
column comp_name format a40
column version format a12
column status format a6
select comp_name, version, status from sys.dba_registry;

Sunday, September 7, 2014

Unix Commands

Locating Files under a particular directory
find . -print |grep -i test.sql


Cleanup any unwanted trace files more than seven days old
find . *.trc -mtime +7 -exec rm {} \;

Locate Oracle files that contain certain strings
find . -print | xargs grep rollback

Locate recently created UNIX files (in the past one day)
find . -mtime -type f -1 -print

Finding large files on the server (more than 100MB in size)
find . -size +102400 -print

To Check file size
ls -l|grep ^d|awk {'print $9'}|xargs du -sh

Find_files_unix (Ex: 4 days)
find /u01/app/oracle/diag/tnslsnr -type f -mtime +4

Remove four day files
find /u01/app/oracle/diag/tnslsnr -type f -mtime +4 -exec rm {} \; >/dev/null 2>&1

Find the size of files
find /z01 -type f -size +1000k -exec ls -lh {} \; 2> /dev/null | awk '{ print $NF ": " $5 }' | sort -nk 2,2

Get lun information
lsattr -El hdisk91
lsattr -El hdisk91 -a lun_id

Get Manufacturer and Machine Type and Model
lscfg -vpl hdisk91

List Physical volumes
lspv

Kill all similar processes with single command (in this case opmn)
ps -ef | grep opmn |grep -v grep | awk ‘{print $2}’ |xargs -i kill -9 {}

To remove a specific column of output from a UNIX command – for example to determine the UNIX process Ids for all Oracle processes on server (second column)
ps -ef |grep -i oracle |awk '{ print $2 }'

Changing the standard prompt for Oracle Users
Edit the .profile for the oracle user
PS1="`hostname`*$ORACLE_SID:$PWD>"

Display top 10 CPU consumers using the ps command
/usr/ucb/ps auxgw | head -11

Show number of active Oracle dedicated connection users for a particular ORACLE_SID
ps -ef | grep $ORACLE_SID|grep -v grep|grep -v ora_|wc -

Display the number of CPU’s in Solaris
psrinfo -v | grep "Status of processor"|wc -l

Display the number of CPU’s in AIX
lsdev -C | grep Process|wc -l

Display RAM Memory size on Solaris
prtconf |grep -i mem

Display RAM memory size on AIX
First determine name of memory device
lsdev -C |grep mem then assuming the name of the memory device is ‘mem0’
lsattr -El mem0

Swap space allocation and usage
Solaris : swap -s or swap -l
Aix : lsps -a

Total number of semaphores held by all instances on server
ipcs -as | awk '{sum += $9} END {print sum}'

View allocated RAM memory segments
ipcs -pmb

Manually deallocate shared memeory segments
ipcrm -m '<ID>'

Show mount points for a disk in AIX
lspv -l hdisk13

Display amount of occupied space (in KB) for a file or collection of files in a directory or sub-directory
du -ks * | sort -n| tail

Display total file space in a directory
du -ks .

AIX: Get LUN id from ASM disk
ls -ltr |grep "`ls -ltr /dev/asm_disk50| cut -c 39-45`" | grep " hdisk"| awk '{print $10}' | awk '{print "lsattr -El ",$1," |grep lun_id"}'| sh

AIX: Get All LUN id from ASM

for i in `ls /dev/asm_disk*`
do
hid=$(ls -ltr |grep "`ls -ltr $i | cut -c 39-45`" | grep " hdisk"| awk '{print $10}')
lid=$(ls -ltr |grep "`ls -ltr $i | cut -c 39-45`" | grep " hdisk"| awk '{print $10}' | awk '{print "lsattr -El ",$1," |grep lun_id"}'| sh | awk '{print $2}')
echo $i" "$hid" "$lid
done

RSYNC
rsync --partial --progress -avzl -e ssh /full_source_dir/ server1.oracleadmin.com:/full_destination_dir/

df in HP-UX

df -Pk | awk '
BEGIN {print "Filesystem                          Mount Point                 Total GB   Avail GB    Used GB  Used"
       print "----------------------------------- ------------------------- ---------- ---------- ---------- -----"}
END {print ""}
/dev/ || /^[0-9a-zA-Z.]*:\// {
printf ("%-35.35s %-25s %10.2f %10.2f %10.2f %4.0f%\n",$1,$6,$2/1024/1024,$4/1024/1024,$3/1024/1024,$5)
}'

Replace a String in Multiple Files in Linux
grep -rl '11107' ./ | xargs sed -i 's/11107/12102/g'

Check all ORA errors
cd $ORACLE_BASE
echo " "$ORACLE_BASE
read -p "Oracle Base is correct ? y/n: " yn
 case $yn in
        [Yy]* ) grep -oP "ORA-[^ ]+" `find . -name alert*.log` |awk -F ':' '{ print $2 }'| sort | uniq -c | sort -r ;;
        [Nn]* ) exit;;
 esac

Wednesday, August 27, 2014

DBA Queries