Friday, September 3, 2010

ORA-29760: instance_number parameter not specified

Problem Description
Using sql*plus whenever I do startup it fails with ORA-29760 like below.

SQL> startup nomount
ORA-29760: instance_number parameter not specified

Similarly, whenever I start my database using srvctl it returns same error like following.

$ srvctl start database -d didar
PRKP-1001 : Error starting instance didar1 on node node1
CRS-0215: Could not start resource ora.node1.didar1.inst.

If you look for imon_didar.log file inside $ORACLE_HOME/log/node1/racg there is showed that startup has failed with 'ORA-29760: instance_number parameter not specified'.

Cause of the Problem
Cause 01:
The database and instance names have been defined in lowercase in the cluster registry (OCR). That's why "srvctl start database" is being passed the argument 'test'.

However, if you look for spfile or pfile you will see that the instance names have been defined in uppercase.

DIDAR1.instance_number=1
DIDAR2.instance_number=2

Cause 02:
You are using sql*plus and within your pfile/spfile it is set proper name that is in lower case. But your environmental variable value of ORACLE_SID contains uppercase database SID "DIDAR". In such case, ORA-29760 will also be reported whenever you try to startup your database.

Solution of the Problem
srvctl is case sensitive. So you need to ensure that the instance and database definitions set in the spfile/pfile are the same case as those in the OCR and as are used in the srvctl commands.
Before going into solution be sure that your ORACLE_SID reflects the correct case so that the instance can be accessed using SQL*Plus. If your ORACLE_SID environmental variable is set to uppercase but inside pfile/spfile it is set to lowercase then you might face the problem.

If they are not then either:

Solution 01
If you use spfile, then

SQL> create pfile from spfile;

Edit the pfile to alter all definitions to the correct case

SQL> create spfile from pfile=[location of pfile here];

SQL> startup

Solution 02
modify the definitions in the OCR:

srvctl remove instance -d didar -i didar1

srvctl remove instance -d didar -i didar2

srvctl remove database -d didar

srvctl add database -d DIDAR -o $ORACLE_HOME

srvctl add instance -d DIDAR -i DIDAR1 -n [node1]

srvctl add instance -d DIDAR -i DIDAR2 -n [node2]

Solution 03
In the pfile add instance_number=1 value.
$ vi newpfile.ora
SPFILE='+DATA/DIDAR/spfileDIDAR.ora'
instance_number=1

SQL> connect sys as sysdba
Enter password:
Connected to an idle instance.

SQL> startup pfile='/opt/app/oracle/product/10.2.0/db_1/dbs/newpfile.ora'

SQL> alter system set instance_number=1 scope=spfile;

SQL> shutdown immediate;

SQL> startup

Tuesday, August 31, 2010

ORA-13516: AWR Operation failed: SWRF Schema not initialized

Problem Description
While executing dbms_workload_repository package the following error message is reported.
sql> exec dbms_workload_repository.modify_snapshot_settings(interval=>0);

BEGIN dbms_workload_repository.modify_snapshot_settings(interval=>0); END;
ERROR at line 1:
ORA-13516: AWR Operation failed: SWRF Schema not initialized
ORA-06512: at "SYS.DBMS_WORKLOAD_REPOSITORY", line 85
ORA-06512: at "SYS.DBMS_WORKLOAD_REPOSITORY", line 133
ORA-06512: at line 1

Cause of the Problem
These errors have happened because of wrong or invalid objects with respect to AWR.

Solution of the Problem
In order to resolve the issue you need to drop and recreate the AWR objects, which you can do by running CATNOAWR.SQL and CATAWR.SQL scripts.

Note that from 10.2 onwards, the script name has changed. The catalog script for AWR Tables, used to create the Workload Repository Schema is CATAWRTB.SQL .

In case of Oracle 10gR1,
To re-create the AWR objects, by running the catnoawr.sql and catawr.sql scripts located in $ORACLE_HOME/rdbms/admin.
SQL> @$ORACLE_HOME/rdbms/admin/catnoawr.sql
SQL> @$ORACLE_HOME/rdbms/admin/catawr.sql
SQL> shut immediate
SQL> startup
In case of Oracle 10gR2,
SQL> @$ORACLE_HOME/rdbms/admin/CATAWRTB.sql
SQL> shut immediate;
SQL> startup
On re-start of the database instance, the AWR tables will be populated with the required data.

Note that, the CATNOAWR.SQL scripts is no longer available in 10.2 and cannot be found
in the $ORACLE_HOME/rdbms/admin directory.

