Junior DBA Interview Question

With well over a decade of Oracle experience from version 6 to 11g, I have had my share of interviewing prospective DBA employees in a range from Junior to Senior DBAs. Needless to say in this field, technical competence is the key to any new hire and early on I made the blunder of not asking the write questions during the interview. I am sure every senior person or manager has made this mistake and had to deal with either training the person from scratch or letting them go. Either of these options is not desirable in our fast past business would. So, I decided to write a couple of articles which cover what I believe a Junior, Mid, and Senior Oracle DBA should know to fill their prospective positions.

In this article we will cover what a Junior DBA should know to be successful. If you have any comments or questions, please email me at larry.catt@relidb.com.

Questions:

1. Give the three modes of starting an oracle database and explain each?
2. Give the three modes of shutting down an Oracle database and explain each?
3. Who can start and stop an Oracle database
4. How do you create a user account in an Oracle database?
5. How do you delete a user account in an Oracle database?
6. Explain the difference between an Oracle database and Oracle instance?
7. Name three physical objects that can be seen from the OS layer of Database Server?
8. Name two Oracle OS layer processes?
9. What is the utility to write an Oracle database to an OS layer file?
10. What is the utility to read an Oracle database to an OS layer file?

Answers:

1. Give the three modes of starting an oracle database and explain each?

Startup nomount – The pfile or initfile is read and memory realm is started.

Startup mount –The controlfile is read and files verified.

Startup –The datafiles are opened in read/write mode and the database is open in read/write mode.

2. Give the three modes of shutting down an Oracle database and explain each?

Shutdown – All new connections are refused, current connections are maintained until the users log off, and once all user connections are completed the database shuts down.

Shutdown immediate – All new connections are refused, all current connection activities are rolled back and disconnected, the database shuts down.

Shutdown abort – All connections are disconnected without roll back and the database shuts down.

3. Who can start and stop an Oracle database?

– The SYS user or any user with sysdba privileges can shutdown an Oracle database.

4. How do you create a user account in an Oracle database?

– Create user ‘username’ identified by ‘password’;

5. How do you delete a user account and all objects owned by that user in an Oracle database?

– Drop user ‘username’ cascade;

6. Explain the difference between an Oracle database and Oracle instance?

-Oracle database includes all of the physical objects of an Oracle environment which reside at the OS layer.

-Oracle Instance is the memory realm and OS processes of the Oracle environment.

7. Name three physical objects that can be seen from the OS layer of Database Server?

-controlfiles
-datafiles
-tempfiles
-redo logs
-archive redologs

8. Name two Oracle OS layer processes?

-PMON
-SMON
-ARCN
-MMON
-MMNL
-MMAN
-LGWR
-CKPT

9. What is the utility to write an Oracle database to an OS layer file?

-EXP or export in any version of Oracle.
-EXPDP or export data pump in Oracle 10g or higher

10. What is the utility to read an Oracle database to an OS layer file?

-IMP or import in any version of Oracle.
-IMPDP or import data pump in Oracle 10g or higher

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

Oracle – Use of UTL_FILE to read external OS file into Oracle RDBMS.

Oracle – Use of UTL_FILE to read external OS file into Oracle RDBMS.

Oracle provides the procedure UTL_FILE to allow for the reading of external OS layer files from within the Oracle RDBMS. This article will give an example of how to read the contents of an external OS file and display it in the Oracle database.

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

2. Create a file called read.txt with the following text.

This is line one.

3. Logon to SQL*PLUS with an account which has DBA privileges. In this example we are using the account LJCATT.

mylinux:> sqlplus ljcatt

SQL*Plus: Release 10.2.0.4.0 – Production on Thu Jan 29 23:28:23 2009

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

Enter password:

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>

4. Create the procedure read_file as detailed below.

create or replace procedure read_file
is

v_record varchar2(50);
v_file varchar2(30) := ‘read.txt’;
v_dir varchar2(512) := ‘/home/lufsora’;
v_write utl_file.file_type;
begin

v_write:=utl_file.fopen(v_dir, v_file, ‘r’, 2000);

utl_file.get_line(v_write,v_record, v_record);

dbms_output.put_line(v_record);

utl_file.fclose(v_write);

end read_file;
/

