Thursday, November 13, 2014

While scheduling backup job  through OEM, I've encountered "ora-20446 the owner of the job is not registered". as workaround from metalink simply execute the following command using sysman user:


sqlplus sysman SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 13 12:14:41 2014 Copyright (c) 1982, 2009, Oracle. All rights reserved. Enter password: Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Data Mining and Real Application Testing options SYSMAN@ feco1>execute MGMT_USER_MAKE_EM_USER('DB_USER');


while DB_USER is the user that you use to connect to OEM.



Reference:
Doc ID 463874.1

Change SYS password

It's being long time writing a post in my blog ..

I've inherited newly installed RAC four nodes without OEM configuration and without SYS password which required to configure OEM.

Generally this post for how to change the sys password in RAC environment which seems very simple at the first instance but it has a trick. The trick is when you change the sys password in one instance, it doesn't reflect on other instances unlike any other user so you need to change it in all instances as follows:

SYS@ feco1> alter user sys identified by newPwd;

User altered.

Then login to node2 and do the same

SYS@ feco2> alter user sys identified by newPwd;

User altered.

and do so in all your RAC nodes.

the other solution which is the only one for 10g is to change the password in one instance and then copy your password file (orapw<instance_name>) located in '$ORACLE_HOME/dbs' to other nodes and amend the name accordingly,

Sunday, May 25, 2014

Change Flash Recovery Area Location

Due to insufficient space on some drives/mount point, you need to change the location of fast/flash recovery area.

Old Location: D:\flash_recovery_area
New Location: E:\flash_recovery_area

ALTER SYSTEM SET DB_RECOVERY_FILE_DEST='E:\flash_recovery_area' SCOPE=BOTH SID='*';

After change this parametr, all new archive log will create on the new location and then database going to remove old archive log files once aged out.

In the case that you need to your old files (archive log, backupset, datafile image copy) do the following:


for archivelog transmission:

RMAN> BACKUP AS COPY ARCHIVELOG ALL DELETE INPUT;

 for backupset transmission:

RMAN> BACKUP DEVICE TYPE DISK BACKUPSET ALL DELETE INPUT;

for datafile image copy transmission:


RMAN> BACKUP AS COPY DATAFILECOPY ALL DELETE INPUT;

Physical Standby vs Logical Standby


Physical Standby
Logical Standby
Complete (Block-based) copy of the primary database.
Can be a complete or partial copy of primary DB.
Use Redo Apply method to apply changes.
Redo data is first converted into SQL statements and then applied to the standby database.
Redo Apply uses Managed Recovery Process (MRP) in order to manage application of the change in information on redo.
The Logical Standby Process (LSP) process manages the application of changes to a logical standby database.
In 11g, a physical standby database can be accessible in read-only mode while Redo Apply is working (Active Data Guard).
This method makes it possible to access the standby database permanently and allows read/write while the replication of data is active.
Unable to change anything on DB structure.
Read-Write mode enables you to create as many object as you need.
Supports all the data types.
One discouraging aspect of the logical standby database is the unsupported data types, objects, and DDLs.
Active Data Guard comes with extra cost.
Free of cost
Easy to configure, manage and less or no performance issues.
More steps to configure, complex to manage and more performance issues.


Saturday, May 24, 2014

OCR Backups Filling Up CRS_HOME Space

While checking my OCR backup I wondered why Oracle keep creating OCR backup without deleting the old ones. Should I delete them by my own?.. it sounds unkind!!.

I start searching on Google and metaling.. Guess what??? It’s a BUG.


That simply means, if you have dozens of OCR backups you may facing the same bug. Since the OCR backups should consist of 7 files as follow:

#ls -ltr u02/app/11.2.0/grid/cdata/feco-cluster/day* week* backup0*

-rw-------    1 root     system      7028736 May 22 2011  backup02.ocr
-rw-------    1 root     system      7028736 May 22 2011  backup01.ocr
-rw-------    1 root     system      7028736 May 22 2011  backup00.ocr
-rw-------    1 root     system      6979584 May 22 2011  week.ocr
-rw-------    1 root     system      7028736 May 22 2011  day_.ocr
-rw-------    1 root     system      7028736 May 22 2011  day.ocr

