Category Archives: oracle 9i

Executing SQL script from command line or executable shell script

You can call into SQLPLUS to execute SQL script from any shell script. This procedure shows how to structure your statements to LINUX environment for call into SQLPLUS from shell script.

1. Logon to your LINUX server as a user with access to SQLPLUS.
2. Use VI to create a executable file. Replace the connection string with appropriate username/password@SID values. Additionally, change the script you which to execute in this example we are executing “utlrp.sql”.

sqlplus sys/password@orcl as sysdba < < EOF @?/rdbms/admin/utlrp.sql exit; EOF

Larry Catt
OCP

Oracle 12c – Perform daily administration tasks

Oracle 12c does not eliminate the need for daily administrative tasks of a database administrator, however it does have many enhancement that can aid in the identification of problems/sub-par performance.    Additionally, there exist two camps on monitoring the health of a database:  One wanting to automate all monitoring tasks and let the database tell you when something is wrong; and One that wants tasks to remain manual where you keep a closer contact with database structures and are able to determine trends.  Regardless of how you perform your monitoring, the following list of daily DBA tasks is a good general guideline.   NOTE:   This list is not limited to just error checking, a DBA job covers both error correction and error avoidance.

 

  1. Check for any database errors in alert and trace.
  2. Check for any networking errors in listener alert. (other network connectivity logs)
  3. Check for errors in Operating System log files for database servers.
  4. Check for errors in Storage Area Network log files.
  5. Check Space allocation for database storage. (database tablespaces)
  6. Check for Space availability at Operating System Layer.
  7. Check any Application Layer error logs.
  8. Installing, Upgrading, and Patching Oracle Database server software (OS) and application tools. (Test installing, upgrading, and Patching before production implementations)
  9. Allocation of system storage and planning future storage.
  10. Creating primary database storage structure (tablespaces)
  11. Create primary database objects (tables, views, indexes)
  12. Planning backup and recovery procedure.
  13. Consult oracle technical support
  14. Ensure compliance with Oracle license agreement.
  15. Modify database structures.
  16. Managing users and maintain security.
  17. Controlling and Monitoring user activity and privileges.
  18. Monitor and optimize performance.
  19. Maintain archive tape backup/recovery devices (other type of backup device).
  20. Backup and restore database. (including test recovery at least twice a year)

 

Larry Catt

OCP

 

 

 

Determining the record insert rate for a table

Some system require the insertion of large amounts of data in as short a period of time as possible. In this cases, you must be able to measure actual physical time of insertion per give number of records or number of records inserted per second.   The following block allows you to perform this action on a give oracle operation.

We will use the following anonymous block to track our processing time:

SET SERVEROUTPUT ON  DECLARE      v_loops          NUMBER := 1000000;    v_start_time     NUMBER;    v_total_time  NUMBER;    v_ct    NUMBER :=1;    BEGIN

— Time we started our process.    v_start_time := DBMS_UTILITY.get_time;

FOR i IN 1 .. v_loops LOOP   < Oracle Action:  Insert, function call, procedure call, etc >   v_ct:=v_ct+1;   commit;   END LOOP;       –Calculate the time in seconds     v_total_time := (DBMS_UTILITY.get_time – v_start_time)/100;           DBMS_OUTPUT.put_line(‘This process took a total of : ‘ ||v_total_time||’ seconds to complete’);  END;  /     Example Execution:

1.  Connect as the user scott and create a table test_data

SQL> connect scott/tiger@orcl Connected. SQL> create table test_data(user_no number, fname varchar2(30), lname varchar2(30));

Table created.

SQL>

2.  Execute your block with < Oracle Action …> replaced with an insert statement for test data.

SET SERVEROUTPUT ON  DECLARE      v_loops          NUMBER := 1000000;    v_start_time     NUMBER;    v_total_time  NUMBER;    v_ct    NUMBER :=1234;    BEGIN

— Time we started our process.    v_start_time := DBMS_UTILITY.get_time;