5. Execute the procedure read_file with the command execute and the test within the OS file will be display.

SQL> execute read_file;
This is line one.

PL/SQL procedure successfully completed.

SQL>

This completes the use of UTL_FILE to read OS level files into your Oracle RDBMS.

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

Upgrade of Oracle 9i RDBMS to 10g RDBMS

Oracle provides upgrade paths for most RDBMS versions, however they are not as simple as some would like. I have ran into several Junior to Mid-level DBA’s who appear to have a difficult time grasping the general steps required to perform this task or just want a Senior person present for them to perform sanity checks with. Thus, I have decided to outline the general steps required to perform the upgrade from 9i to 10g.

1. Downloading the following software from www.oracle.com if you do not have the media available:

• Oracle 10.2.0.1 (this is the base release of Oracle 10g R2)
• Oracle 10.2.0.1 Companion CD (if needed)
• Oracle 10.2.0.4 (This is patch set 6810189)
• Latest Oracle CPU Patch

2. Shutdown your current Oracle 9i database system and listener. Do not delete any of the 9i binaries or database objects.

$ sqlplus ” / as sysdba”
SQL> shutdown immediate
SQL> exit
$
$ cd network/admin
$ lsnrctl stop LISTENER

3. Unpack or Unzip (dependent on OS) your 10.2.0.1 database installation. Execute the runInstaller. Note: It is most likely that your OS will be of a higher version, than is supported by this installer. You may have to use the tags “–jreLoc –ignoreSysPrereqs” to bypass the OS support version. Example:

./runInstaller -jreLoc /opt/java1.4/jre -ignoreSysPrereqs

4. At the Welcome to the Oracle Database 10g Installation page, check the Advanced Installation option and press Next.

5. At the Select Installation Type page, select Enterprise Addition and press Next.

6. At the Specify Home Details page, enter OraDb10g for Name and /app/oracle/10.2.0 for the path and press Next.

7. At the Product-Specific Prerequisite Checks page the Installer will verify the system is ready for installation.

8. At the Product-Specific Prerequisite Checks, review any warning received and press Next.

9. At the Upgrade an Existing Database page, select No and press next.

10. At the Select Configuration Options page, select Install Database Software Only and press Next.

11. At the Summary page, press Install.

12. Once the installer request for you to execute shell script root.sh, contact the SA support for your system and have them execute, then click OK.

13. Record the following output in a safe place and click Exit.

The following J2EE Applications have been deployed and are accessible at the
URLs listed below.
iSQL*Plus URL:
http://linux1:5560/isqlplus
iSQL*Plus DBA URL:
http://linux1:5560/isqlplus/dba

14. This completes Installation of 10.2.0.1 software.

15. Install Oracle companion component. (if desired)

16. Upgrade to 10.2.0.4, unzip the Oracle patch set 6810189 and execute the runInstaller utility. NOTE: You may again have to user the –jreLoc and –ignoreSysPrereqs tags. Example

./runInstaller -jreLoc /opt/java1.4/jre -ignoreSysPrereqs

17. At the Welcome page, select Next.

18. At the Specify Home Details page, enter OraDb10g in Name and /app/oracle/10.2.0 in Path and press Next

19. At the Product-Specific Prerequisite Checks page, press Next.

20. At the Oracle Configuration Manager Registration page, press Next.

21. At the Summary page, press Install.

22. Once requested to execute the script: app/oracle/10.2.0/root.sh, contact the SA and have them execute as root, then press OK.

23. At the End of Installation page, record the below information and press Exit.

The iSQL*Plus URL is:
http://linux1:5560/isqlplus

The iSQL*Plus DBA URL is:
http://linux1:5560/isqlplus/dba

24. At the screen ‘Do you really want to exit?’, press Yes.

25. This completes the upgrade to 10.2.0.4

26. Apply latest CPU patch. Logon to Metalink at metalink.oracle.com and download the latest CPU patch for Oracle 10.2.0.4. In this example, we will download CPU Jan 2009 – patch number 7592346

27. Unzip the patch file.

28. Ensure that the ORACLE_HOME parameter is point to 10.2.0.4 install by setting the parameter again.

Linux1:/oracle_software/7592346:>echo $ORACLE_HOME
/app/oracle/10.2.0
Linux1:/oracle_software/7592346:>