presenting the result of :

# ./ocrconfig -showbackup auto

feco04     2014/05/24 12:31:09     /u02/app/11.2.0/grid/cdata/feco-cluster/backup00.ocr

feco04     2014/05/24 08:31:07     /u02/app/11.2.0/grid/cdata/feco-cluster/backup01.ocr

feco04     2014/05/24 04:31:06     /u02/app/11.2.0/grid/cdata/feco-cluster/backup02.ocr

feco04     2014/05/23 04:31:00     /u02/app/11.2.0/grid/cdata/feco-cluster/day.ocr

feco04     2014/05/14 04:29:51     /u02/app/11.2.0/grid/cdata/feco-cluster/week.ocr


My current ocr backup look like:


-rw-------    1 root     system      7221248 Jun 24 2013  13458777.ocr
-rw-------    1 root     system      7221248 Jun 24 2013  14872007.ocr
-rw-------    1 root     system      7221248 Jun 24 2013  28713517.ocr
-rw-------    1 root     system      7221248 Jun 25 2013  39937824.ocr
-rw-------    1 root     system      7221248 Jun 25 2013  56169871.ocr
-rw-------    1 root     system      7221248 Jun 25 2013  58569011.ocr
:
:
-rw-------    1 root     system      7221248 Jun 27 2013  21069301.ocr
-rw-------    1 root     system      7221248 Jun 27 2013  11741111.ocr
-rw-------    1 root     system      7221248 Jun 27 2013  29616835.ocr
-rw-------    1 root     system      7221248 Jun 27 2013  19887106.ocr
-rw-------    1 root     system      7221248 Jun 28 2013  27246017.ocr

And crsd.log showing this error:

OCRSRV][9521]Failure in renaming file [/u02/app/11.2.0/grid/cdata/feco-cluster/25677603.ocr] to [/u02/app/11.2.0/grid/cdata/feco-cluster/backup00.ocr]


How to solve that???

According to (Doc ID 1191067.1) "change all 7 automatic backup files to be owned  by root:root with permission "-rw-------""

The current privilege of the 7 files are:

-rw-r--r--    1 grid     oinstall      7028736 May 22 2011  backup02.ocr
-rw-r--r--    1 grid     oinstall      7028736 May 22 2011  backup01.ocr
-rw-r--r--    1 grid     oinstall      7028736 May 22 2011  backup00.ocr
-rw-r--r--    1 grid     oinstall      6979584 May 22 2011  week.ocr
-rw-r--r--    1 grid     oinstall      7028736 May 22 2011  day_.ocr
-rw-r--r--    1 grid     oinstall      7028736 May 22 2011  day.ocr 

Just change them to:

chown root:system week*
chown root:system day*
chown root:system backup0*

chmod 600 week*
chmod 600 day*
chmod 600 backup0*

:-)

Note:
My database version is : 11.2.0.2.0

Reference:
Automatic OCR Backup Filling Up <CRS_HOME>/cdata/<clustername> Directory (Doc ID 1191067.1)


Tuesday, April 29, 2014

Monday, April 14, 2014

Duplicate Database Using RMAN



Since 11gR2 released we're able to duplicate database without connecting to target DB or CATALOG using backup where target database could be down. This kind of duplicate termed as “Backup-Based Duplication without a target and Recovery Catalog Connection”.

    1-    From RMAN prompt check control file autobackup is ON.

    2-   Connect to the target to get a new backup.
cmd > rman target /
rman > backup database plus archivelog;

    3-   Once it finished copy backup folder to your destination DB using normal OS copy.

    4-   Create your duplicate instance – windows only
cmd > oradim –NEW –SID destination database name

    5-   Create parameter file with following parameter.
