Tag Archives: Add new tag

OPatch Oracle database still running: Code 73

Oracle’s OPatch utility is used for applying interim CPU patches to maintain the security of your RDBMS. In this article we will cover the error which would be received when you attempt to apply an Oracle patch to a currently executing Oracle database.

1. Logon to your Oracle database server as the Oracle software owner.

2. Change directories to the location of your CPU patch and unzip the file.

unzip p9119226_10204_.zip

3. Change directories into your unzipped patch directory which is named with the CPU number you are applying.

cd 9119226
OPatch apply

conflicts against Oracle Home…
OPatch continues with these patches: 7155248 7155249 7155250 7155251
7155252 7155253 7155254 7197583 7375611 7375613 7375617 7609057 7609058
8309592 8309632 8309642 8568395 8568397 8568398 8568402 8568404 8568405
8836667 8836671 8836675 8836677 8836678 8836681 8836683 8836684 8836686
9119226 9173244 9173248 9173253

Do you want to proceed? [y|n]
y
User Responded with: Y

Running prerequisite checks…
Prerequisite check “CheckActiveFilesAndExecutables” failed.
The details are:

Following executables are active :
/u01/prism/oracle/product/10.2.0/db_1/bin/oracle
UtilSession failed: Prerequisite check “CheckActiveFilesAndExecutables” failed.

OPatch failed with error code 73
mylinux :>

4. As seen above the OPatch utility errored out with code 73 and references the Prerequisite check “CheckActiveFilesAndExecutables”. This error normally occurs when the Oracle database is still up and running, so we check it below with the command ps:

mylinux :> ps -ef|grep smon
cimsora 26981 1 0 02:12 ? 00:00:00 ora_smon_prism
cimsora 4326 11581 0 02:34 pts/1 00:00:00 grep smon

5. As seen above the database is in fact up, so logon as sysdba and shut it down.

mylinux :> sqlplus ‘/ as sysdba’

SQL*Plus: Release 10.2.0.4.0 – Production on Sun Feb 2802:38:36 2010

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit

6. Once the database is shutdown we can re-execute our OPatch install.

Larry J Catt, OCP9i, 10g
oracle@allcompute.com
www.allcompute.com

Setup of Oracle STATSPACK Diagnostics tool

Oracle STATSPACK is a tool that allows you to analyze the performance of your Oracle RDBMS over a specific period of time. Normally the analysis of how your database is performing should be based over a period of the highest usage, but over a length of time that would avoid short term peaks to skew your results. STATSPACK has been in use since Oracle 8i with continual enhancements with every new version release. In this article, we will show how to install and prepare your database for the use of STATSPACK.

Also see:
Taking STATSPACK snap shots and producing reports.
Setup of STATSPACK scheduled jobs.

1. Logon to Oracle as sys dba

MyLinux:mydb:/mydb:>sqlplus ‘/ as sysdba’

SQL*Plus: Release 10.2.0.4.0 – Production on Mon Aug 3 09:03:30 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

2. The STATSPACK tool is owned by the user PERFSTAT and specific storage should be created to avoid interference with your database. In this step will create specific storage for PERFSTAT user.

SQL> create tablespace perfstat datafile ‘/mydb/ordata/perfstat01.dbf’ size 2096m;

Tablespace created.

SQL> alter tablespace perfstat add datafile ‘/mydb/ordata/perfstat02.dbf’ size 2096m;

Tablespace altered.

3. The user PERFSTAT and all components of the STATSPACK tool are created with the ORACLE provided script SPCREATE.SQL. Execute the script $ORACLE_HOME/rdbms/admin/spcreate.sql to create the perfstat user and data structures.

SQL> @?/rdbms/admin/spcreate.sql

4. The SPCREATE.SQL script accept three parameters before execution: Password; Default Tablespace; and Temp Tablespace. Enter the following when prompted:
PERFSTAT Password
Default Tablespace
Temp Tablespace

5. After execution has occurred, check the following list files to determine that no errors occurred.

spcusr.lis – Creates the perfstat user account.
spctab.lis – Creates all data structure under the perfstat user account.
spcpkg.lis – Creates the perfstat packages.

6. This completes the build of Oracle’s STATSPACK diagnostic tool in your database.

Larry J Catt, OCP 9i, 10g
oracle@allcompute.com
www.allcompute.com

Recreate Oracle User account.

Since the release of Oracle 10g and 9i, most would think that the need for scripts to recreate individual database components are unnecessary and they would be correct if you are already at Oracle 9i or 10g. Oracle 9i provides the user of the DBMS_METADATA package, which give the DBA the ability to generate the DDL for most any Oracle structure. Oracle 10g has enhanced the abilities of DBMS_METADATA and given the add value of ORACLE expdmp and impdmp, which do not require the existence of such objects as a user to transport data between databases. However, there still exist tons of Oracle 8i and earlier versions, which do not contain either of the abilities above and from which we still have to recreate individual oracle objects. This article is part of a series that covers the recreation of Oracle objects by producing the DDL from which to recreate them.