BSLN_MAINTAIN_STATS_JOB fails with ORA-12012, ORA-06502, ORA-06512

Problem Description
The BSLN_MAINTAIN_STATS_JOB doesn't run anymore.
From the trace file we see the following information.
ORA-12012: error on auto execute of job 11689
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "DBSNMP.BSLN_INTERNAL", line 2073

Cause of the Problem
Table DBSNMP.BSLN_BASELINES contains inconsistent information. In this case, after database cloning, existing records in table "DBSNMP.BSLN_BASELINES" conflict with new baseline information inserted in the cloned database.

Solution of the Problem
The DBSNMP user needs to be dropped and re-created.

Login as sys user.

SQL> sqlplus / as sysdba

From the sqlplus execute the following:

Drop the user by executing catnsnmp.sql script.
SQL> @$ORACLE_HOME/rdbms/admin/catnsnmp.sql

Create the DBSNMP user by executing catsnmp.sql
SQL> @$ORACLE_HOME/rdbms/admin/catsnmp.sql

Datapump export or import fails with ORA-31626, ORA-31633, ORA-00955

Problem Description
While doing datapump export or import operation it fails with following error messages:

ORA-31626: job does not exist
ORA-31633: unable to create master table "ARJU.SYS_EXPORT_TABLE_05"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.KUPV$FT", line 863
ORA-00955: name is already used by an existing object

Cause of the Problem
Error is caused by a stopped job that remained in the DBA_DATAPUMP_JOBS. The new expdp/impdp job has the same name as the old expdp/impdp job.

Solution of the Problem
Clear the old job or specify a different name for the new job.

Step 01. Determine in SQL*Plus which Data Pump jobs exist in the database:
select owner_name, job_name, operation, job_mode, 
state, attached_sessions
from dba_datapump_jobs
where job_name not like 'BIN$%'
order by 1, 2;

Step 02. Ensure that the listed jobs in DBA_DATAPUMP_JOBS are not active DataPump export/import jobs. The status should be 'NOT RUNNING'.

Step 03. Check with the job owner that the job with status 'NOT RUNNING' in DBA_DATAPUMP_JOBS is not an export/import DataPump job that has been temporary stopped, but is actually a job that failed.

Step 04. Determine in SQL*Plus the related master tables:
select o.status, o.object_id, o.object_type, 
o.owner||'.'||object_name "OWNER.OBJECT"
from dba_objects o, dba_datapump_jobs j
where o.owner=j.owner_name and
o.object_name=j.job_name and
j.job_name not like 'BIN$%'
order by 4, 2;

Step 05. For jobs that were stopped in the past and won't be restarted anymore, delete the master table.
drop table ARJU.SYS_EXPORT_TABLE_05 ;

Related Documents
Expdp fails with ORA-01950 and ORA-01536
Expdp fails with ORA-31626, ORA-31633, ORA-06512, ORA-01031
Data pump export fails with ORA-39000, ORA-31641,ORA-27038

Troubleshoot ORA-06512: at line

ORA-06512 is a common error faced by Oracle DBA, programmers as well as end users. ORA-06512 does not identify the root cause of the problem, rather it only prints the line number where the errors or exception happened. So just before ORA-06512 there will be additional error which we may need to investigate. If the errors come from any function or package or package body or procedure then with ORA-06512 there exists the name of the function or package or package body or procedure as well as the line number of those objects where error is occurred.

A simple demonstration of ORA-06512 error using PL/SQL anonymous block is shown below.
SQL> declare
2 var1 number(3);
3 begin
4 var1:=1000;
5 end;
6 /
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at line 4
As this one is simply anonymous block and no package, function or procedure involved, so it does not generate any additional ORA-06512 error. However, just before ORA-06512 error there contains the root cause of the problem which is due to "ORA-06502: PL/SQL: numeric or value error: number precision too large". ORA-06512 simply notifies the problem happened at line number 4 of the anonymous block because we declare var1 length as 3 digits but we were going to insert 4 digits.

Now let's look a small variation of above error. Same code with a procedure.
SQL> create or replace procedure ORA06512_demo as
2 var1 number(3);
3 begin
4 var1:=1000;
5 end;
6 /

Procedure created.

SQL> exec ORA06512_demo
BEGIN ORA06512_demo; END;

