Thursday, 14 January 2016

How to update/patch the time zone version


How to update/patch the time zone version 1 to 4

(Before or after error while upgrading 

[9i-11gr1])



-The best way to update the time zone is to apply the patch to 9i home before starting upgrade(DOC id   568125.1).
-9i has time zone version 1 but to upgrade to 11g we need time zone version 4.
--We have not got any Warning in pre-check upgrade log (Usual the warning message will be shown).
--We checked for the affected object from time zone version in 9i home.
---As per the above output no object was affected, but still we thought to apply patch, and the reason was unknown as it was taking long time to diagnose. We decided to ignore the patch (which was bad idea).
--While upgrade process (catupgrd.sql), it was stooped with the error related to time zone.

***********************END LINES OF ERROR**********************************
SQL> SELECT TO_NUMBER('MUST_BE_SAME_TIMEZONE_FILE_VERSION')
2 FROM registry$database
3 WHERE tz_version != (SELECT version from v$timezone_file);
SELECT TO_NUMBER('MUST_BE_SAME_TIMEZONE_FILE_VERSION')
*
ERROR at line 1:
ORA-01722: invalid number
*****************************************************************************
--After many attempts to apply patch and trying to troubleshoot we have ended up with unknown reason for patch fail.
--As we could not apply patch we thought to do this process manually (after recommended by oracle support)
--Below are the manual steps to follow.

--Now our 9i database was of no use as we have opened 11gr1 (11.1.0.7) in upgrade mode


 

oracle 9i
*********

To check the time stamp version in 9i.
SQL> SELECT CASE COUNT(DISTINCT(tzname))
 WHEN 183 then 1
 WHEN 355 then 1
 WHEN 347 then 1
 WHEN 377 then 2
 WHEN 186 then CASE COUNT(tzname) WHEN 636 then 2 WHEN 626 then 3 ELSE 0 END
 WHEN 185 then 3
 WHEN 386 then 3
 WHEN 387 then case COUNT(tzname) WHEN 1438 then 3 ELSE 0 end
 WHEN 391 then case COUNT(tzname) WHEN 1457 then 4 ELSE 0 end
 WHEN 392 then case COUNT(tzname) WHEN 1458 then 4 ELSE 0 end
 WHEN 188 then case COUNT(tzname) WHEN 637 then 4 ELSE 0 end
 WHEN 189 then case COUNT(tzname) WHEN 638 then 4 ELSE 0 end
 ELSE 0 end VERSION
 FROM v$timezone_names;

VERSION
----------
1

Steps as osuser (oracle)--Replace the existing file with new files from patch.
Extract the patch zip file p5632264_92080_SOLARIS64.zip.
unzip p5632264_92080_SOLARIS64.zip
Take the backup of $ORACLE_HOME/oracore/zoneinfo/
cd $ORACLE_HOME/oracore
cp -R zoneinfo zoneinfo.bkp
cd 5632264/files/oracore/zoneinfo/
Copy the three files readme.txt, timezlrg.dat and timezone.dat into $ORACLE_HOME/oracore/zoneinfo/

 

Perform the below activity to update the timezone in registry$database.

UPDATE registry$database SET TZ_VERSION=4 ;
commit ;

Verify both v$timezone_file and registry$database having same value for timezone version and re-try the upgrade.

SQL> select * from registry$database;

PLATFORM_ID
-----------
PLATFORM_NAME
--------------------------------------------------------------------------------
EDITION TZ_VERSION
------------------------------ ----------

4

SQL> select * from v$timezone_file;

FILENAME VERSION
------------ ----------
timezlrg.dat 4



There you good to go.................................................

Tuesday, 15 December 2015

How to Modify SCAN Setting or SCAN Listener Port after Installation.

                   How to Modify SCAN Setting or SCAN Listener Port after Installation.


1. As per documentation "Oracle Grid Infrastructure Installation Guide", Oracle strongly recommend to configure SCAN name in either DNS or GNS as /etc/hosts file can only resolve to one IP address.

SCAN IP must be in same subnet as public and VIP, This Below steps is for the SCAN IP in same sub-net as public for different sub-net please search for oracle Doc.