In this article we will cover the recreate of an Oracle User account in its most simple form. NOTE: We will not cover the recreation of a user defined profile or other objects an oracle user account may depend on. For that information, please see my related article Recreation of User defined Oracle Profiles.

The below script regenerates a user account:

set serveroutput on
spool c:\oradata\create_user_account.sql

declare

curr varchar2(30):= ‘TEST_USER’;
v_ext varchar2(3);

begin

for user in(select * from dba_users where username = curr)
loop

dbms_output.put_line(‘create tablespace ‘||user.default_tablespace);

for dat_file in(select * from dba_data_files where
tablespace_name=user.default_tablespace)
loop

if dat_file.autoextensible=’YES’
then
v_ext:=’ON’;
else
v_ext:=’OFF’;
end if;

dbms_output.put_line(‘datafile ‘||””||dat_file.file_name||””||’ size
‘||floor(dat_file.bytes/1024/1024)||’m’);
dbms_output.put_line(‘autoextend ‘||v_ext);
dbms_output.put_line(‘maxsize ‘||floor(dat_file.maxbytes/1024/1024)||’m’);
end loop;
dbms_output.put_line(‘/’);

dbms_output.put_line(‘create user ‘||user.username||’ identified by
‘||user.username||’;’);

dbms_output.put_line(‘alter user ‘||user.username||’ default tablespace
‘||user.default_tablespace||’;’);

dbms_output.put_line(‘alter user ‘||user.username||’ temporary tablespace
‘||user.temporary_tablespace||’;’);

dbms_output.put_line(‘alter user ‘||user.username||’ profile
‘||user.profile||’;’);

if user.account_status<>’OPEN’
then
dbms_output.put_line(‘alter user ‘||user.username||’ account lock;’);
end if;

end loop;

for role in(select * from dba_role_privs where grantee=curr)
loop

if role.admin_option = ‘YES’
then
dbms_output.put_line(‘grant ‘||role.granted_role||’ to ‘||role.grantee||’ with
admin option’||’;’);
else
dbms_output.put_line(‘grant ‘||role.granted_role||’ to ‘||role.grantee||’;’);
end if;
end loop;

for sys_priv in(select * from dba_sys_privs where grantee=curr)
loop

if sys_priv.admin_option = ‘YES’
then
dbms_output.put_line(‘grant ‘||sys_priv.privilege||’ to ‘||sys_priv.grantee||’
with admin option’||’;’);
else
dbms_output.put_line(‘grant ‘||sys_priv.privilege||’ to
‘||sys_priv.grantee||’;’);
end if;
end loop;

for tab_priv in(select * from dba_tab_privs where grantee=curr)
loop

if tab_priv.grantable = ‘YES’
then
dbms_output.put_line(‘grant ‘||tab_priv.privilege||’ on
‘||tab_priv.owner||’.’||tab_priv.table_name||’ to ‘||tab_priv.grantee||’ with
grant option;’);
else
dbms_output.put_line(‘grant ‘||tab_priv.privilege||’ on
‘||tab_priv.owner||’.’||tab_priv.table_name||’ to ‘||tab_priv.grantee||’;’);
end if;

end loop;
end;
/

spool off

The output generated by above script to recreate the TEST_USER account is listed below.