29. Edit your .profile file to ensure that OPATCH parameter is pointing at the correct OPatch directory and your PATH parameter is specifying the correct $ORACLE_HOME/bin directory. NOTE: The OPatch utility installed with 10.2.0.1 maybe too old for your CPU patch, see the README in your CPU to determine the correct OPatch version to use. You can navigate to $ORACLE_HOME/OPatch and execute the command “opatch version” to determine you current version.

30. Note: you may have to user the -jre tag to make the patch work.

opatch napply -skip_subset -skip_duplicate -jre /opt/java1.4/jre

or
$ORACLE_HOME/OPatch/opatch napply -skip_subset -skip_duplicate -jre
/opt/java1.4/jre

31. This completes installation of the latest CPU patch.

Post installation Steps

32. Update the .profile file to point to the new Oracle installation and make sure the following environment variables point to the new ORACLE installation.

ORACLE_HOME
PATH
LD_LIBRARY_PATH
SH_LIB_PATH

33. Logout and login to reset your environment variables.

34. Copy the init.ora file from existing 9.2.0.8 $ORACLE_HOME/dbs to 10g $ORACLE_HOME/dbs folder

Linux1:/app/oracle/9.2.0.8.0/dbs:>cp initorcl.ora ../../10.2.0/dbs/.
Linux1:/app/oracle/9.2.0.8.0/dbs:>

35. NOTE: See listing at bottom of this article for all non-supported 9i init parameters which must be removed or commented out.

36. Increase large pool size=200M in init.ora file.

37. Change folders to $ORACLE_HOME/rdbms/admin/. This is the folder where the SQL files for upgrade are stored.

$ cd $ORACLE_HOME/rdbms/admin

38. Start the database in upgrade mode

$>sqlplus / as sysdba
SQL>startup upgrade

39. Create sysaux tablespace

Ex:CREATE TABLESPACE sysaux DATAFILE
‘/orcl/oradata/orcl/data1/sysaux02.dbf’ SIZE 4096M REUSE EXTENT
MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ONLINE;

40. Issue unlimited quota for system

ALTER USER SYSTEM QUOTA UNLIMITED ON system;

41. Start the upgrade by running catupgrd.sql

SQL> spool /scripts/upgrade.log
SQL> @catupgrd.sql
Turn off the spooling of script results to the log file:
SQL> SPOOL OFF

Check the spool file and verify that the packages and procedures compiled successfully. You named the spool file earlier in this step; the suggested name was upgrade.log. Correct any problems you find in this file and rerun the appropriate upgrade script if necessary. You can rerun any of the scripts described in this note as many times as necessary.

42. Run utlu102s.sql, specifying the TEXT option:

SQL> @utlu102s.sql TEXT

43. Insure that all temp files from the production system are attached to temporary tablespace in converted database. If not recreate temp files.

Example:
alter tablespace TEMP add tempfile ‘/orcl/oradata/orcl/data1/temp_01.dbf’
size 2048m;

44. Run utlrp.sql to recompile any remaining stored PL/SQL and Java code.

SQL> @utlrp.sql

Verify that all expected packages and classes are valid:

45. If there are still objects which are not valid after running the script run
the following:

spool invalid_post.lst
Select substr(owner,1,12) owner,
substr(object_name,1,30) object,
substr(object_type,1,30) type, status
from dba_objects where status <>‘VALID’;
spool off

46. Copy old listeners.ora and tnsnames.ora from the previous 9.2.0.8 oracle installation and update their ORACLE_HOME references.
• Copy files to new ORACLE_HOME/network/admin folder
cp listener.ora $ORACLE_HOME/network/admin
cp tnsnames.ora $ORACLE_HOME/network/admin
• Change folders to $ORACLE_HOME/network/admin
cd $ORACLE_HOME/network/admin
• Update the newly copied files to point to the new ORACLE_HOME location

47. Restart the database in a normal mode with “startup open”

48. It is a good idea to know rebuild all of your indexes and gather statistics.

49. NOTE: You will not get all of the benefits of Oracle 10g until you set the COMPATIBILITY parameter to a minimum of 10.1

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