FOR i IN 1 .. v_loops LOOP   insert into scott.test_data(user_no, fname, lname) values(v_ct, ‘JANE’, ‘DOE’);   v_ct:=v_ct+1;   commit;   END LOOP;       –Calculate the time in seconds     v_total_time := (DBMS_UTILITY.get_time – v_start_time)/100;           DBMS_OUTPUT.put_line(‘This process took a total of : ‘ ||v_total_time||’ seconds to complete’);  END;  /      Results:    SQL> SET SERVEROUTPUT ON SQL>  DECLARE   2   3     v_loops          NUMBER := 1000000;   4     v_start_time     NUMBER;   5     v_total_time            NUMBER;   6     v_ct                            NUMBER :=1234;   7   8   BEGIN   9  10     — Time we started our process.  11     v_start_time := DBMS_UTILITY.get_time;  12  13    FOR i IN 1 .. v_loops LOOP  14  15  insert into scott.test_data(user_no, fname, lname) values(v_ct, ‘JANE’, ‘DOE’);  16    v_ct:=v_ct+1;  17    commit;  18    END LOOP;  19  20     –Calculate the time in seconds  21      v_total_time := (DBMS_UTILITY.get_time – v_start_time)/100;  22  23      DBMS_OUTPUT.put_line(‘This process took a total of : ‘ ||v_total_time||’ seconds to complete’);  24     END;  25   / This process took a total of : 86.45 seconds to complete

PL/SQL procedure successfully completed.

SQL> SQL>

3.  The results show a insert rate of 86.45 seconds for 1 million records or 11,567.38 records per second.

Larry Catt

Oracle Error ORA-32004 and ORA-00845

Error:

[oracle@mylinux1 bin]$ ./dbca -silent -deleteDatabase -sourceDB orcl -sysDBAUserName larry -sysDBAPassword larry
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORA-00845: MEMORY_TARGET not supported on this system

Solution:

1. Logon to the database as sysdba

2. Execute the command.

SQL> show parameter memory_target;

NAME TYPE VALUE
———————————— ———– ——————————
memory_target big integer 3104M
SQL>

3. Issue the command.

SQL> alter system reset memory_target;

System altered.

SQL>

4. Shutdown the database

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

5. Startup the database.

SQL> startup open
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.

Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
Database mounted.
Database opened.
SQL>

6. Execute command:

SQL> show parameter memory_target

NAME TYPE VALUE
———————————— ———– ——————————
memory_target big integer 0
SQL>

7. re-execute

[oracle@mylinux1 bin]$ ./dbca -silent -deleteDatabase -sourceDB orcl -sysDBAUserName larry -sysDBAPassword larry
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance

[oracle@mylinux1 bin]$

This completes resolution of Oracle Error ORA-32004 – ORA-00845.

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

Find the Oracle parameter causing ORA-32004 and removing

During the normally life cycle of a database, multiple upgrades will occur, resulting in parameters becoming obsolete. This article shows how to determine the parameter which is obsolete and removing it.

Typical error generated by an obsolete parameter:

[oracle@mylinux2 bin]$ ./dbca -silent -deleteDatabase -sourceDB orcl
-sysDBAUserName larry -sysDBAPassword larry
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
[oracle@mylinux2 bin]$

1. Logon to the database as the sys user.

[oracle@mylinux2 bin]$ sqlplus ‘/ as sysdba’

SQL*Plus: Release 11.2.0.1.0 Production on Thu Feb 10 01:32:07 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>

2. Execute the following SQL to find the problem

select name, value from v$parameter where ISDEPRECATED=’TRUE’ and ISDEFAULT=’FALSE’;

SQL> select name, value from v$parameter where ISDEPRECATED=’TRUE’ and ISDEFAULT=’FALSE’;

NAME
——————————————————————————–
VALUE
——————————————————————————–
remote_os_authent
FALSE
SQL>

3. Reset this parameter

SQL> alter system reset remote_os_authent;
System altered.
SQL>

4. Stop database.

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

5. Start database.

