Saturday, May 27, 2006

Patching from 10.2.0.1 to 10.2.0.2

Today’s task is to patch from .1 to .2 on our SunOS(10) E25K, 160 gbs of ram, 20 dual core CPU’s and 18 terabytes of useable RAID 5 disks.

I would highly recommend that you do a metalink (http://metalink.oracle.com) search for: <10.2.0.2 Patch Set - Known Issues> before you get to far into this. Consider, how this search id’s Note 359415.1. This note contains important additional information for the SunOS I am dealing with. It lets me know that there is an additional OUI (Oracle Universal Installer) patch that must be installed post 10.2.0.2 and pre any other patchs (i.e. 1offs, .3, etc.). This additional patch is to correct bug 5117016. This bug causes the OUI to install the libserver10.a library into $ORACLE_HOME/rdbms/lib
instead of into $ORACLE_HOME/lib. This in-turn can cause subsequent problems when applying patches on top of 10.2.0.2. Therefore this is a Mandatory Patch and must be applied immediately after completing the installation of 10.2.0.2

I downloaded the patch set from metalink (p4547817_10202_SOLARIS64.zip) aprox. 788 mbs in size and unzip’ed it using Sun’s unzip feature.

I pointed my web browser to the README.html file that came with the patch set.

Validated that the cold backup (oracle was down during the backup) completed successfully.

I made sure that the shared_pool_size and java_pool_size were at least 150M or larger in the init.ora file.

I then shutdown the base: sqlplus “/ as sysdba” from the oracle Unix user and then by issuing a . I also shutdown the lsnr. via command.

Next I made of copy of the ../Disk1/response/patchset.rsp file in the ../Disk1/ directory to install the patch set noninteractively. And of course I edited the variables that required changing in the patchset.rsp file.
 A couple of “got-u’s” to watch for:
 One: ensure that the ORACLE_HOME and ORACLE_SID values are set in your environment.
 In the patchset.rsp template ensure you set the oracle home to your current oracle home value. For example: ORACLE_HOME="/u01/app/oracle/product/10.2.0"
 Ensure that you set the oracle home name value as follows: ORACLE_HOME_NAME="OraDb10g_home1".

Then from the ../Disk1/ directory I executed the following on the command line:
./runInstaller -silent –responseFile ../Disk1/patchset.rsp

Then executed the $ORACLE_HOME/roo.sh.

Then since this is a single-instance database I logged into sqlplus as sysdba and did a STARTUP MOUNT.

Then I entered the following SQL*PLUS commands:
1. SQL> STARTUP UPGRADE
2. SQL> SPOOL patch.log
3. SQL> start $ORACLE_HOME/rdbms/admin/catupgrd.sql
4. SQL> SPOOL OFF
5. SQL> SHUTDOWN IMMEDIATE
6. SQL> STARTUP
7. SQL> start $ORACLE_HOME/rdbms/admin/utlrp.sql

The catupgrd.sql script reexectues your catalog and catproc sql scripts. The utlrp.sql script recompiles all PL/SQL invalid packages now instead of when the packages are accessed for the first time.

Now I can restart the lsnr and turn the user loose again; only now on a 10.2.0.2 instance!

Monday, May 15, 2006

GUI, Not Really (Scripts)

I am not a strong proponent for GUI’s. I am not opposed to them exactly; I just think you should know how to operate at the command-line level; then you can use a GUI if you so choose. With that typed; here are some of the scripts I use regularly instead of GUI’s:

Remember the old TOP tool in OEM? Basically this script produces similar output for the most part given you session information.

"top.sql" 93 lines, 2369 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 5/16/1999 --
-- Purpose: Display Oracle session information. --
-- Example: sqlplus / @top.sql --
-- Disclaimer: Use is at your sole risk. All info is provided --
-- "as -is", without any warranty, whether express --
-- or implied, of its accuracy, completeness. --
-----------------------------------------------------------------

create table toptab
as
select sid,sum(value) as memory
from v$sesstat
group by sid
/
set pagesize 132 linesize 2048 trimspool on recsep off space 2 wrap off
column username format a10
column sid format 999999
column serial# format 9999999
column osuser format a10
column memory format 999999999999
column command format a12
column status format a8
column machine format a15
column program format a25
spool top.log
select username
,v$session.sid
,serial#
,osuser
,memory
,status
,decode(command ,1, 'Create Table'
,2, 'Insert'
,3, 'Select'
,4, 'Create Cluster'
,5, 'Alter Cluster'
,6, 'Update'
,7, 'Delete'
,8, 'Drop'
,9, 'Create Index'
,10, 'Drop Index'
,11, 'Alter Index'
,12, 'Drop Table'
,13, '---'
,14, '---'
,15, 'Alter Table'
,16, '---'
,17, 'Grant'
,18, 'Revoke'
,19, 'Create Synonym'
,20, 'Drop Synonym'
,21, 'Create View'
,22, 'Drop View'
,23, '---'
,24, '---'
,25, '---'
,26, 'Lock Table'
,27, 'No Operation'
,28, 'Rename'
,29, 'Comment'
,30, 'Audit'
,31, 'Noaudit'
,32, 'Create External Database'
,33, 'Drop External Database'
,34, 'Create Database'
,35, 'Alter Database'
,36, 'Create Rollback Segment'
,37, 'Alter Rollback Segment'
,38, 'Drop Rollback Segment'
,39, 'Create Tablespace'
,40, 'Ater Tablespace'
,41, 'Drop Tablespace'
,42, 'Alter Session'
,43, 'Alter User'
,44, 'Commit'
,45, 'Rollback'
,46, 'Savepoint'
, 'Unknown') as command
,program
,machine
from v$session, toptab
where v$session.sid = toptab.sid
and v$session.sid is not null
order by status, memory desc, username, osuser
/
spool off
set pagesize 0 feedback off
select ' '
from dual
/
select ' '
from dual
/
select ' NOTE: Alter System Kill Session''SID,Serial#'';' from dual
/
drop table toptab;
set pagesize 23 linesize 80 trimspool off space 2 feedback on wrap on
clear columns


This little script allows you to quickly display all of the objects in tablespace and their size:

"segment.sql" 20 lines, 867 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 2/10/2006 --
-- Purpose: Display all segments for a given tablespace. --
-- Parameter: Tablespace Name (Upper, Lower, Mixed Case OK --
-- Example: sqlplus / @segment.sql tablespace_namne --
-- Disclaimer: Use is at your sole risk. All info is provided --
-- "as -is", without any warranty, whether express --
-- or implied, of its accuracy, completeness. --
-----------------------------------------------------------------

set numf 999,999,999,999,999
column segment_name format a32

select segment_name,sum(bytes)
from dba_segments
where tablespace_name=upper('&tspacename')
group by segment_name
order by sum(bytes) asc
/

This script will allow you to do a string search of the sql area.

"tsql1.sql" 72 lines, 2795 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 1/12/2006 --
-- Purpose: Display information about sql currently in the --
-- sql area. --
-- Parameter: String (i.e. insert) Param. is not case senstive --
-- Example: sqlplus / @tsql1.sql string --
-- Disclaimer: Use is at your sole risk. All info is provided --
-- "as -is", without any warranty, whether express --
-- or implied, of its accuracy, completeness. --
-----------------------------------------------------------------


set linesize 132 pagesize 132
column username format a8
column osuser format a6
column command format a6
column sid format 9999
column serial# format 99999
select a.username,a.osuser,a.sid,a.SERIAL#,substr(sql_text,1,85)
,decode(command ,1, 'CrTab'
,2, 'Ins'
,3, 'Sel'
,4, 'CrClus'
,5, 'AltClus'
,6, 'Up'
,7, 'Del'
,8, 'Drop'
,9, 'CrInd'
,10, 'DrInd'
,11, 'AltInd'
,12, 'DrTab'
,13, '---'
,14, '---'
,15, 'AltTab'
,16, '---'
,17, 'Grant'
,18, 'Revoke'
,19, 'CrSyn'
,20, 'DrSyn'
,21, 'CrVi'
,22, 'DrVi'
,23, '---'
,24, '---'
,25, '---'
,26, 'LkTab'
,27, 'NoOper'
,28, 'Rena'
,29, 'Com'
,30, 'Aud'
,31, 'Noaud'
,32, 'CrExtDb'
,33, 'DrExtDb'
,34, 'CrDb'
,35, 'AltDb'
,36, 'CrRolbSeg'
,37, 'AltRolbSeg'
,38, 'DrRolbSeg'
,39, 'CrTsp'
,40, 'AltTsp'
,41, 'DrTsp'
,42, 'AltSes'
,43, 'AltUsr'
,44, 'Commit'
,45, 'Rolbk'
,46, 'Savpo'
, 'Unknown') as command
from v$session a,v$sqlarea b
where upper(b.sql_text) like upper('%&searchstring.%')
and b.address = a.sql_address
order by a.username,a.osuser,b.sql_text,a.sid,a.serial#
/


This script will display detail information about all the tablespaces:

"tsspace.sql" 35 lines, 1522 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 10/06/2004 --
-- Purpose: Display usage information about tablespaces. --
-- Example: sqlplus / @tsspace.sql --
-- Disclaimer: Use is at your sole risk. All info is provided --
-- "as -is", without any warranty, whether express --
-- or implied, of its accuracy, completeness. --
-----------------------------------------------------------------


clear columns
clear breaks
set linesize 132 trimspool on pagesize 66

column total_bytes format 999,999,999,999,999
column bytes_free format 999,999,999,999,999
column bytes_used format 999,999,999,999,999
column largest_free format 999,999,999,999,999
column bytes format 999,999,999,999,999
column tablespace_name format a28

spool tsspace.log

select a.TABLESPACE_NAME,a.BYTES total_bytes,a.BYTES - b.BYTES bytes_used,b.BYTES bytes_free
,b.largest largest_free,round(((a.BYTES-b.BYTES)/a.BYTES)*100,2) percent_used
from (select TABLESPACE_NAME,sum(BYTES) BYTES
from dba_data_files
group by TABLESPACE_NAME) a, (select TABLESPACE_NAME,sum(BYTES) BYTES,max(BYTES) largest
from dba_free_space
group by TABLESPACE_NAME) b
where a.TABLESPACE_NAME=b.TABLESPACE_NAME
order by ((a.BYTES-b.BYTES)/a.BYTES) desc;

spool off


This script will figure out and display how large a table can be in MB’s for a given tablespace based on the extent size feed into the script:

"./nexte.sql" 12 lines, 678 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 4/28/2005 --
-- Purpose: Used to figure out the largest table that can be --
-- created in a tablespace based on an extent size --
-- Parameters: A: Extent_Size (in MB's) B: Tablespace_Name --
-- Example: sqlplus / @nexte.sql 1 tablespace_name --
-----------------------------------------------------------------

select ltrim(to_char(sum(floor((bytes/1048576)/&&amp;amp;1))*&&1,'999,999,999,999')) as TotMBs
from dba_free_space
where tablespace_name = upper


Here is a nice little script for displaying information about the number of commits, logons, etc.

"tinfo.sql" 11 lines, 520 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 9/15/2004 --
-- Purpose: To display info. such as no. of transactions, --
-- commits, aborts, logons current, cumulative, etc. --
-- Example: sqlplus / @tinfo.sql --
-----------------------------------------------------------------

select value,name
from v$sysstat
where statistic# <7;>
"notdparm.sql" 26 lines, 856 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 9/15/2004 --
-- Purpose: To display non-default init. parm's. --
-- Example: sqlplus / @notdparm.sql --
-----------------------------------------------------------------

spool notdpar.lst
set pagesize 999

ttitle center 'Not Default Init. Parameters' skip 1 -
center '----------------------------' skip 2;
col num format 9999 head 'Parameters'
col name format a45 head 'Name' wrap
col type format 9999 head 'Type'
col value format a45 wrap head 'Value'
col isdefault format a9 head 'Default?'

select name,value
from v$parameter
where isdefault = 'FALSE'
order by name;

ttitle off
spool off

Here is a great little script for producing the ddl required to create an object. The 3 variables must be passed in, in upper case for this to work.

"./getddl.sql" 15 lines, 677 characters
-----------------------------------------------------------------
-- Author: Sam Fulkerson --
-- Date : 8/17/2005 --
-- Purpose: Used to create the ddl for object. --
-- Parameters: A: Object Type (i.e. Table) B: Object Name --
-- C: Object owner (variables must be in upper case --
-- Example: sqlplus / @getddl.sql table table_name owner_name --
-----------------------------------------------------------------

set heading off echo off pagesize 999 long 90000

spool getddl_&&amp;amp;amp;amp;amp;amp;amp;3.&&2.sql
select dbms_metadata.get_ddl('&&amp;amp;amp;amp;amp;amp;amp;1','&&2','&&3')
from dual;
spool off

This script will provide info. on the temporary tablespaces:


"././tmp1.sql" 12 lines, 631 characters------------------------------------------------------------------- Author: Sam Fulkerson ---- Date : 4/26/2006 ---- Purpose: To provide info. on the temporary tablespace. ---- Example: sqlplus / @tmp1.sql -------------------------------------------------------------------
set numf 999,999,999,999,999 linesize 132select tablespace_name, SUM(bytes_used) as Used, SUM(bytes_free) as Free, sum(bytes_used + bytes_free) as Totalfrom v$temp_space_headergroup by tablespace_nameorder by tablespace_name;


This script will display info. about who is using temp:


"././tmp2.sql" 23 lines, 963 characters------------------------------------------------------------------- Author: Sam Fulkerson ---- Date : 4/26/2006 ---- Purpose: To provide info. on who is using temporary ---- tablespace. ---- Parameters: Username-- Example: sqlplus / @tmp2.sql -------------------------------------------------------------------
column tablespace format a8
select a.username, b."USER", b.tablespace, b.contents, b.extents, b.blocksfrom sys.v_$session a, sys.v_$sort_usage bwhere a.saddr = b.session_addr;
select a.osuser, a.process, a.username, a.serial#, sum(b.blocks)*c.value/1024 sort_sizefrom sys.v_$session a, sys.v_$sort_usage b, sys.v_$parameter cwhere a.saddr = b.session_addrand c.name = 'db_block_size'and a.osuser like '&&1'group by a.osuser, a.process, a.username, a.serial#, c.value;

CRON (crontab info.)

From a Unix prompt type the following:

crontab –l (to list out the contents of the crontab.)
crontab –e (to edit the contents of the crontab.)
crontab –v (to verify the crontab.)
crontab –r (to remove the contents of the crontab.) Careful, as an ‘e’ and ‘r’ are next to each other on the keyboard.



Here is a header I put in all my crontab’s:

# Parameter 1: Minute <0-59>
# Parameter 2: Hour <0-23>
# Parameter 3: Day of the Month <1-31>
# Parameter 4: Month <1-12>
# Parameter 5: Day of the Week <0-6 sunday="0">
# Parameter 6: Command
# Place a comma between multiple values
# Place a hyphen to indicate a range
# Place an asterisk to indicate all possible values.
#############################################

Some AIX Stuff

To find out what maintenance level the OS is at type:
oslevel –r

FIND (Unix Command)

The “find” command is a very powerful and useful tool. Here are just a few examples to wet your taste buds with:

The below command will give you a list of all files over a gig in size. Just change the '/u01/' to look at what ever mount point is appropriate.

find /u01/ -size +1048576000c -print

The output can be redirected from standard output to a file by appending the following to the end of the command:

>/directory/path/file_name.txt

If you want to remove all files in a directory and its sub-directories, move to the starting directory and execute the following command:

cd /u01/directory_name/
find . -name '*.txt -mtime +32 -exec rm -f {} ";"

This will remove all *.txt files 32 days or older. A ‘oops’ to watch out for, is that some OS’s such as AIX tend to not always update the timestamp on a file when it is moved into another directory such as one being used for archiving. For example; if you just moved a file into a directory you have identified for archival purposes and the timestamp is say, 64 days old on the file in question and it is not re-stamped during the “mv” command and you run this “find” example, that file will be removed. This would be a bad thing if your backup routine had not executed on that file yet. Just a little something to keep in mind.

Creating a primary key with a parallel degree.

Step 1: (Create a primary key, disabled.)
alter table table_name
add (constraint pk_key_name
primary key (field_name))
disable primary key;


Step 2: (Create an unique index with the same name and columns as the primary key.)
create unique index pk_key_name on table_name(field_name)
tablespace tablespace_name
storage (initial ?M next ?M pctincrease 0)
parallel (degree ?)
nologging;

Step 3: (Now enable the primary key.)
alter table table_name enable primary key;

What do you want to do?

Let’s bring this question into more focus. I am of the opinion that simpler is better. “The more you over tic the plumbing, the easier it is to stop it up.” So from a high level:

If you want Replication, you want Streams.
If you want a Stand-By Database, you want Data Guard.
If you want Fail-Over, you want RAC.