December 28, 2014

Delete multiple rows from a table

Today we have face one issue, We have to delete the 25930814 rows in a table of size 23 gb. We just followed like below.

Going to further first we have to take the export of that table.

$ expdp directory=data_pump_dir dumpfile=table.dmp tables=<username.tablename> logfile=table.log

Here table export backup is needed because if anything went wrong we will import that table.

Once the table export is completed prepare a shell script that will commit the data after every 1 lac rows deleted from the table.

#!/bin/bash

export ORACLE_SID=raj
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/db_1
export PATH=/u01/app/oracle/product/11.2.0.3/db_1/bin:$PATH

sqlplus -s "/ as sysdba" <<EOF

set feed off
set pages 0
BEGIN
LOOP
DELETE FROM <username.tablename> where <condition> AND ROWNUM <= 100000;
EXIT WHEN SQL%ROWCOUNT = 0;
COMMIT;
END LOOP;
END;
/
exit
EOF

Run the script using the nohup command.

nohup ksh delete.sh > delete.out &

$jobs -l

[1]+ 11228 Running                 nohup ksh delete.sh > delete.out &


This way we avoid rollback segment contention and at the same time we also avoid frequent commit (instead of commit for every row).

December 13, 2014

Remove or Delete or Un-schedule Oracle OEM scheduled backup jobs

To permanently delete a scheduled backup job from OEM 10g

Login to the Grid > go to jobs tab >  

Here you can see the Job Activity page. Give the details:

Status: All
Name: Name of the database the job is scheduled
View: Executions

By choosing the above options it will list out the jobs under the database.

Use the “Select” radio buttons on the left side of the list to select the job you want to delete.

Then click on the 'Delete Run' button >

OEM will give you two options:

Do you want to delete just this run or 
Delete all runs of job


Select the Delete all runs of job option if you want to remove this job permanently from the OEM.

If you select first option on the above it simply deletes the job for this occurrence. After that OEM will submit this job automatically for the next occurrence.


The 
Delete all runs of job option will delete the job from the OEM permanently. 


If you want to re run a failed backup at OEM level then:

Login to Grid > go to jobs tab >


Here you can see the Job Activity page. Give the details:

Status: All
Name: Name of the database the job is scheduled
View: Executions

By choosing the above options it will list out the jobs under the database.

Use the “Select” radio buttons on the left side of the list to select the job you want to run it again.

Then click on the try again, it will ask for the confirmation just click on Yes button.

If you want to show the status of the job then set the options as above on the Job Activity Page.



December 6, 2014

Convert RAC database from Archivelog Mode to NoArchivelog Mode

[oracle@pard15 ~]$. oraenv
ORACLE_SID = [oracle]STG1
The Oracle base has been changed from /u01/app/oracle to /u02/app/oracle
[oracle@pard15 ~]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Jun 10 07:12:55 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +RECO
Oldest online log sequence     26114
Next log sequence to archive   26116
Current log sequence           26116
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@pard15 ~]$srvctl status database -d STG
Instance STG1 is running on node pard15
Instance STG2 is running on node pard16
[oracle@pard15 ~]$srvctl stop database -d STG
[oracle@pard15 ~]$srvctl status database -d STG
Instance STG1 is not running on node pard15
Instance STG2 is not running on node pard16
[oracle@pard15 ~]$srvctl start instance -i STG1 -d STG -o mount
[oracle@pard15 ~]$srvctl status database -d STG
Instance STG1 is running on node pard15
Instance STG2 is not running on node pard16
[oracle@pard15 ~]$. oraenv
ORACLE_SID = [STG1] ?
The Oracle base remains unchanged with value /u02/app/oracle
[oracle@pard15 ~]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Jun 10 07:15:01 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select inst_id,instance_name,status from gv$instance;

   INST_ID INSTANCE_NAME    STATUS
---------- ---------------- ------------
         1       STG1           MOUNTED

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            +RECO
Oldest online log sequence     26114
Next log sequence to archive   26116
Current log sequence           26116
SQL> alter database noarchivelog;

Database altered.

SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            +RECO
Oldest online log sequence     26114
Current log sequence           26116
SQL> alter database open;

Database altered.

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
[oracle@pard15 ~]$srvctl status database -d STG
Instance STG1 is running on node pard15
Instance STG2 is not running on node pard16
[oracle@pard15 ~]$srvctl stop instance -i STG1 -d STG
[oracle@pard15 ~]$srvctl start database -d STG
[oracle@pard15 ~]$srvctl status database -d STG
Instance STG1 is running on node pard15
Instance STG2 is running on node pard16
[oracle@pard15 ~]$. oraenv
ORACLE_SID = [STG1] ?
The Oracle base remains unchanged with value /u02/app/oracle
[oracle@pard15 ~]$sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Tue Jun 10 07:17:57 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> select inst_id,instance_name,status from gv$instance;

   INST_ID INSTANCE_NAME    STATUS
---------- ---------------- ------------
         1 STG1           OPEN
         2 STG2           OPEN

SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            +RECO
Oldest online log sequence     26114
Current log sequence           26116

December 5, 2014

ORA-48913: Writing into trace file failed, file size limit [10000000] reached


If the trace file reached its maximum specified size then we got this error.  MAX_DUMP_FILE_SIZE parameter specifies the maximum size of the trace file. If you increase the value of this parameter clears the error.


SQL> show parameter MAX_DUMP_FILE_SIZE

NAME                                 TYPE                             VALUE
------------------------------------ -------------------------------- ------------------------------
max_dump_file_size                   string                           10M

Check the mount point has the free space to increase the MAX_DUMP_FILE_SIZE parameter. If
it has the enough free space then increase the value.

SQL> alter system set MAX_DUMP_FILE_SIZE ='20m';

System altered.

Even we can set the  MAX_DUMP_FILE_SIZE parameter value to 'unlimited'.

SQL> alter system set MAX_DUMP_FILE_SIZE = unlimited;

UNLIMITED means there is no upper limit on trace file size. Thus files can be  increase to operating system level limits. But it causes the disk utilization high.



SQL> show parameter MAX_DUMP_FILE_SIZE

NAME                                 TYPE                             VALUE
------------------------------------ -------------------------------- ------------------------------
max_dump_file_size                   string                           20M


If the mount point in which trace files are located, doesn't have the enough space then you just zip the trace file to subsidize this error (Temporary fix).