Appendix A: Initialization Parameters Obsolete in 10g
—————————————————–

ENQUEUE_RESOURCES
DBLINK_ENCRYPT_LOGIN
HASH_JOIN_ENABLED
LOG_PARALLELISM
MAX_ROLLBACK_SEGMENTS
MTS_CIRCUITS
MTS_DISPATCHERS
MTS_LISTENER_ADDRESS
MTS_MAX_DISPATCHERS
MTS_MAX_SERVERS
MTS_MULTIPLE_LISTENERS
MTS_SERVERS
MTS_SERVICE
MTS_SESSIONS
OPTIMIZER_MAX_PERMUTATIONS
ORACLE_TRACE_COLLECTION_NAME
ORACLE_TRACE_COLLECTION_PATH
ORACLE_TRACE_COLLECTION_SIZE
ORACLE_TRACE_ENABLE
ORACLE_TRACE_FACILITY_NAME
ORACLE_TRACE_FACILITY_PATH
PARTITION_VIEW_ENABLED
PLSQL_NATIVE_C_COMPILER
PLSQL_NATIVE_LINKER
PLSQL_NATIVE_MAKE_FILE_NAME
PLSQL_NATIVE_MAKE_UTILITY
ROW_LOCKING
SERIALIZABLE
TRANSACTION_AUDITING
UNDO_SUPPRESS_ERRORS

Appendix B: Initialization Parameters Deprecated in 10g
——————————————————-

LOGMNR_MAX_PERSISTENT_SESSIONS
MAX_COMMIT_PROPAGATION_DELAY
REMOTE_ARCHIVE_ENABLE
SERIAL_REUSE
SQL_TRACE
BUFFER_POOL_KEEP (replaced by DB_KEEP_CACHE_SIZE)
BUFFER_POOL_RECYCLE (replaced by DB_RECYCLE_CACHE_SIZE)
GLOBAL_CONTEXT_POOL_SIZE
LOCK_NAME_SPACE
LOG_ARCHIVE_START
MAX_ENABLED_ROLES
PARALLEL_AUTOMATIC_TUNING
PLSQL_COMPILER_FLAGS (replaced by PLSQL_CODE_TYPE and PLSQL_DEBUG)

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

Oracle – ORA-00604: error occurred at recursive SQL level 1 and revoking a user privileges.

A schema is considered all of the objects owned by a single user within the Oracle database. When a user has a privilege revoked in the database, but owns a particular object which requires that privilege, errors will result. This article will recover an error which will result from a user having a privilege revoked which is require by one of the objects he owns.

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

2. Logon to SQLPLUS with SYSDBA privileges.

mylinux:> sqlplus ‘/ as sysdba’

SQL*Plus: Release 10.2.0.4.0 – Production on Sat Jan 17 11:00:09 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>

3. Create the user LJCATT and grant him the DBA role and create procedure privileges.

SQL> create user ljcatt identified by password10;

User created.

SQL> grant dba to ljcatt;

Grant succeeded.

SQL> grant execute on utl_file to ljcatt;

Grant succeeded.

4. Connect as the user ljcatt and create a procedure named test_file.

SQL> connect ljcatt
Enter password:
Connected.

SQL> create or replace procedure test_file
is
2 3 v_record varchar2(50) := ‘Testing file creation’;
4 v_file varchar2(30) := ‘testfile’;
5 v_dir varchar2(100) := ‘/home/lcatt’;
6 v_write utl_file.file_type;
7 begin
8
9 v_write := utl_file.fopen(v_dir, v_file, ‘w’, 4000);

10 11 –utl_file.fopen(v_dir, v_file, ‘w’, 100);
12
13 utl_file.put_line(v_write, v_record);

14 15 utl_file.fclose(v_write);
16
17 end test_file;
/ 18

Procedure created.

5. Reconnect to the database with SYSDBA privileges and revoke the DBA from ljcatt and grant the create session privilege. Then attempt to reconnect as the user LJCATT.

SQL> connect / as sysdba
Connected.
SQL> revoke dba from ljcatt;

Revoke succeeded.

SQL> grant create session to ljcatt;

Grant succeeded.

SQL> connect ljcatt
Enter password:
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-00900: invalid SQL statement
ORA-06512: at line 8