1a. If you intend to use /etc/hosts for SCAN name resolution, the same and only entry for SCAN name must exist on all nodes.

1b. If you intend to use DNS for SCAN name resolution, remove entries for SCAN name from /etc/hosts on all nodes, and make sure nslookup returns good result on all nodes, for example:




Steps to follow:

Precheck

$GRID_HOME/bin$ nslookup New_scan_name.com
Server:        xx.xxx.xx.xx
Address:        xx.xx.xx.xx#xx

Name:   New_scan_name.com
Address: xx.xx.xx.xx1
Name:   New_scan_name.com
Address: xx.xx.xx.xx2
Name:   New_scan_name.com
Address: xx.xx.xx.xx0

$GRID_HOME/bin$ srvctl config scan
SCAN name: old_scan.com, Network: 1/xx.xx.xx.xx/xxx.xxx.xxx.0/eth0
SCAN VIP name: scan1, IP: old_scan.com/xx.xx.xx.xx2
SCAN VIP name: scan2, IP:old_scan.com/xx.xx.xx.xx0
SCAN VIP name: scan3, IP: old_scan.com/xx.xx.xx.xx1
$GRID_HOME/bin$ srvctl config network
Network exists: 1/xx.xx.xx.xx/xxx.xxx.xxx.x/eth0, type static


Once #1a or #1b is configured properly, execute the following to modify:

If name resolution for SCAN is being switched from local hosts file to DNS, be sure to remove SCAN name in local hosts file on all nodes prior to execute below commands.

2.1. To modify SCAN name or SCAN VIP addresses:

2.1.1. As grid user stop resources:

$ $GRID_HOME/bin/srvctl stop scan_listener
$ $GRID_HOME/bin/srvctl stop scan

Execution

2.1.2. As root user modify SCAN:
#$GRID_HOME/bin/srvctl modify scan -n New_scan_name.com
Once SCAN name is changed, update database init.ora/spfile parameter remote_listener to the new one.

alter system set remote_listener = "New_scan_name.com:1521" scope=both

2.1.3. As grid user modify and start resources:

$ $GRID_HOME/bin/srvctl modify scan_listener -u
$ $GRID_HOME/bin/srvctl start scan_listener

Post Check:

$ $GRID_HOME/bin$ ./srvctl config scan
SCAN name: New_scan_name.com, Network: 1/xx.xx.xx.xx/xxx.xxx.xxx.0/eth0
SCAN VIP name: scan1, IP: New_scan_name.com/xx.xx.xx.xx1
SCAN VIP name: scan2, IP: New_scan_name.com/xx.xx.xx.xx2
SCAN VIP name: scan3, IP: New_scan_name.comt/xx.xx.xx.xx0

$ $GRID_HOME/bin/srvctl config scan_listener
SCAN Listener LISTENER_SCAN1 exists. Port: TCP:1521
SCAN Listener LISTENER_SCAN2 exists. Port: TCP:1521
SCAN Listener LISTENER_SCAN3 exists. Port: TCP:1521




Ref: ORACLE DOC: (Doc ID 972500.1)


There you good to go.................................................

Thursday, 26 November 2015

REDO RESIZE ON RAC




PRECHECK

**********


Check the size of present REDO
SELECT a.group#, a.member, b.bytes FROM v$logfile a, v$log b WHERE a.group# = b.group#;
SQL> set lines 132
SQL> set trims on
SQL> select * from v$log;


SQL> col member format a35
SQL> select * from v$logfile;