SQL> startup
ORACLE instance started.

Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
Database mounted.
Database opened.
SQL>

This completes removing of obsolete or deprecated Oracle parameters.

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

How to debug Oracle opatch utility

The following procedure shows how to debug the Oracle opatch utility when you receive an error.

1. Execution of opatch utility results in the following error.

[oracle@mylinux1 OPatch]$ opatch lsinventory
Invoking OPatch 11.1.0.6.6

Oracle Interim Patch Installer version 11.1.0.6.6
Copyright (c) 2009, Oracle Corporation. All rights reserved.

Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.1.0.6.6
OUI version : 11.2.0.1.0
OUI location : /u01/app/oracle/product/11.2.0/dbhome_1/oui
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2011-04-02_19-17-51PM.log

Patch history file: /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch_history.txt
Inventory load failed… OPatch cannot load inventory for the given Oracle Home.
LsInventorySession failed: Unable to create patchObject

OPatch failed with error code 73
[oracle@mylinux1 OPatch]$

2. Set the environmental variable OPATCH_DEBUG equal to true.

[oracle@mylinux1 OPatch]$ export OPATCH_DEBUG=true
[oracle@mylinux1 OPatch]$

3. Re-execute your opatch utility and every action performed by opatch will be displayed in your buffer. Use the messages to determine the error.

This completes use of debug with the opatch utility.

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

Creation of Oracle OS accounts for 11g RAC install on Linux

Deployment of Oracle software requires the creation of multiple groups and users on UNIX and Linux servers to properly configure and administrate. This procedure covers the basic creation of Oracle groups and users for a standard 11g RAC implementation.

1. Create group accounts on all nodes: NOTE: id must be exactly the same

/usr/sbin/groupadd -g 501 oinstall
/usr/sbin/groupadd -g 502 dba
/usr/sbin/groupadd -g 504 asmadmin
/usr/sbin/groupadd -g 506 asmdba
/usr/sbin/groupadd -g 507 asmoper

2. Create user accounts on all nodes: NOTE: id must be exactly the same

/usr/sbin/useradd -u 501 -g oinstall -G asmadmin,asmdba,asmoper grid
/usr/sbin/useradd -u 502 -g oinstall -G dba,asmdba oracle

3. Set password for GRID and ORACLE account to be the same on every node.

passwd oracle
Changing password for user oracle.
New UNIX password: password
retype new UNIX password: password
passwd: all authentication tokens updated successfully.
passwd grid
Changing password for user oracle.
New UNIX password: password
retype new UNIX password: password
passwd: all authentication tokens updated successfully.

This completes the standard configuration creation of Oracle groups and users on Linux.

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

Configuration of OCFS2 in LINUX

OCFS2 Oracle Cluster File System version 2 is a file system which allows for multiple machines to open the same files at the same time without corruption. This file system can be used for multiple reasons but is mostly seen in Oracle RAC systems. This article details the configuration of OCFS2 after the RPMs have been installed on your OS.

1. Logon to your Linux server as root.

2. Create the directory /etc/ocfs2 to house your oracle cluster.conf file. This file will contain the name of your cluster and all nodes with in that cluster.

[root@mylinux1 etc]# mkdir /etc/ocfs2
[root@mylinux1 etc]# chmod 775 /etc/ocfs2

3. Edit the file cluster.conf and enter the strings similar to below; changing the value of ip_address, name and cluster to values which are correct for your installation..

[root@mylinux1 etc]# vi /etc/ocfs2/cluster.conf

node:
ip_port = 7777
ip_address = 204.34.132.38
number = 0
name = mylinux1.mydomain.com
cluster = myrac

node:
ip_port = 7777
ip_address = 204.34.132.39
number = 1
name = mylinux2.mydomain.com
cluster = myrac

cluster:
node_count = 2
name = myrac

4. Configure the ocfs2 installed on each node of the RAC with the o2cb configure command. NOTE: Enter the following:


Load O2CB driver on boot (y/n) [y] = y
Cluster stack backing O2CB [o2cb] = o2cb
Cluster to start on boot (Enter “none” to clear) [ocfs2]: = name of the cluster in cluster.conf file for this example it is myrac
Specify heartbeat dead threshold (>=7) [31] = 31
Specify network idle timeout in ms (>=5000) [30000] = 30000
Specify network keepalive delay in ms (>=1000) [2000] = 2000
Specify network reconnect delay in ms (>=2000) [2000] = 2000

Example:
[root@mylinux1 etc]# /etc/init.d/o2cb configure
Configuring the O2CB driver.

This will configure the on-boot properties of the O2CB driver.
The following questions will determine whether the driver is loaded on
boot. The current values will be shown in brackets (‘[]’). Hitting
without typing an answer will keep that current value. Ctrl-C
will abort.

Load O2CB driver on boot (y/n) [y]:
Cluster stack backing O2CB [o2cb]:
Cluster to start on boot (Enter “none” to clear) [ocfs2]: myrac
Specify heartbeat dead threshold (>=7) [31]:
Specify network idle timeout in ms (>=5000) [30000]:
Specify network keepalive delay in ms (>=1000) [2000]:
Specify network reconnect delay in ms (>=2000) [2000]:
Writing O2CB configuration: OK
Starting O2CB cluster myrac: OK
[root@mylinux1 etc]#

[root@mylinux2 etc]# /etc/init.d/o2cb configure
Configuring the O2CB driver.

This will configure the on-boot properties of the O2CB driver.
The following questions will determine whether the driver is loaded on
boot. The current values will be shown in brackets (‘[]’). Hitting
without typing an answer will keep that current value. Ctrl-C
will abort.

Load O2CB driver on boot (y/n) [n]: y
Cluster stack backing O2CB [o2cb]:
Cluster to start on boot (Enter “none” to clear) [ocfs2]: myrac
Specify heartbeat dead threshold (>=7) [31]:
Specify network idle timeout in ms (>=5000) [30000]:
Specify network keepalive delay in ms (>=1000) [2000]:
Specify network reconnect delay in ms (>=2000) [2000]:
Writing O2CB configuration: OK
Loading filesystem “configfs”: OK
Mounting configfs filesystem at /sys/kernel/config: OK
Loading filesystem “ocfs2_dlmfs”: OK
Creating directory ‘/dlm’: OK
Mounting ocfs2_dlmfs filesystem at /dlm: OK
Starting O2CB cluster myrac: OK
[root@mylinux2 etc]#


This completes configuration of OCFS2 for Oracle RAC.

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

Download and Installation of OCFS2 RPMs for Linux

Oracle Cluster File System 2 (OCFS2) is a file system which allows for multiple hosts to access the same files on a shared storage at the same time. This type of access is required for deployment of an Oracle RAC system. In this article we will cover the procedure to download and install the RPMs for OCFS2 to support shared storage on an Oracle RAC system.

1. Determine the current Kernel installed on all RAC nodes. NOTE: The kernels must be the same on every RAC node.

NODE 1:
[root@mylinux1 etc]# uname -r
2.6.18-194.32.1.el5
[root@mylinux1 etc]#

NODE2:
[root@mylinux2 ~]# uname -r
2.6.18-194.32.1.el5
[root@mylinux2 ~]#

2. Go to the URL: http://oss.oracle.com/projects/ocfs2/ , select the download tab and navigate to the correct rpm download for your kernel.

2.6.18-194.32.1.el5
2011.01.20
Packages for RHEL5 2.6.18-194.32.1.el5

3. Go to the URL: http://oss.oracle.com/projects/ocfs2-tools/, select the download tab and navigate to the correct rpm downloads for your OS. Example for this OS we download the following files:

ocfs2-tools-1.4.4-1.el5.x86_64.rpm
2010.04.19 7a2f59a05f2cf1bea24dc04f34b09371
OCFS2 tools
ocfs2-tools-debuginfo-1.4.4-1.el5.x86_64.rpm
2010.04.19 91d6e65e902dedcd28e8e4f2d9fb4271
OCFS2 tools debuginfo
ocfs2-tools-devel-1.4.4-1.el5.x86_64.rpm
2010.04.19 2e47beaab89ebba8b1d276fb894184d5
OCFS2 tools libraries/header
ocfs2console-1.4.4-1.el5.x86_64.rpm
2010.04.19 78ccf0cf8564a6d5b48d534c7f3a07bc

4. Once the download completes transfer all the files to all nodes in the cluster. It is best at this point to create a temporary directory under /tmp, to store your files with the following command.

[root@mylinux1 tmp]# mkdir oracle_tmp
[root@mylinux1 tmp]# chmod 777 oracle_tmp
[root@mylinux1 tmp]#

5. Once the files are in location, logon as root and install using the rpm command on all nodes of the RAC.

rpm -Uvh ocfs2-tools-1.4.4-1.el5.x86_64.rpm
rpm -Uvh ocfs2-2.6.18-194.32.1.el5-1.4.7-1.el5.x86_64.rpm
rpm –Uvh ocfs2console-1.4.4-1.el5.x86_64.rpm

[root@mylinux1 oracle_tmp]# rpm -Uvh ocfs2-tools-1.4.4-1.el5.x86_64.rpm
warning: ocfs2-tools-1.4.4-1.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing… ########################################### [100%]
1:ocfs2-tools ########################################### [100%]
[root@mylinux1 oracle_tmp]# rpm -Uvh ocfs2-2.6.18-194.32.1.el5-1.4.7-1.el5.x86_64.rpm
warning: ocfs2-2.6.18-194.32.1.el5-1.4.7-1.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing… ########################################### [100%]
1:ocfs2-2.6.18-194.32.1.el########################################### [100%]
[root@mylinux1 oracle_tmp]# rpm -Uvh ocfs2console-1.4.4-1.el5.x86_64.rpm
warning: ocfs2console-1.4.4-1.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing… ########################################### [100%]
1:ocfs2console ########################################### [100%]
[root@mylinux1 oracle_tmp]#

This completes the download and installation of OCFS2 on Linux to support an Oracle RAC system.

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

Oracle Installation – Add swap space in UNIX or Linux environment

The typical Oracle installation will require more swap space on a system, due to prerequisite checks performed by the installer, than is typical available. The following procedure shows how to create additional swap in Unix or Linux.

1. Create a file on /u01 of 12gb with the dd command. NOTE: Repeat on each RAC node.

dd if=/dev/zero of=/u01/tempswap bs=1k count=12000000

Example:

[root@mylinux1 ~]# dd if=/dev/zero of=/u01/tempswap bs=1k count=12000000
12000000+0 records in
12000000+0 records out
12384000000 bytes (12 GB) copied, 64.2111 seconds, 255 MB/s
[root@mylinux1 ~]#

2. Then format your new file with the mke2fs command. NOTE: Repeat on each RAC node.

/sbin/mke2fs /u01/tempswap

Example:

[root@mylinux1 ~]# /sbin/mke2fs /u01/tempswap
mke2fs 1.39 (29-May-2006)
/u01/tempswap is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2003424 inodes, 4000000 blocks
200000 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4097835008
123 block groups
32768 blocks per group, 32768 fragments per group
12288 inodes per group
Superblock backups stored on blocks:
32768, 98304, 123840, 229376, 294912, 819200, 884736, 1205632, 2654208

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@mylinux1 ~]#

3. Make the additional swap space with the mkswap command. NOTE: Repeat on each RAC node.

/sbin/mkswap /u01/tempswap

Example:

[root@mylinux1 ~]# /sbin/mkswap /u01/tempswap
Setting up swapspace version 1, size = 12383995 kB
[root@mylinux1 ~]#

4. Make the swap space available to the OS with the command swapon. NOTE: This will have to be executed after every reboot. Repeat on each RAC node.

/sbin/swapon /u01/tempswap

Example:

[root@mylinux1 ~]# /sbin/swapon /u01/tempswap
[root@mylinux1 ~]#

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