Warning: You are no longer connected to ORACLE.

6. NOTE: The error is received due to this user owning objects which he does not have privileges to create or access. This is shown below by reconnecting as SYSDBA and displaying objects owned by the user LJCATT.

SQL> connect / as sysdba
Connected.

SQL> select owner, object_name from dba_objects where object_name like ‘TEST_F%’
and owner=’LJCATT’

OWNER OBJECT_NAME
————————- ————————–
LJCATT TEST_FILE

7. As SYSDBA, re-grant the DBA role to LJCATT and attempt to reconnect.

SQL> grant dba to ljcatt;

Grant succeeded.

SQL> connect ljcatt
Enter password:
Connected.
SQL>

Now that the user LJCATT has the specific privileges required by the objects he owns, he is able to connect without error.

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

Oracle – User does not have permissions on Oracle package UTL_FILE.

Oracle provides the package UTL_FILE to produce OS layer files from within the Oracle RDBMS. Due to this procedures ability to create OS layer files from within the database, its access must be controlled through system privileges. This article will show a common PLS-00201 error, which indicates a lack of access permissions and how to resolve it.

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

2. Create a file called create_file.sql with the following SQL.

create or replace procedure test_file
is

v_record varchar2(50) := ‘Testing file creation’;
v_file varchar2(30) := ‘test_file.txt’;
v_dir varchar2(512) := ‘/home/lcatt’;
v_write utl_file.file_type;
begin

v_write:=utl_file.fopen(v_dir, v_file, ‘w’, 2000);

utl_file.put_line(v_write, v_record);

utl_file.fclose(v_write);

end test_file;
/

3. Logon to SQL*PLUS as the SYSDBA and create the user account LJCATT with the privileges: connect, create session, and resource to LJCATT.

mylinux:> sqlplus ‘/ as sysdba’

SQL*Plus: Release 10.2.0.4.0 – Production on Tue Jan 13 22:26:07 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>

SQL> create user ljcatt identified by ljcatt;

User created.

SQL> grant connect to ljcatt;

Grant succeeded.

SQL> grant create session to ljcatt;

Grant succeeded.

SQL> grant resource to ljcatt;

Grant succeeded.

SQL>

4. Reconnect to SQL*PLUS as LJCATT and execute the file create_file.sql to create your procedure

Mylinux:/home/lcatt:>sqlplus ljcatt

SQL*Plus: Release 10.2.0.4.0 – Production on Tue Jan 13 22:43:17 2009

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

Enter password:

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> set feedback on
SQL> set echo on
SQL>@./create_file.sql

SQL> create or replace procedure test_file
is
2 3
4 v_record varchar2(50) := ‘Testing file creation’;
5 v_file varchar2(30) := ‘test_file.txt’;
6 v_dir varchar2(512) := ‘/home/lcatt’;
7 v_write utl_file.file_type;
8 begin
9
10 v_write:=utl_file.fopen(v_dir, v_file, ‘w’, 2000);
11
12 utl_file.put_line(v_write, v_record);
13
utl_file.fclose(v_write);
14 15
16 end test_file;
17 /

Warning: Procedure created with compilation errors.

SQL> show errors
Errors for PROCEDURE TEST_FILE:

LINE/COL ERROR
——– —————————————————————–
7/9 PL/SQL: Item ignored
7/9 PLS-00201: identifier ‘UTL_FILE’ must be declared
10/1 PL/SQL: Statement ignored
10/1 PLS-00320: the declaration of the type of this expression is
incomplete or malformed

12/1 PL/SQL: Statement ignored
12/19 PLS-00320: the declaration of the type of this expression is
incomplete or malformed

14/1 PL/SQL: Statement ignored

LINE/COL ERROR
——– —————————————————————–
14/17 PLS-00320: the declaration of the type of this expression is
incomplete or malformed

SQL>

5. NOTE: The error received indicates that we do not have permissions to use the package UTL_FILE. Now connect to the database as sydba, execute the grant command: grant execute on utl_file to ljcatt;

SQL> connect / as sysdba
Connected.
SQL> grant execute on utl_file to ljcatt;

Grant succeeded.

SQL>

6. Connect back to the database as the user LJCATT, re-execute the SQL file create_file.sql, and execute the procedure test_file.

