Wednesday, January 13, 2010

Manual Database creation

Creating an Oracle 10g database from the command line only
This article is the successor to Creating an Oracle 9i database on NT from the command line only. There are basically three ways to create an Oracle database:

•Using the Database Configuration Assistant (DBCA)
•With the SQL create database statement
•Through upgrading an existing database.

This article focuses on the second option. It can be completed on the command line only, that is, without any GUI tool. Also, the article is a bit biased towards Windows and its command prompt (cmd.exe: start->run->cmd). Specifying the Instance's SID
There can be more than one Oracle instance on a single machine. In order to be able to distinguish these instances, Oracle uses a SID (System Identifier) which is a string. The SID can be set through the ORACLE_SID environment variable.

D:\oracle\product\10.1.0>set ORACLE_SID=ORA10
Creating an Oracle Service
On Windows, each instance requires a Windows service. This service must first be created with oradim: D:\oracle\product\10.1.0\Db_1>oradim -new -sid %ORACLE_SID% -intpwd MYSECRETPASSWORD -startmode M
Instance created.

It can be verified that a Windows service was created by typing services.msc into the console. A service named OracleServiceORA10 (ORA10 = %ORACLE_SID%) will be found. Also, the startup type is manual as was requested by -startmode M. Oracle also created a password file under %ORACLE_HOME%\database: D:\oracle\product\10.1.0\Db_1>dir database
Volume in drive D has no label.

As can be seen, the SID is in the password file's name. Creating the initialization parameter file
When an Oracle instance starts up, it requires either an initialization paramter file (init.ora) or an SPFILE. SPFILES have binary content and must be created from init.ora files. Therefore, the init.ora file (which is an ordianary text file) is created first. Here's a minimal init.ora (under $ORACLE_HOME/dbs if it is Unix, or %ORACLE_HOME%\database, if it is windows) just to demonstrate how the control files are found. Of course, you will add more init params into the init.ora file. D:\oracle\product\10.1.0\Db_1\database\initORA10.ora
control_files = (d:\oracle\databases\ora10\control01.ora,
undo_management = auto
db_name = ora10
db_block_size = 8192
The undo_management parameter is necessary if we want to use automatic undo management. Although the above seems to be the bare required minimum, you probably also want do define background_dump_dest, core_dump_dest and user_dump_dest. Starting the instance
Now, that we have created an Oracle service and the init.ora file, we're ready to start the instance: D:\oracle\product\10.1.0\Db_1>sqlplus /nolog

SQL*Plus: Release - Production on Sat Mar 5 16:05:15 2005

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

SQL> connect sys/MYSECRETPASSWORD as sysdba
Connected to an idle instance.
SQL*Plus tells us that we're connected to an idle instance. That means that it is not yet started. So, let's start the instance. We have to start the instance without mounting (nomount) as there is no database we could mount at the moment. SQL> startup nomount
ORACLE instance started.

Total System Global Area 113246208 bytes
Fixed Size 787708 bytes
Variable Size 61864708 bytes
Database Buffers 50331648 bytes
Redo Buffers 262144 bytes
This created the SGA (System Global Area) and the background processes. Creating the database
We're now ready to finally create the database: SQL>create database ora10
logfile group 1 ('D:\oracle\databases\ora10\redo1.log') size 10M,
group 2 ('D:\oracle\databases\ora10\redo2.log') size 10M,
group 3 ('D:\oracle\databases\ora10\redo3.log') size 10M
character set WE8ISO8859P1
national character set utf8
datafile 'D:\oracle\databases\ora10\system.dbf'
size 50M
autoextend on
next 10M maxsize unlimited
extent management local
sysaux datafile 'D:\oracle\databases\ora10\sysaux.dbf'
size 10M
autoextend on
next 10M
maxsize unlimited
undo tablespace undo
datafile 'D:\oracle\databases\ora10\undo.dbf'
size 10M
default temporary tablespace temp
tempfile 'D:\oracle\databases\ora10\temp.dbf'
size 10M;
If something goes wrong with the creation, Oracle will write an error into the alert.log. The alert log is normaly found in the directory that is specified with the background_dump_dest. If this parameter was not specified (as is the case in our minimal init.ora), the alert.log will be written into %ORACLE_HOME%/RDMBS/trace. If an ORA-01031: insufficient privileges is returned, that means most likely, that the current user is not in the dba group (on unix), or the ORA_DBA (windows). If the init.ora file is not at its default location or has not been found with the pfile attribute, an ORA-01078: failure in processing system parameters and an LRM-00109: could not open parameter file '/appl/oracle/product/' error is issued. The create database command also executes a file whose name is determined by the (hidden) init parameter _init_sql_file (which seems to default to sql.bsq) After the creation of the database, it can be mounted and opened for use. Completing the DB creation
In order to complete the db creation, the following scripts must be run as sys:
•%ORACLE_HOME%/rdbms/admin/catproc.sql and
SQL*Plus provides a shortcut to refer to the ORACLE_HOME directory: the question mark (?). Therefore, these scripts can be called like so: SQL> @?/rdbms/admin/catalog.sql
SQL> @?/rdbms/admin/catproc.sql
catalog.sql creates the data dictionary. catproc.sql creates all structures required for PL/SQL.

Now the Dataabse is ready for use..!

No comments:

Post a Comment