Category Archives: Oracle

Oracle 10g RMAN database Setup

Oracle Recovery Manager is an excellent tool for the backup and recovery of Oracle databases. It allows you to easily backup your information on scheduled bases to ensure against all forms of data loss. Additionally, it makes the process of recovering from data corruption to disk loss in a very expedient manor. The following instruction set covers the setup of an oracle database for storage of your recovery catalog and the cataloging of your first target database. This instruction set was written from a Linux installed Oracle system; however it will work on most any flavor of UNIX.

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

2. Use the ./dbca command as follows to open up the Oracle Database Creation Assistant or create a database named RMAN manually. Note: This oracle database is only used to store the catalog information of backed-up databases, thus the storage and memory requirements are very low. I would not allocate more than 200MB of space and 100MB of memory to this database.

linux1# cd $ORACLE_HOME/bin
linux1#
linux1# ./dbca

3. If using dbca, follow the prompted screens to create a general purpose database.

4. If the database is created using manual methods ensure that the following Oracle scripts are executed after build.

connect sys/oracle@RMAN as sysdba
set echo off
@?/rdbms/admin/catalog
@?/rdbms/admin/catproc
@?/rdbms/admin/catrep
@?/rdbms/admin/catexp
@?/rdbms/admin/catldr
@?/rdbms/admin/dbmsutil
@?/rdbms/admin/prvtutil.plb
@?/rdbms/admin/dbmssql
@?/rdbms/admin/prvtsql.plb
@?/rdbms/admin/dbmsdefr
@?/rdbms/admin/prvtdefr.plb
@?/rdbms/admin/catqueue
@?/rdbms/admin/dbmsaqad
@?/rdbms/admin/prvtaqad.plb
@?/rdbms/admin/catcr
@?/rdbms/admin/prvtcr.plb
connect system/oracle@RMAN
@?/rdbms/admin/catdbsyn
@?/sqlplus/admin/pupbld.sql
conn sys/oracle@RMAN as sysdba
@?/rdbms/admin/utlrp

5. Logon to your newly created database and create a tablespace for the RMAN user with the following command.

create tablespace rman
datafile ‘/u05/oradata/RMAN/rman01.dbf’ size 200m
extent management local autoallocate
segment space management auto;

6. Logon to your newly created database and create the RMAN User with the following command. Then grant the RMAN user the privileges: recovery_catalog_owner, connect, and resource.

create user rman identified by rman
temporary tablespace temp
default tablespace rman quota unlimited on rman;

grant recovery_catalog_owner to rman;

grant connect,resource to rman;

7. Add the following text to the listener.ora file on the server hosting the RMAN database and ensure that an entry is listed on all database servers to be backed-up in their individual tnsnames.ora files for the newly created RMAN database.

(SID_DESC =
(ORACLE_HOME = /u01/opt/app/oracle/product/10.2.0/Db_1)
(SID_NAME = RMAN1)
)

8. Issue a stop and restart of the oracle listener for changes to take affect.

linux1# lsnrctl stop

linux1# lsnrctl start

9. Register the target database in the catalog.

10. Logon to your server and set the ORACLE_SID parameter to your target database.

linux1# echo $ORACLE_SID

linux1# ORACLE_SID=orcl
linux1# export ORACLE_SID
linux1# echo $ORACLE_SID
orcl
linux1#

11. Execute the command , to logon to the RMAN utility.

linux1# rman target / catalog rman/rman@RMAN

Recovery Manager: Release 10.2.0.2.0 – Production on Wed Sep 24 15:42:29 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

connected to target database: ORCL (DBID=3051662701)
connected to recovery catalog database

RMAN>

12. Issue the command in the RMAN utility.

RMAN> create catalog

recovery catalog created

RMAN>

13. Issue the command in the RMAN utility.

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN>

14. NOTE: By default RMAN will attempt to register a TAPE drive in the system. If you do not have a tape drive available specify.