SQL> connect ljcatt
Enter password:
Connected.
SQL> create or replace procedure test_file
2 is
3
4 v_record varchar2(50) := ‘Testing file creation’;
5 v_file varchar2(30) := ‘test_file.txt’;
6 v_dir varchar2(512) := ‘/home/lcatt’;
7 v_write utl_file.file_type;
8 begin
9
10 v_write:=utl_file.fopen(v_dir, v_file, ‘w’, 2000);
11
12 utl_file.put_line(v_write, v_record);
13
14 utl_file.fclose(v_write);
15
end test_file;
16 17 /

Procedure created.

SQL> execute test_file

PL/SQL procedure successfully completed.

SQL>

The procedure now compiles without error and executes, due to the owner having proper privileges on the package UTL_FILE.

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

Oracle – ORA-29280: invalid directory path when using UTL_FILE

Oracle provides the package UTL_FILE to produce OS layer files from within the Oracle RDBMS. This article will describe the common error of ORA-29280 which maybe received when using the UTL_FILE procedure and how to resolve it.

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

2. Create a file called create_file.sql with the following SQL.

create or replace procedure test_file
is

v_record varchar2(50) := ‘Testing file creation’;
v_file varchar2(30) := ‘test_file.txt’;
v_dir varchar2(512) := ‘/home/lcatt’;
v_write utl_file.file_type;
begin

v_write:=utl_file.fopen(v_dir, v_file, ‘w’, 2000);

utl_file.put_line(v_write, v_record);

utl_file.fclose(v_write);

end test_file;
/

3. Enter SQL*PLUS, set ECHO and FEEDBACK to on, and execute the file
create_file.sql as a user with DBA privileges. In this example we are using the account LJCATT.

Mylinux:/home/lcatt:>sqlplus ljcatt

SQL*Plus: Release 10.2.0.4.0 – Production on Sat Jan 10 10:43:17 2009

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

Enter password:

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> set feedback on
SQL> set echo on
SQL>@./create_file.sql
SQL> create or replace procedure test_file
2 is
3
4 v_record varchar2(50) := ‘Testing file creation’;
5 v_file varchar2(30) := ‘test_file.txt’;
6 v_dir varchar2(512) := ‘/home/lcatt’;
7 v_write utl_file.file_type;
8 begin
9
10 v_write:=utl_file.fopen(v_dir, v_file, ‘w’, 2000);
11
12 utl_file.put_line(v_write, v_record);
13
14 utl_file.fclose(v_write);
15
16 end test_file;
17 /

Procedure created.

SQL>

4. Use the SQL*PLUS command show to display the initialization parameter utl_file_dir and ensure that the directory /home/lcatt is not present.

SQL> show parameter utl_file_dir

NAME TYPE VALUE
———————————— ———– ——————————
utl_file_dir string /home/lcatt/output
SQL>

5. If the directory is present, remove it with the following command:

SQL> alter system set utl_file_dir=” scope=spfile;

System altered.

SQL>

6. Logon to the database as sysdba and restart your oracle instance.

SQL> connect / as sysdba
Connected.
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup open
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size 2068728 bytes
Variable Size 654315272 bytes
Database Buffers 503316480 bytes
Redo Buffers 48259072 bytes
Database mounted.
Database opened.
SQL>

7. Now logon as the user LJCATT and execute the package test_file with the command execute.

SQL> execute test_file
BEGIN test_file; END;

*
ERROR at line 1:
ORA-29280: invalid directory path
ORA-06512: at “SYS.UTL_FILE”, line 29
ORA-06512: at “SYS.UTL_FILE”, line 448
ORA-06512: at “LJCATT.TEST_FILE”, line 10
ORA-06512: at line 1

SQL>

8. NOTE: The error produced is a result of no reference to the defined directory structure in the initialization parameter UTL_FILE_DIR. This parameter is used to allow the database access to OS layer directories. To resolve this error, connect to the database as sysdba and place the directory path in the initialization parameter UTL_FILE_DIR with the command alter system and restart the database.

SQL> connect / as sysdba
Connected.
SQL> alter system set utl_file_dir=’/home/lcatt’ scope=spfile;

System altered.

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