Check for the recommended size by running any of the below queries providing peak hour on your environment.
SELECT
(SELECT ROUND (AVG (BYTES) / 1024 / 1024, 2) FROM V$LOG) AS "Redo size (MB)", ROUND ( (20 / AVERAGE_PERIOD) * (SELECT AVG (BYTES) FROM V$LOG) / 1024 / 1024, 2) AS "Recommended Size (MB)" FROM (SELECT AVG ( (NEXT_TIME - FIRST_TIME) * 24 * 60) AS AVERAGE_PERIOD FROM V$ARCHIVED_LOG WHERE FIRST_TIME > SYSDATE - 3 AND TO_CHAR (FIRST_TIME, 'HH24:MI') BETWEEN '16:00' AND '17:00');
SELECT
(SELECT ROUND(AVG(BYTES) / 1024 / 1024, 2) FROM V$LOG) AS "Redo size (MB)",
ROUND((20 / AVERAGE_PERIOD) * (SELECT AVG(BYTES)
FROM V$LOG) / 1024 / 1024, 2) AS "Recommended Size (MB)"
FROM (SELECT AVG((NEXT_TIME - FIRST_TIME) * 24 * 60) AS AVERAGE_PERIOD
FROM V$ARCHIVED_LOG
WHERE FIRST_TIME > SYSDATE - 3
AND TO_CHAR(FIRST_TIME, 'HH24:MI') BETWEEN
&START_OF_PEAK_HOURS AND &END_OF_PEAK_HOURS);

SQL> select group#,thread#,members,status from v$log;
    GROUP#    THREAD#    MEMBERS STATUS
---------- ---------- ---------- ----------------
         1          1          2 INACTIVE
         2          1          2 CURRENT
         3          2          2 CURRENT
         4          2          2 INACTIVE
         5          3          2 ACTIVE
         6          3          2 CURRENT

Check every time for the status of group you’re going to drop.
Note:
To drop the group the status should be INACTIVE, if it’s no then switch the log file to make it forcibly inactive.

SQL> alter system switch logfile;

Continue this until the group you want to drop comes to INACTIVE state.

EXECUTION


**********

If your each instance has only two groups then create another temporary group.

In RAC, each logfile is associated with thread# each instance can only use one thread,You need a minimal of two group for each thread#.

ALTER DATABASE ADD LOGFILE THREAD 1 GROUP 8 ('+ DISKGROUP_NAME ') SIZE 100M;

When the status is inactive.

Drop the logfile
*************
SQL>  alter database drop logfile group 1;

To remove the file from asm disks (if it is not deleted automatically).

$ export ORACLE_SID=+ASM1
$ sqlplus / as sysdba
 
SQL>  ALTER DISKGROUP DISKGROUP_NAME DROP FILE '+DISKGROUP_NAME/PATH/group_1.XXXXX';


ADD the logfile with your desired size
*******************************
SQL>  ALTER DATABASE ADD LOGFILE THREAD 1 GROUP 1 ('+ DISKGROUP_NAME ','+ DISKGROUP_NAME ') SIZE 500M;

After all done just drop the temporary group

Drop the logfile
*************
SQL>  alter database drop logfile group 8;



Repeat the above steps for the entire instances log file on RAC.


POST CHECK


***********


Check the size of REDO.
SQL> SELECT a.group#, a.member, b.bytes FROM v$logfile a, v$log b WHERE a.group# = b.group#;

Check the status

SQL> select group#,thread#,members,status from v$log;
SQL> set lines 132
SQL> set trims on
SQL> select * from v$log;


SQL> col member format a35
SQL> select * from v$logfile;




There you good to go.................................................

Thursday, 5 November 2015

STATSPACK


 STATSPACK



                         It's Easy with AJEET,


In this Section I am going to provide the steps how to configure stats pack and how to generate stats pack report in oracle.

Stats pack is a earlier version of AWR, which is used for getting details of processes going internally in oracle database and can be used for performance tuning.



Installation of  STATSPACK  needs the following steps:

·    Creating the perfstat tablespace
·    Creating the perfstat user(automatically created)
·    Creating the tables(automatically created)
·    Installing the packages
·    Collecting data

·    Scheduling data collection snapshots with dbms_job

Create tablespace
create tablespace statspack_data datafile '/data/oracle/database/11gR2/oradata/scratch/statspack_data01.dbf' size 2G autoextend on maxsize 5G extent management local uniform size 1M  segment space management auto;

(Note: only tablespace should be created not the user as user perfstat will be created automatically when we run spcreate.sql)


CONFIGURING THE STATSPACK PACKAGE

1.      Conn as sysdba
2.      Run the SPCREATE.SQL file
              SQL> @?/rdbms/admin/spcreate
Enter password: give u r password for  the user perfstat
            Enter default tablespace: statspack_data
            Enter temporary tablespace:temp