RMAN> CONFIGURE CHANNEL DEVICE TYPE ‘SBT_TAPE’ clear;

old RMAN configuration parameters:
CONFIGURE CHANNEL DEVICE TYPE ‘SBT_TAPE’ MAXPIECESIZE 10 G;
old RMAN configuration parameters are successfully deleted
starting full resync of recovery catalog
full resync complete

This completes the creation of RMAN recovery catalog and registration of your target database.

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

Configuration of Oracle Flashback

The Flashback database allows you to maintain a backup version of changes in the database that enables you to recovery from user mistakes without the need for a full database recovery. In this section, we will describe the following:

1. Configuration of Flashback for existing database.
2. Configuration of Flashback to a new database.

Steps in implementing the Flashback for existing database

1. Defining the Initialization Parameters for Flashback area.

a. DB_RECOVERY_FILE_DEST_SIZE – defines the maximum size that the Flashback Area can grow to. NOTE: This parameter must be set before defining DB_RECOVERY_FILE_DEST.
b. DB_RECOVERY_FILE_DEST – this the directory storage area on disk that will hold all files related to backup and recovery, note this is for both flashback recovery and traditional RMAN recovery.

2. Specify initialization parameter by defining in PFILE or Altering the system: In this example we will alter the system.

SQL> alter system set db_recovery_file_dest_size=30G scope = both;
System altered.
SQL> alter system set db_recovery_file_dest=’/u03/oradata/orcl/flash_recovery_area’ scope = both;
System altered.
SQL>

3. Ensure that the parameters LOG_ARCHIVE_DEST and LOG_ARCHIVE_DUPLEX_DEST are not set in the database. With Flashback you can only specify an LOG_ARCHIVE_DEST_n, by default LOG_ARCHIVE_DEST_10 will be set to your flash_recovery area.

SQL> show parameter log_archive

NAME TYPE VALUE
———————————— ———– ——————————
log_archive_config string
log_archive_dest string
log_archive_dest_1 string LOCATION=use_db_recovery_file_dest
log_archive_dest_10 string
log_archive_dest_2 string LOCATION=/u02/oradata/orcl/arc
hive
log_archive_dest_3 string LOCATION=/u05/oradata/orcl/arc
hive
log_archive_dest_4 string
log_archive_duplex_dest string

4. With the flash recovery area set we can startup our database in flashback mode. NOTE: The database must be mounted in exclusive mode, archiving enabled, and then flashback turned on before opening the database for use.

startup mount exclusive;
alter database archivelog;
alter database flashback on;
alter database open;

5. This completes the configuration of Flashback for existing database.

Configuration of Flashback on a new database

1. The following entries need to be placed in your pfile of new database.

DB_NAME=orcl
# set location for current datafiles:
DB_CREATE_FILE_DEST = ‘/u02/oradata/orcl’
# set location for control files and online redo logs:
DB_CREATE_ONLINE_LOG_DEST_1 = ‘/u03/oradata/orcl’
DB_CREATE_ONLINE_LOG_DEST_2 = ‘/u04/oradata/orcl’
# set flash recovery area location and size
DB_RECOVERY_FILE_DEST = ‘/u03/oradata/orcl/flash_recovery_area’
DB_RECOVERY_FILE_DEST_SIZE = 30G

2. Create your new database with DBCA or manually with scripts.

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

Recreating Oracle 10g EM

Oracle 10g Enterprise Manager has been a vast improvement over previous versions. However, I have experienced several situation where its behavior has become very unpredictable due to changes to DBSNMP or SYSMAN schemas and changes made to the your EM configuration files. In these situations, I have found it much easier to remove the EM components and re-install to resolve the problems. NOTE: This may not always be your best option; some objects created in EM may no longer exist after performing this procedure. However, EM will work without error itself.

1. Login to your Oracle server as the oracle software owner, set your ORACLE_SID and shutdown your Oracle EM console.