MYDB >
MYDB > set serveroutput on
MYDB > spool c:\oradata\create_user_account.sql
MYDB >
MYDB >
MYDB > declare
2
3 curr varchar2(30):= ‘TEST_USER’;
4 v_ext varchar2(3);
5
6
7 begin
8
9
10 for user in(select * from dba_users where username = curr)
11 loop
12
13
14 dbms_output.put_line(‘create tablespace ‘||user.default_tablespace);
15
16 for dat_file in(select * from dba_data_files where tablespace_name=user.def
ault_tablespace)
17 loop
18
19 if dat_file.autoextensible=’YES’
20 then
21 v_ext:=’ON’;
22 else
23 v_ext:=’OFF’;
24 end if;
25
26
27 dbms_output.put_line(‘datafile ‘||””||dat_file.file_name||””||’ size ‘|
|floor(dat_file.bytes/1024/1024)||’m’);
28 dbms_output.put_line(‘autoextend ‘||v_ext);
29 dbms_output.put_line(‘maxsize ‘||floor(dat_file.maxbytes/1024/1024)||’m’);
30 end loop;
31 dbms_output.put_line(‘/’);
32
33 dbms_output.put_line(‘create user ‘||user.username||’ identified by ‘||user
.username||’;’);
34
35
36 dbms_output.put_line(‘alter user ‘||user.username||’ default tablespace ‘||
user.default_tablespace||’;’);
37
38 dbms_output.put_line(‘alter user ‘||user.username||’ temporary tablespace ‘
||user.temporary_tablespace||’;’);
39
40 dbms_output.put_line(‘alter user ‘||user.username||’ profile ‘||user.profil
e||’;’);
41
42 if user.account_status<>’OPEN’
43 then
44 dbms_output.put_line(‘alter user ‘||user.username||’ account lock;’);
45 end if;
46
47 end loop;
48
49
50 for role in(select * from dba_role_privs where grantee=curr)
51 loop
52
53
54 if role.admin_option = ‘YES’
55 then
56 dbms_output.put_line(‘grant ‘||role.granted_role||’ to ‘||role.grantee||’ w
ith admin option’||’;’);
57 else
58 dbms_output.put_line(‘grant ‘||role.granted_role||’ to ‘||role.grantee||’;’
);
59 end if;
60
61
62 end loop;
63
64 for sys_priv in(select * from dba_sys_privs where grantee=curr)
65 loop
66
67 if sys_priv.admin_option = ‘YES’
68 then
69 dbms_output.put_line(‘grant ‘||sys_priv.privilege||’ to ‘||sys_priv.grantee
||’ with admin option’||’;’);
70 else
71 dbms_output.put_line(‘grant ‘||sys_priv.privilege||’ to ‘||sys_priv.grantee
||’;’);
72 end if;
73
74 end loop;
75
76 for tab_priv in(select * from dba_tab_privs where grantee=curr)
77 loop
78
79 if tab_priv.grantable = ‘YES’
80 then
81 dbms_output.put_line(‘grant ‘||tab_priv.privilege||’ on ‘||tab_priv.owner||
‘.’||tab_priv.table_name||’ to ‘||tab_priv.grantee||’ with grant option;’);
82 else
83 dbms_output.put_line(‘grant ‘||tab_priv.privilege||’ on ‘||tab_priv.owner||
‘.’||tab_priv.table_name||’ to ‘||tab_priv.grantee||’;’);
84 end if;
85
86 end loop;
87 end;
88 /
create tablespace FOMIS_PROBLEM_TRACKING_BE2
datafile ‘C:\ORACLE\PRODUCT\10.1.0\ORADATA\MYDB\FOMIS_PROBLEM_TRACKING_BE2’
size 304m
autoextend ON
maxsize 4096m
/

create user TEST_USER identified by TEST_USER;
alter user TEST_USER default tablespace TEST_USER_T;
alter user TEST_USER temporary tablespace TEMP;
alter user TEST_USER profile DEFAULT;
grant CONNECT to TEST_USER;
grant CREATE JOB to TEST_USER;
grant CREATE TYPE to TEST_USER;
grant CREATE VIEW to TEST_USER;
grant CREATE TABLE to TEST_USER;
grant ALTER SESSION to TEST_USER;
grant CREATE CLUSTER to TEST_USER;
grant CREATE LIBRARY to TEST_USER;
grant CREATE SESSION to TEST_USER;
grant CREATE SYNONYM to TEST_USER;
grant CREATE TRIGGER to TEST_USER;
grant CREATE OPERATOR to TEST_USER;
grant CREATE SEQUENCE to TEST_USER;
grant CREATE DIMENSION to TEST_USER;
grant CREATE INDEXTYPE to TEST_USER;
grant CREATE PROCEDURE to TEST_USER;
grant CREATE ANY CONTEXT to TEST_USER;
grant CREATE DATABASE LINK to TEST_USER;
grant UNLIMITED TABLESPACE to TEST_USER;
grant CREATE MATERIALIZED VIEW to TEST_USER;
grant EXECUTE on SYS.DBMS_RLS to TEST_USER;
grant EXECUTE on CTXSYS.CTX_DDL to TEST_USER;
grant EXECUTE on CTXSYS.CTX_DOC to TEST_USER;

PL/SQL procedure successfully completed.

MYDB >
MYDB >

This completes the creation of SQL to regenerate a specific user account.

 

LARRY J. Catt, OCP 9i, 10g
oracle@allcompute.com
www.allcompute.com

UNIX CRON – Shell script errors with [10]: sqlplus: not found

In normal administration of an Oracle RDBMS on UNIX or LINUX operating systems, the DBA will be required to develop shell and SQL scripts to maintain his/her RDBMS. In fact, to be considered a mid to senior DBA you will need to be well versed in scripting at the OS layer. In this article we will review a common error which occurs in a shell script called by CRON due to a lack of properly set variables.

1. In a normal scenario, the DBA has developed a shell script which calls and executes a SQL script to perform a certain maintenance task. In testing, the DBA executes the script as the oracle software owner and the script performs perfectly. However, when placed in the OS CRON for execution, the following error occurs.

[10]: sqlplus: not found

2. The error occurs because the environmental variables are not being read. Thus, the OS does not know where to find the executable: sqlplus.

3. The solution is to update your shell script and hard code the directory structure for the command sqlplus. An example would be if sqlplus is located in the following path /u01/opt/app/oracle/bin then perform the following:

Replace:

sqlplus

With:

/u01/opt/app/oracle/bin/sqlplus

This completes resolving the error message [10]: sqlplus: not found in a shell script called through CRON.

Larry J. Catt, OCP 9i, 10g
oracle@allcompute.com
www.allcompute.com