*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: number precision too large
ORA-06512: at "ARJU.ORA06512_DEMO", line 4
ORA-06512: at line 1
Here notice as the code is run by a procedure and procedure contains same error so ORA-06512 is generated twice. If there is several ORA-06512 error then you should first take care of the first one. It is specified in which procedure as well as in which line problem happened. Then step by step you should fix second, third and so on if after fixing first one you get any more. Here "ORA-06512: at line 1" error is generated for the statement "exec ORA06512_demo".

To make you more clear, I will show you a more detail example.
SQL> create or replace procedure ORA06512_DEMO_SUB2(var1in number, string1in varchar2) as
2 var1 number;
3 var2 number;
4 var3 number;
5 begin
6 var1:=var1in;
7 var2:=string1in;
8 var3:='a';
9 end;
10 /

Procedure created.

SQL> create or replace procedure ORA06512_DEMO_SUB1(string1 varchar2) as
2 var1 number ;
3 begin
4 var1:=100;
5 ORA06512_DEMO_SUB2(var1,string1);
6 end;
7 /

Procedure created.

SQL> create or replace procedure ORA06512_DEMO_MAIN as
2 begin
3 ORA06512_DEMO_SUB1('This is a string');
4 end;
5 /

Procedure created.

SQL> exec ORA06512_DEMO_MAIN;
BEGIN ORA06512_DEMO_MAIN; END;

*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "ARJU.ORA06512_DEMO_SUB2", line 7
ORA-06512: at "ARJU.ORA06512_DEMO_SUB1", line 5
ORA-06512: at "ARJU.ORA06512_DEMO_MAIN", line 3
ORA-06512: at line 1
Here you see the first ORA-06512 is generated for the procedure "ARJU.ORA06512_DEMO_SUB2" and line 7. So you should take care of that first. The main cause of the problem is for ORA-06502 which is shown just before very first of ORA-06512 error. So fix the "ARJU.ORA06512_DEMO_SUB2" procedure first by changing datatype and then "ARJU.ORA06512_DEMO_SUB1" and so on.

Let's try to fix the problem. So deal with "ARJU.ORA06512_DEMO_SUB2" procedure. We see input parameter string1in is datatype of varchar2. Within procedure it is assigned to variable var2 which is number datatype, so we need to change it to varchar2. Also var3 is number datatype, so we will assign number variable into it not any char type. So doing these two changes and then run the main procedure ORA06512_DEMO_MAIN.
SQL> create or replace procedure ORA06512_DEMO_SUB2(var1in number, string1in varchar2) as
2 var1 number;
3 var2 varchar2(20);
4 var3 number;
5 begin
6 var1:=var1in;
7 var2:=string1in;
8 var3:=10;
9 end;
10 /

Procedure created.

SQL> exec ORA06512_DEMO_MAIN;

PL/SQL procedure successfully completed.
It looks perfect.

Related Documents
ORA-39127 ORA-04063 ORA-06508 ORA-06512 package body "WMSYS.LT_EXPORT_PKG" has errors
ORA-13600, QSM-00775, ORA-06512 when running DBMS_ADVISOR
Expdp fails with ORA-31626, ORA-31633, ORA-06512, ORA-01031
Export Full=y fails with PLS-00201 ORA-06510 ORA-06512
Expdp fails with ORA-39001,ORA-39169,ORA-39006,ORA-39022

Monday, August 30, 2010

Oracle DBA Interview Questions - Part 1

Question 01: When Oracle database implemented PL/SQL Language?
Answer: The first version of the PL/SQL language is introduced in Oracle version 6. In oracle Oracle7, released in 1992, introduced PL/SQL stored procedures and triggers.

Question 02: In which version of Oracle RAC is implemented?
Answer: Oracle 9i database introduced Oracle RAC in year 2001. Later Oracle Database 10g introduced grid computing in 2003.


Question 03: What is Oracle database instance?
Answer: An Oracle instance is a set of memory structures that manage different database files. It consists of Shared/System Global Area (SGA) and a set of background processes.

Question 04: Name the Oracle schema object types.
Tables, Indexes, Partitions, Views, Sequences, Dimensions, Synonyms, PL/SQL subprograms and packages.

Question 05: What are the characteristics of Materialized Views?
i) Just like table materialized views contain data and consume storage space.
ii) They can be refreshed when the data in their master tables changes.
iii) They can improve performance of SQL execution when used for query rewrite operations.
iv) The existence of materialize view is transparent to SQL applications and users. So if optimizer sees use of materialize view is more efficient than accessing original table then for that query materialize view will be automatically used.

Question 06: Name the different types of Constraints
NOT NULL, Unique, Primary, Foreign, Check.