3.      If any error occurred  then check the following log files
ORACLE_HOME/bin/spcusr.lis
            ORACLE_HOME/bin/spctab.lis
            ORACLE_HOME/bin/spcpkg.lis

  1. Conn as sysdba and make timed statistic to true dynamically
              alter system set TIMED_STATISTICS=TRUE; 

Collecting data
SQL> CONNECT perfstat/log           (The perfstat user will be created automaticaly when we run spcreate.sql)
            SQL> EXECUTE statspack.snap;
            PL/SQL procedure successfully completed.



Scheduling data collection snapshots with dbms_job
Schedule a snapshot to be run on this instance every hour, on the hour
(Note: - Run any one of the below, don’t’ run both or don’t’ run twice it creates the snap how many times  you run this .sql file or the script)
Conn as sysdba
SQL>@?/rdbms/admin/spatuo.sql
(OR)
variable jobno number;
variable instno number;
BEGIN
  SELECT instance_number INTO :instno FROM v$instance;
  DBMS_JOB.SUBMIT(:jobno, 'statspack.snap;', TRUNC(sysdate+1/24,'HH'), 'TRUNC(SYSDATE+1/24,''HH'')', TRUE, :instno);
  COMMIT;
END;
/
To check that the job is scheduled in dbjob
SQL>select * from dba_jobs;

(The above configuration must be done only once don’t repeat the above process at the next time, from next time only execute the below statement i.e., run only the spreport.sql)
Generate the stats-pack
(This is to Generate the report from the already generated snaps)
            as a perfstat user
SQL> @?/rdbms/admin/spreport
            The SPREPSQL.SQL report prompts you for the following:
                                    •           Beginning snapshot ID
                                    •           Ending snapshot ID
                                    •           Name of the report text file to be created


To purge the data of stats-pack
Important Note
Note that purging may require the use of a large rollback segment, as all data relating each snapshot to be purged will be deleted. You can get around the issue by issuing the alter session set rollback segment command before running sppurge.sql. The example below shows a sample execution of this script:

SQL> connect perfstat/perfstat
Connected.

SQL> set transaction use rollback segment big_rbs;
Session altered.

SQL> @$ORACLE_HOME/rdbms/admin/sppurge
 
Manual:
Use these two scripts run either sptrunc.sql (to truncate tables of perfstat user) or sppurge.sql (to delete rows from tables of perfstat user)
           
To truncate use this command:
SQL> conn perfstat/log
SQL> @?/rdbms/admin/sptrunc.sql    
 (or)  
To purge use this command:
SQL> @?/rdbms/admin/sppurge
 (We can use this command like “delete from stats$snapshot where snap_id < 10000;”)

Automatic:
Add the following parameters in the sppuge.sql (/rdbms/admin/sppurge.sql) to purge the snaps older than 15 days.
column min_snap_id new_val LoSnapId
column max_snap_id new_val HiSnapId
select nvl(min(s.snap_id), 0) min_snap_id, nvl(max(s.snap_id), 0) max_snap_id
  from perfstat.stats$snapshot s
     , perfstat.stats$database_instance di
                          where s.dbid              = :dbid
                          and di.dbid             = :dbid
                          and s.instance_number   = :inst_num
                          and di.instance_number  = :inst_num
                          and di.startup_time     = s.startup_time
                          and s.snap_time < sysdate-14;

Add this parameter in sppurge.sql or create another file and schedule it in cronjobs. Add start and end of file.


Manually removing STATSPACK snapshots
 
Fortunately, STATSPACK uses foreign-key referential integrity constraints with the ON CASCADE DELETE option. This means that all information for a given snapshot can be deleted by deleting the corresponding stats$snapshot record. For example, suppose that you wanted to delete all snapshots for 2002, and these were snapshots that have a snap_id of less than 10,000. The following DELETE would remove all of these snapshots, and all subordinate detail rows:
 

SQL > delete from stats$snapshot where snap_id < 10000;
28923563 rows deleted.
 
Of course, you can selectively delete rows from STATSPACK. For example, you might want to keep all of the system statistics and delete all of the SQL statements that were more than six months old. In this case, you could selectively remove the rows from stats$sql_summary:

SQL > delete from stats$sql_summary where snap_time < sysdate - 180;
2888363 rows deleted.
 
