|René Nyffenegger's collection of things on the web|
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
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:
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->
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.
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
D:\oracle\product\10.1.0\Db_1>dir database Volume in drive D has no label. Volume Serial Number is C4E9-469A Directory of D:\oracle\product\10.1.0\Db_1\database 03/05/2005 03:54 PM <DIR> . 03/05/2005 03:54 PM <DIR> .. 03/05/2005 11:16 AM <DIR> archive 03/05/2005 11:13 AM 31,744 oradba.exe 03/05/2005 03:54 PM 2,560 PWDORA10.ORA
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.
control_files = (d:\oracle\databases\ora10\control01.ora, d:\oracle\databases\ora10\control02.ora, d:\oracle\databases\ora10\control03.ora) undo_management = auto db_name = ora10 db_block_size = 8192
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 10.1.0.2.0 - 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
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/188.8.131.52/dbs/initadpdb.ora' 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
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:
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.
catalog.sql calls, for example, catexp.sql which is a requirement for exp, or dbmsstdx.sql which is a requirement to create triggers.
The user system might also want to run ?/sqlplus/admin/pupbld.sql. pupbld.sql creates a table that allows to block someone from using sql plus.
SQL> connect system/manager SQL> @?/sqlplus/admin/pupbld
Of course, tablespaces, users, tables and so on must be created according to the use of the database.
Setting up database to using java
Also call @?/javavm/install/initjvm if you want to enable the JServer option(?).
Oracle managed files
Errors while creating database
If there is an error while the database is created, such as a ORA-01092: ORACLE instance terminated. Disconnection forced, the alert log should be consulted. This file most probably contains a more desriptive error message.
If the error occurs at a very early stage, there won't be an alert.log. In this case, the error will most probably be found in a trace file in udump directory.