Question 07: What are the DDL statements?
DDL statements do structural changes or drop schema objects. For example: CREATE, ALTER, DROP, TRUNCATE, GRANT, REVOKE, AUDIT, NOAUDIT, COMMENT.

Question 08: What are the DML statements?
Data manipulation language (DML) statements query or manipulate data in existing schema objects. For example: SELECT, INSERT, UPDATE, MERGE, DELETE, EXPLAIN PLAN, LOCK TABLE.

Question 09: What are the TC statements?
Transaction control statements manage the changes made by DML statements and group DML statements into transactions. For example: COMMIT, ROLLBACK, ROLLBACK TO SAVEPOINT, SAVEPOINT, SET TRANSACTION.

Question 10: What are the Session Control statements?
Session Control Statements dynamically manage the properties of a user session. For example: ALTER SESSION, SET ROLE.

Question 11: What are the System Control statements?
System control statements change the properties of the database instance. The only system control statement is ALTER SYSTEM.

Question 12: What are the Embedded SQL statements?
Embedded SQL statements incorporate DDL, DML, and transaction control statements within a procedural language program.
For example:
- Define, allocate, and release cursors (DECLARE CURSOR, OPEN, CLOSE).
- Specify a database and connect to it (DECLARE DATABASE, CONNECT).
- Assign variable names (DECLARE STATEMENT).
- Initialize descriptors (DESCRIBE).
- Specify how error and warning conditions are handled (WHENEVER).
- Parse and run SQL statements (PREPARE, EXECUTE, EXECUTE IMMEDIATE).
- Retrieve data from the database (FETCH).

Sunday, August 29, 2010

Time synchronization in Oracle clusterware 11gR2

Oracle clusterware 11gR2 requires time synchronization across all nodes within a cluster when Oracle RAC is deployed. Through two ways you can do time synchronization across the cluster.
1) An operating system configured network time protocol (NTP)
2) Oracle Cluster Time Synchronization Service (ctss).

While installing Oracle Grid Infrastructure, if you don't have NTP daemons then (Oracle Cluster Time Synchronization daemon)ctssd starts up in active mode and synchronizes time among cluster members without contacting an external time server.

When Oracle sees there is NTP, then the Oracle Cluster Time Synchronization daemon (ctssd)
starts up in observer mode and no active time synchronization is performed by
Oracle Clusterware within the cluster.

In fact Oracle Cluster Time Synchronization Service is designed for organizations whose cluster servers are unable to access NTP services. For example your RAC database does not have way to access any external time server, then you can use ctssd for your clusterware installation.

If you have NTP daemons on your server but you cannot configure them to synchronize time with a time server, and you want to use Cluster Time Synchronization Service to provide synchronization service in the cluster then do the following steps.

1) Stop the existing ntpd service
# /sbin/service ntpd stop

2) Disable ntpd service from the initialization sequences
# chkconfig ntpd off

3) Remove or move the ntp.conf file.
# rm /etc/ntp.conf
or,
# mv /etc/ntp.conf /etc/ntp.conf.org

4) Also remove the ntpd.pid file which maintains the pid for the NTP daemon.
# rm /var/run/ntpd.pid

However if you are using NTP and you you prefer to continue using it instead of Cluster Time
Synchronization Service, then you need to modify the NTP configuration to set the -x flag, which prevents time from being adjusted backward.

1) Edit the /etc/sysconfig/ntpd file to add the -x flag
# vi /etc/sysconfig/ntpd
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"

2) Restart the NTP service.
# /sbin/service ntp restart

Note that on SUSE systems, you have to modify the configuration file /etc/sysconfig/ntp with the
following settings:
NTPD_OPTIONS="-x -u ntp"

Related Documents
ORA-15018, ORA-15072 on 11gR2 grid node 2 when running root.sh
In 11gR2 RAC after server reboot crsd fails to startup on 2nd node
PRKP-1001, CRS-0215 while starting instance using srvctl
NTP and csstd time synchronization option to install Oracle Clusterware 11gR2
cluvfy fails with PRVF-5436 PRVF-9652 Cluster Time Synchronization Services check failed
In 11gR2 Grid root.sh fails with CRS-2674: Start of 'ora.cssd' failed
What to do after failure of Oracle 11gR2 Grid Infrastructure (CRS) Installation
Enable Archive log Mode for RAC database
List of Parameters that must have identical in RAC database
CRS Stack Fails to Start After Reboot ORA-29702 CRS-0184