Dn_name= destination database name
Db_unique_name= destination database name
Db_file_name_conevrt=’source datafile location’,’destination datafile location’
Log_file_name_convert=’source logfile location’,’destination logfile location’

    6-   Startup the destination DB in nomount stage.
sql > Startup nomount

    7-   Connect to the auxiliary through RMAN and restore the db.
cmd > rman auxiliary /
rman > duplicate database to DB_NAME backup location ‘backup PATH’;

Note:
As per metaling In release 11.2.0.2 there is a bug through an ora-600


RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 01/09/2013 11:39:15
RMAN-06403: could not obtain a fully authorized session
RMAN-04006: error from auxiliary database: ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
RMAN-04014: startup failed: ORA-00600: internal error code, arguments: [17099], [], [], [], [], [], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [KSMFPG5], [0xAEC0000], [], [], [], [], [], [], [], [], [], []


When you try to open the DB you will get following error:


ORA-19838: Cannot use this control file to open database


And when you show up db_name and db_unique_name parameters , you find old name for db_name so continue next steps.

    8-   Backup control file as trace.
sql > alter database backup controlfile to trace as ‘PATH(CNTRL.sql)’;

    9-   Edit controlfile trace to replace (REUSE to SET, OLD_DB_NAME to NEW_DB_NAME and remove all blank spaces and commented rows)

    10- Restart database  in mount stage and change the DB_NAME
sql > shutdown
sql > startup mount
sql > alter system set db_name=NEW_DB_NAME scope=spfile;

    11- Shutdown the DB again and recreate control file after remove it through OS.
sql > shutdown
sql > @CNTRL.sql

    12-Alter database open with resetlogs option.
sql > alter database open resetlogs

Note:
If you get below error go and check the alert file to find out which parameters are deprecated and remove them.

ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance

Congratulation you have duplicate your database successfully.

Saturday, March 1, 2014

Customised Capture Statistic


Database Growth


This script is designed to snapshoot the size of the database on a daily basis.

CREATE TABLE dba1.dbgrowth
(
   SDate   DATE NOT NULL,
   FullDBS     NUMBER,
   DBS     NUMBER,
   UsedSP     NUMBER,
   FreeSP     NUMBER


)
TABLESPACE USERS;

-- add primary key to sdate column
ALTER TABLE dba1.dbgrowth ADD(CONSTRAINT PK_DATABASE_GROWTH PRIMARY KEY  (sdate));

--Fill the database growth table by select statement

Add this entry to script.sql

INSERT INTO dba1.dbgrowth
SELECT SYSDATE "Log Date",
         (SUM (all_df.bytes) / 1024 / 1024 / 1024) "Full Database Size",
         (df.p / 1024 / 1024 / 1024) "Database space",
         (used.p / 1024 / 1024 / 1024) "Used space",
         (free.p / 1024 / 1024 / 1024) "Free space"
    FROM (SELECT bytes FROM v$datafile
          UNION ALL
          SELECT bytes FROM v$tempfile
          UNION ALL
          SELECT bytes FROM v$log) all_df,
         (SELECT SUM (bytes) AS p FROM dba_data_files) df,
         (SELECT SUM (bytes) AS p FROM dba_free_space) free,
         (SELECT SUM (bytes) AS p FROM dba_segments) used
GROUP BY free.p, used.p, df.p;
Commit;

Add this entry to dbreads.sh

ORACLE_HOME=/u02/app/oracle/product/11.2.0/dbhome_1; export ORACLE_HOME
ORACLE_UNQNAME=imcpr; export ORACLE_UNQNAME
ORACLE_SID=imcpr2; export ORACLE_SID
$ORACLE_HOME/bin/sqlplus / as sysdba @/u02/app/oracle/DBScripts/dbreads.sql


Schedule this job as daily script on crontab
00 01 * * * /u02/app/oracle/DBScripts/dbreads.sh -cron -silent start


Tablespace Growth


This script is designed to snapshoot the details of all tablespaces.

create table dba1.tsreads as