Now let's take a look at some handy shell scripts that will make your use of STATSPACK easier.
 
Removing ranges of snapshots

The STATSPACK utility provides a batch mode purging function. To run the sppurge.sql script in batch mode, you must assign SQL*Plus variables to identify the low snapshot and the high snapshot for purging.

#!/bin/ksh

# First, we must set the environment . . . .
ORACLE_SID=$1
export ORACLE_SID
ORACLE_HOME=`cat /etc/oratab|grep ^$ORACLE_SID:|cut -f2 -d':'`
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH

$ORACLE_HOME/bin/sqlplus system/manager<<!

select * from v\$database;
connect perfstat/perfstat
define losnapid=$2
define hisnapid=$3
@sppurge
exit
!


If db_job fails than perform the following steps

If the job fails to run and after checking alert log if we get the error like below
--------------------------------------------------------------------------------------
Mon May 21 06:06:08 2012
Errors in file /XXXX/bdump/PROd_j000_3976.trc:
ORA-12012: error on auto execute of job 23
ORA-00001: unique constraint (PERFSTAT.STATS$SQL_SUMMARY_PK) violated
ORA-06512: at "PERFSTAT.STATSPACK", line 1361
ORA-06512: at "PERFSTAT.STATSPACK", line 2471
ORA-06512: at "PERFSTAT.STATSPACK", line 91
ORA-06512: at line 1

--------------------------------------------------------------------------------------
As Job is scheduled through DBMS_JOBS package so it will run 16 times till it will get broken.
(Note: - please check the job no properly before performing the following operation please conform the job no and then you proceeded)

1.     Check the status of the Job from dba_jobs.

select JOB,LOG_USER,PRIV_USER,SCHEMA_USER,LAST_DATE,LAST_SEC,NEXT_DATE,NEXT_SEC,TOTAL_TIME,BROKEN,WHAT,FAILURES from dba_jobs where JOB=41;

The output will give all details about the job 23.(job number from the error)  Please be sure it is stats-pack job only.

(Note: - Once you get the error immediately make the job broken as below. If you don't make it broken it will run 16 times and fail every time. We will get the error in the alert log 16 times.)
2.     Making Job broken manually

Before making the job broken be sure job number is correct.


sqlplus perfstat/<Passwd>

SQL> exec dbms_job.broken(41,TRUE);

PL/SQL procedure successfully completed.

Now the job got broken it won't execute again.
Check again the status

SQL> select JOB,LOG_USER,PRIV_USER,SCHEMA_USER,LAST_DATE,LAST_SEC,NEXT_DATE,NEXT_SEC,TOTAL_TIME,BROKEN,WHAT,FAILURES from dba_jobs where JOB=23;
(After Job got broken it will not execute at all till we make it run once and then automatically it will schedule itself. But for running again we need to wait for some time. )
3.     Now wait for some 2 to 3 hours (Approx. time. We don't know exact   time) and then execute the job again. As this is the issue so till information is not cleared from the v$ tables the job can't run again. If you try it will fail again.

Note:- if you run the job and you got issue again then the broken status of the job will change to "N" and you need to again make it broken again so that it won't run 16 times with same problem.

E.g,
Execute the Job again

sqlplus perfstat/<Passwd>

SQL> exec DBMS_JOB.RUN(41);
[[[[
PL/SQL procedure successfully completed.

Check the Job status again. It will show that it is not broken and is executed the time you run the command and after 30 Minutes it will execute again. please be sure it is running fine.

4.     Again check that the job is running.

SQL> select * from dba_jobs where job=41;


5.     To remove the job

SELECT * FROM dba_jobs_running;

SELECT JOB FROM DBA_JOBS WHERE JOB=21;

BEGIN
EXECUTE DBMS_JOB.REMOVE(21);
COMMIT;
END;

SELECT JOB FROM DBA_JOBS WHERE JOB=21;



                       That's It 


                                                             There you good to go.................................................



Please subscribe for latest updates.

RemoteHostExecutor.pl The file access permissions while patching

Hi, In this article, I am going to share one the issue which we usually face while patching. Here our DB and Grid home are 12.1.0.2, an...