[root@linux1 ~]# su – oracle
[oracle@linux1 ~]$ ORACLE_SID=orcl
[oracle@linux1 ~]$ export ORACLE_SID
[oracle@linux1 ~]$ emctl stop dbconsole
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://linux1:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10g Database Control …
… Stopped.
[oracle@linux1 ~]$

2. Startup the Oracle universal installer, located under $ORACLE_HOME/oui/bin directory. The shell script to execute the installer is runInstaller.

3. At the welcome screen select deinstall Products.

4. At the Inventory screen, expand the tabs Oracle Home and Oracle Database to show all installed components. Ensure that only Oracle Enterprise Manager is selected and press the Remove button.

5. At the Confirmation screen, press the Yes button to continue.

6. The Oracle Universal Installer will remove all Oracle Enterprise Manager components.

7. After the uninstall is complete, the Oracle Universal Installer will return you to the Inventory screen, press the Close button to exit the installer.

8. Login to SQL*Plus with as sysdba and drop the user schemas dbsnmp and sysman with the cascade clause.

login as: oracle
oracle@linux1’s password:
Last login: Mon Jan 14 11:31:32 2008 from 192.168.1.101
[oracle@linux1 ~]$ ORACLE_SID=orcl
[oracle@linux1 ~]$ export ORACLE_SID
[oracle@linux1 ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 – Production on Mon Jan 14 13:47:52 2008

Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> connect / as sysdba
SQL> drop user sysman cascade;
User dropped.
SQL> drop user dbsnmp cascade;
User dropped.
SQL>

9. Now execute the script catsnmp.sql located in $ORACLE_HOME/rdbms/admin to recreate the dbsnmp schema.

SQL>$ORACLE_HOME/rdbms/admin/catsnmp.sql

10. Startup the Oracle universal installer, located under $ORACLE_HOME/oui/bin directory. The shell script to execute the installer is runInstaller.
11. At the welcome screen select Next button.

12. At the Specify Source Location page, enter the directory where you unzipped your oracle database software and select Next.

13. At the Select Installation Type, select the Custom radio button and press Next.

14. At the Specify Home Details, enter the Home name and default path for installation and press Next.

15. You will receive a Warning message stating the directory is not empty. Select Yes to continue.

16. At the Available Products Components page, ensure that only Oracle Enterprise Manger is select and press Next button.

17. At the Product-Specific Prerequisite Checks page, select Next.

18. At the Summary page, select the Install button.

19. The Oracle Enterprise Manger will now install.

20. Once the End of Installation page is display, select the exit button.

21. Logon to your Oracle host machine console as the oracle software owner and set your ORACLE_SID variable.

login as: oracle
oracle@linux1’s password:
Last login: Mon Jan 14 11:31:32 2008 from 192.168.1.101
[oracle@linux1 ~]$ ORACLE_SID=orcl
[oracle@linux1 ~]$ export ORACLE_SID

22. Startup the em console and test your connection.

[oracle@linux1 ~]$ emctl start dbconsole
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://linux1:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control ……………….. started.
——————————————————————
Logs are generated in directory /u01/oracle/oracle/product/10.2.0/db_1/linux1_orcl/sysman/log
[oracle@linux1 ~]$

23. Test your connect to the dbconsole at reference address in the emctl start command: normally this would be http://<machine_name>:1158/em

 

 

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

DBCA will not start with error NJNI10

1. If you see the error below when trying to execute DBCA try the next three steps to resolve.

[oracle@mylinux1 bin]$ ./dbca

UnsaUntitled 1tisfiedLinkError exception loading native library: njni10
Exception in thread “main” java.lang.UnsatisfiedLinkError: get
at oracle.net.common.NetGetEnv.get(Native Method)
at oracle.net.config.Config.getNetDir(Unknown Source)
at oracle.net.config.Config.initConfig(Unknown Source)
at oracle.net.config.Config.(Unknown Source)
at oracle.sysman.assistants.util.NetworkUtils.(NetworkUtils.java:225)
at oracle.sysman.assistants.util.step.StepContext.(StepContext.java:264)
at oracle.sysman.assistants.dbca.backend.Host.(Host.java:686)
at oracle.sysman.assistants.dbca.ui.UIHost.(UIHost.java:205)
at oracle.sysman.assistants.dbca.ui.InteractiveHost.(InteractiveHost.java:54)
at oracle.sysman.assistants.dbca.Dbca.getHost(Dbca.java:160)
at oracle.sysman.assistants.dbca.Dbca.execute(Dbca.java:94)
at oracle.sysman.assistants.dbca.Dbca.main(Dbca.java:180)

[oracle@mylinux1 bin]$

2. Create the following soft links in $ORACLE_HOME/bin directory and retry ./dbca command.

[oracle@mylinux1 bin]$ ln -s $ORACLE_HOME/lib/libnjni10.dylib $ORACLE_HOME/lib/libnjni10
[oracle@mylinux1 bin]$ ln -s $ORACLE_HOME/lib/libclntsh.dylib $ORACLE_HOME/lib/libclntsh.dylib.10.1

3. If the previous step did not resolve the issue ensure that the variable LD_LIBRARY_PATH contains both $ORACLE_HOME/lib and $ORACLE_HOME/lib32. Re-execute your .bash file and retry ./dbca command.

[oracle@mylinux1 ~]$ vi .bash_profile
[oracle@mylinux1 ~]$ . ./.bash_profile

4. If the previous step did not resolve the issue, install or re-install the following 32 bit packages: glibc-devel-2.3.4-2.36.i386.rpm and glibc-2.3.4-2.36.i686.rpm. Then cd to $ORACLE_HOME/bin and execute ./relink all. Finally, retry the ./dbca command.

[root@mylinux1 RPMS]# rpm -Uvh –force glibc-devel-2.3.4-2.36.i386.rpm
Preparing… ########################################### [100%]
1:glibc-devel ########################################### [100%]
[root@mylinux1 RPMS]# rpm -Uvh –force glibc-2.3.4-2.36.i686.rpm
Preparing… ########################################### [100%]
1:glibc ########################################### [100%]
[root@mylinux1 RPMS]#

Larry J Catt, OCP
oracle@allcompute.com
www.allcompute.com

ASM with RAW Disks will not start after reboot

ASM (Automatic Storage Management) instances for the storage of database files have become a very popular option in the database world since the release of ORACLE 10g. However, there exist several administration concerns over ASM, which the DBA must take into consideration. This article covers the problem of ASM instance not starting after a reboot of a Linux server and applies to most Unix systems while using RAW Disks.

Error: ORA-15042: ASM disk is missing.

Reason: This error is caused by the RAW device being removed from the OS, corrupted, or/and most likely, not owned by the ORACLE user.

1. Verify that the ASM disk exists.

[root@mylinux1 /]# cd /dev/raw
[root@mylinux1 /dev/raw]# ls
/dev/raw/raw1
/dev/raw/raw2
/dev/raw/raw3
[root@mylinux1 u06]#

2. Check the ownership of the disks.

[root@mylinux1 /]# cd /dev/raw
[root@mylinux1 /dev/raw]# ls –la
-rw-r–r– 1 root root 2 Sep 2 08:33 raw1
-rw-r–r– 1 root root 2 Sep 2 08:33 raw2
-rw-r–r– 1 root root 2 Sep 2 08:34 raw3
[root@mylinux1 /dev/raw]#

NOTE: These raw devices are now owned by ROOT after the reboot, thus ORACLE does not have access.

3. On most UNIX systems you will see that the ownership of RAW devices is reset to ROOT after reboot. To correct this behavior, enter the following code into your init process before the Oracle database startup scripts are executed.

chown oracle:dba /dev/raw/raw1
chown oracle:dba /dev/raw/raw2
chown oracle:dba /dev/raw/raw3

Larry J Catt, OCP
oracle@allcompute.com
www.allcompute.com

CRS setup for ORACLE 10g ASM instance

In order for ASM and RAC to work properly the CRS (Cluster Ready Service) must first be configured. This procedure outlines the configuration of CRS in a Linux environment.

1. Logon to Linux server as the root user.

2. Verify that the correct support packages are installed.

[root@mylinux_1 RPMS]# ls compat-libstdc++*
compat-libstdc++-296-2.96-132.7.2.i386.rpm

3. NOTE: depending on your OS you may require a different version or bit setting of this package. I am running x86_64 system so I will install the newest compat-listdc++ package for this system.

[root@mylinux_1 RPMS]# rpm -i compat-libstdc++-33-3.2.3-47.3.x86_64.rpm
[root@mylinux_1 RPMS]#

4. As the ROOT user navigate to the directory $ORACLE_HOME/bin. Execute the command ./localconfig add. The localconfig command cannot be run as the ORACLE user.

[root@mylinux_1 bin]# ./localconfig add
Successfully accumulated necessary OCR keys.
Creating OCR keys for user ‘root’, privgrp ‘root’..
Operation successful.
Configuration for local CSS has been initialized

Adding to inittab
Startup will be queued to init within 30 seconds.
Checking the status of new Oracle init process…
Expecting the CRS daemons to be up within 600 seconds.
CSS is active on these nodes.
mylinux_1
CSS is active on all nodes.
Oracle CSS service is installed and running under init(1M)
[root@mylinux_1 bin]#

5. If CRS fails to install you must back out the files created with the command ./localconfig delete. Most likely the failure has occurred due to missing support packages. Verify that all packages suggested by Oracle Corporation for your OS and product version exist. You can find this listing at www.oracle.com/technology/index.html.

Larry Catt, OCP
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

Safely removing an Oracle user account

In an oracle database every user has the ability (may not have the privilege) to own objects, this collection of objects is referred to as a schema. A typical user of a database application will not have any objects within their schema. To safely remove an Oracle user you must ensure that they do not own any objects which may be referenced by other users. This article outlines the step to ensure that the user does not own any objects.

1. Logon to SQL*PLUS with DBA privileges.

2. Select the number of objects owned by the user account you wish to delete with the following statement. In this example we are trying to delete user JDOE.

SQL> select count(*) from dba_objects where owner='JDOE';

COUNT(*)
----------
0

SQL>

3. If the above SQL statement returns a number greater than 0, further investigation is required. If the above SQL statement returns 0, you can safely remove the user account with the below statement.

SQL> drop user jdoe;

User dropped.

SQL>

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

Dropping a user and the cascade option

In an oracle database every user has the ability (may not have the privilege) to own objects, this collection of objects is referred to as a schema. A typical user of a database application will not have any objects within their schema. To safely remove an Oracle user you must ensure that they do not own any objects which may be referenced by other users. The cascade option of the drop command, allows the administrator to by-pass the deletion of objects owned by the user. NOTE: It is very important to verify that you do not need any objects owned by a user before dropping the account with the cascade option. This article outlines the step to list all objects owned by a user before dropping the account with the cascade option..

1. Logon to SQL*PLUS with DBA privileges.

2. Select the object name and type owned by the user account you wish to delete with the following statement. In this example we are trying to delete user JDOE.
SQL> column object_name format a30
SQL> select object_name, object_type from dba_objects where owner='JDOE';

OBJECT_NAME OBJECT_TYPE
------------------------------ -------------------
TEMP TABLE

SQL>

3. If the above SQL statement returns a number greater than 0, you should validate that the objects are not used by any other user. If the above SQL statement returns 0, you can remove the user account without the cascade option as shown below.

SQL> drop user jdoe;

User dropped.

SQL>

4. Once you are sure that the objects are not being used by any other user, use the following SQL to remove the account and all associated objects.

SQL> drop user jdoe cascade;

User dropped.

SQL>

NOTE: The associated table TEMP was removed before the actual account was removed.

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