Select trunc(SYSDATE) "Log Date",ts.tablespace_name, ts.status, ts.contents,
       size_info.megs_alloc "Size MB", size_info.megs_free "Free MB", size_info.megs_used "Used MB",
       size_info.pct_free "Used%", size_info.pct_used "Free%"
From
      (
      select  a.tablespace_name,
             round(a.bytes_alloc / 1024 / 1024) megs_alloc,
             round(nvl(b.bytes_free, 0) / 1024 / 1024) megs_free,
             round((a.bytes_alloc - nvl(b.bytes_free, 0)) / 1024 / 1024) megs_used,
             round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_Free,
            100 - round((nvl(b.bytes_free, 0) / a.bytes_alloc) * 100) Pct_used
      from  ( select  f.tablespace_name,
                     sum(f.bytes) bytes_alloc,
                     sum(decode(f.autoextensible, 'YES',f.maxbytes,'NO', f.bytes)) maxbytes
              from dba_data_files f
              group by tablespace_name) a,
            ( select  f.tablespace_name,
                     sum(f.bytes)  bytes_free
              from dba_free_space f
              group by tablespace_name) b
      where a.tablespace_name = b.tablespace_name (+)
      union all
      select h.tablespace_name,
             round(sum(h.bytes_free + h.bytes_used) / 1048576) megs_alloc,
             round(sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / 1048576) megs_free,
             round(sum(nvl(p.bytes_used, 0))/ 1048576) megs_used,
             round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) Pct_Free,
             100 - round((sum((h.bytes_free + h.bytes_used) - nvl(p.bytes_used, 0)) / sum(h.bytes_used + h.bytes_free)) * 100) pct_used
      from   sys.v_$TEMP_SPACE_HEADER h, sys.v_$Temp_extent_pool p, dba_temp_files f
      where  p.file_id(+) = h.file_id
      and    p.tablespace_name(+) = h.tablespace_name
      and    f.file_id = h.file_id
      and    f.tablespace_name = h.tablespace_name
      group by h.tablespace_name
      ) size_info,
      sys.dba_tablespaces ts
where ts.tablespace_name = size_info.tablespace_name

dbreads.sh
dbreads.sql
Scheduled once every day


Table Growth


This script is designed to snapshoot the biggest tables from number of rows or size aspects. 
create table dba1.tbreads as
Select trunc(sysdate) "Log Date", segment_name,round(sum(bytes)/1024/1024/1024,4) "GB", b.num_rows
from  sys.dba_segments a, DBA_TABLES b
Where segment_type in ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION')
and a.OWNER = 'PHOENIX'
and  a.owner=b.owner
and a.segment_name=b.table_name
group by segment_name,b.num_rows
having round(sum(bytes)/1024/1024/1024,2)>2 or  b.num_rows>2000000
order by 2 desc
dbreads.sh
dbreads.sql
Scheduled once every day



Number & Active Sessions Load


This script is designed to snapshoot the load and number of session every hour.

Create table dba1.sessionstat as
SELECT SYSDATE "Log Date",
            COUNT (*) AS imcpr1,
            (SELECT COUNT (*) AS imcpr2 FROM gv$session WHERE inst_id = 2) imcpr2,
             round((select value from Gv$osstat where stat_name='LOAD'  AND INST_ID=1),2) LOAD1,
             round((select value from Gv$osstat where stat_name='LOAD'  AND INST_ID=2),2) LOAD2
       FROM gv$session
      WHERE inst_id = 1
   GROUP BY inst_id;



And then insert the same statement
 Sessionstat.sh
Sessionstat.sql
Schedule every one hour



CPU Utilization


This script is designed to snapshot the CPU usage every hour.