Total System Global Area 1207959552 bytes
Fixed Size 2068728 bytes
Variable Size 654315272 bytes
Database Buffers 503316480 bytes
Redo Buffers 48259072 bytes
Database mounted.
Database opened.
SQL> show parameter utl_file_dir

NAME TYPE VALUE
———————————— ———– ——————————

utl_file_dir string /home/lcatt

9. Connect back to the database as the user LJCATT and re-execute the procedure test_file.

SQL> connect ljcatt
Enter password:
Connected.
SQL> execute test_file

PL/SQL procedure successfully completed.

SQL>

10. Exit out of SQL*PLUS, change directories to the location of your output file, and perform an ls command to display the file generated.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 –
64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Mylinux:/home/lcatt:>cd /home/lcatt
Mylinux:/home/lcatt:>ls testfile
testfile
Mylinux:/home/lcatt:>

The file was produced under the directory defined by the initialization parameter utl_file_dir and the error ORA-29280 has been resolved.

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

Creating an external file from within the Oracle RDBMS.

Oracle provides the package UTL_FILE to produce OS layer files from within the Oracle RDBMS. This article will show a basic procedure for the producing an OS layer file from within the Oracle RDBMS.

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

2. Create a file called create_file.sql with the following SQL.

create or replace procedure test_file
is

v_record varchar2(50) := ‘Testing file creation’;
v_file varchar2(30) := ‘test_file.txt’;
v_dir varchar2(512) := ‘/home/lcatt’;
v_write utl_file.file_type;
begin

v_write:=utl_file.fopen(v_dir, v_file, ‘w’, 2000);

utl_file.put_line(v_write, v_record);

utl_file.fclose(v_write);

end test_file;
/

3. Enter SQL*PLUS, set ECHO and FEEDBACK to on, and execute the file
create_file.sql.

Mylinux:/home/lcatt:>sqlplus ljcatt

SQL*Plus: Release 10.2.0.4.0 – Production on Sat Jan 03 09:43:17 2009

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

Enter password:

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> set feedback on
SQL> set echo on
SQL>@./create_file.sql
SQL> create or replace procedure test_file
2 is
3
4 v_record varchar2(50) := ‘Testing file creation’;
5 v_file varchar2(30) := ‘test_file.txt’;
6 v_dir varchar2(512) := ‘/home/lcatt’;
7 v_write utl_file.file_type;
8 begin
9
10 v_write:=utl_file.fopen(v_dir, v_file, ‘w’, 2000);
11
12 utl_file.put_line(v_write, v_record);
13
14 utl_file.fclose(v_write);
15
16 end test_file;
17 /

Procedure created.

SQL>

4. Ensure that the system initialization parameter for utl_file_dir contains the directory to which utl_file is going to write with the command show utl_file_dir.

SQL> show parameter utl_file_dir

NAME TYPE VALUE
———————————— ———– ——————————
utl_file_dir string

SQL>

5. If it does not contain the directory, as is the case in step 4, logon to your Oracle database as sysdba and add the directory structure and bounce the database, as seen below:

SQL> connect / as sysdba
Connected.
SQL> alter system set utl_file_dir=’/home/lcatt’ scope=spfile;

System altered.

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

Total System Global Area 1207959552 bytes
Fixed Size 2068728 bytes
Variable Size 654315272 bytes
Database Buffers 503316480 bytes
Redo Buffers 48259072 bytes
Database mounted.
Database opened.
SQL> show parameter utl_file_dir

NAME TYPE VALUE
———————————— ———– ——————————

utl_file_dir string /home/lcatt

SQL>

6. Execute the newly create procedure with the SQL*PLUS command; execute test_file

SQL> execute test_file

PL/SQL procedure successfully completed.

SQL>

7. Exit out of SQL*PLUS and change directory to where you wrote your file.

SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 –
64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Mylinux:/home/lcatt:>cd /home/lcatt
Mylinux:/home/lcatt:>

8. Execute the ls and more command on the file testfile.

Mylinux:/home/lcatt:>ls testfile
testfile
Mylinux:/home/lcatt:>more testfile
Testing file creation
Mylinux:/home/lcatt:>

This completes the creation of external OS layer file from within the Oracle RDBMS.

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

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

Oracle tips and tricks.