create table dba1.cpureads as
with AASSTAT as (
           select
                 decode(n.wait_class,'User I/O','User I/O',
                                     'Commit','Commit',
                                     'Wait')                               CLASS,
                 sum(round(m.time_waited/m.INTSIZE_CSEC,3))                AAS,
                 BEGIN_TIME ,
                 END_TIME
           from  gv$waitclassmetric  m,
                 gv$system_wait_class n
           where m.wait_class_id=n.wait_class_id
             and n.wait_class != 'Idle'
            and n.inst_id=&&1 and  m.inst_id=&&1
           group by  decode(n.wait_class,'User I/O','User I/O', 'Commit','Commit', 'Wait'), BEGIN_TIME, END_TIME
          union
             select 'CPU_ORA_CONSUMED'                                     CLASS,
                    round(value/100,3)                                     AAS,
                 BEGIN_TIME ,
                 END_TIME
             from gv$sysmetric
             where metric_name='CPU Usage Per Sec'
               and group_id=2
             and  inst_id=&&1
          union
            select 'CPU_OS'                                                CLASS ,
                    round((prcnt.busy*parameter.cpu_count)/100,3)          AAS,
                 BEGIN_TIME ,
                 END_TIME
            from
              ( select value busy, BEGIN_TIME,END_TIME from gv$sysmetric where metric_name='Host CPU Utilization (%)' and group_id=2 and inst_id=&&1 ) prcnt,
              ( select value cpu_count from gv$parameter where name='cpu_count' and inst_id=&&1)  parameter
          union
             select
               'CPU_ORA_DEMAND'                                            CLASS,
               nvl(round( sum(decode(session_state,'ON CPU',1,0))/60,2),0) AAS,
               cast(min(SAMPLE_TIME) as date) BEGIN_TIME ,
               cast(max(SAMPLE_TIME) as date) END_TIME
             from gv$active_session_history ash
              where inst_id=&&1 and SAMPLE_TIME >= (select BEGIN_TIME from gv$sysmetric where metric_name='CPU Usage Per Sec' and group_id=2 and inst_id=&&1 )
               and SAMPLE_TIME < (select END_TIME from gv$sysmetric where metric_name='CPU Usage Per Sec' and group_id=2 and inst_id=&&1 )
)
select trunc(sysdate) "LOG_DATE", &&1 INST_ID,
       to_char(BEGIN_TIME,'HH:MI:SS') BEGIN_TIME,
       to_char(END_TIME,'HH:MI:SS') END_TIME,
       ( decode(sign(CPU_OS-CPU_ORA_CONSUMED), -1, 0, (CPU_OS - CPU_ORA_CONSUMED )) +
       CPU_ORA_CONSUMED +
        decode(sign(CPU_ORA_DEMAND-CPU_ORA_CONSUMED), -1, 0, (CPU_ORA_DEMAND - CPU_ORA_CONSUMED ))) CPU_TOTAL,
       decode(sign(CPU_OS-CPU_ORA_CONSUMED), -1, 0, (CPU_OS - CPU_ORA_CONSUMED )) CPU_OS,
       CPU_ORA_CONSUMED CPU_ORA,
       decode(sign(CPU_ORA_DEMAND-CPU_ORA_CONSUMED), -1, 0, (CPU_ORA_DEMAND - CPU_ORA_CONSUMED )) CPU_ORA_WAIT,
       COMMIT,
       READIO,
       WAIT
from (
select trunc(sysdate) "LOG_DATE", &&1 INST_ID,
       min(BEGIN_TIME) BEGIN_TIME,
       max(END_TIME) END_TIME,
       sum(decode(CLASS,'CPU_ORA_CONSUMED',AAS,0)) CPU_ORA_CONSUMED,
       sum(decode(CLASS,'CPU_ORA_DEMAND'  ,AAS,0)) CPU_ORA_DEMAND,
       sum(decode(CLASS,'CPU_OS'          ,AAS,0)) CPU_OS,
       sum(decode(CLASS,'Commit'          ,AAS,0)) COMMIT,
       sum(decode(CLASS,'User I/O'        ,AAS,0)) READIO,
       sum(decode(CLASS,'Wait'            ,AAS,0)) WAIT
from AASSTAT)
-- Reference; http://www.kylehailey.com/oracle-cpu-time/
/

Then add entry in crontab to run every hour
Cpureads.sql