Linux下以命令行方式新建oracle数据库实例
承接上次所说,数据库创建好了之后,新建一个数据库实例caacdb。
一、Create database
---------------------------------------------
1. create log dir
$ mkdir -p $ORACLE_BASE/admin/$ORACLE_SID
$ cd $ORACLE_BASE/admin/$ORACLE_SID
$ mkdir adump bdump cdump dpdump hdump pfile udump
2. init file
$ORACLE_BASE/admin/$ORACLE_SID/pfile/init.ora
---------------------------------------------
##############################################################################
# Copyright (c) 1991, 2001, 2002 by Oracle Corporation
##############################################################################
###########################################
# Cache and I/O
###########################################
db_block_size=8192
db_file_multiblock_read_count=16
###########################################
# Cluster Database
###########################################
instance_name=caacdb
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_domain=""
db_name=caacdb
###########################################
# Diagnostics and Statistics
###########################################
background_dump_dest=/opt/app/oracle/admin/caacdb/bdump
core_dump_dest=/opt/app/oracle/admin/caacdb/cdump
user_dump_dest=/opt/app/oracle/admin/caacdb/udump
###########################################
# File Configuration
###########################################
db_recovery_file_dest=/opt/app/oracle/flush_area/caacdb
db_recovery_file_dest_size=2147483648
control_files=("/opt/app/oracle/oradata/caacdb/control01.ctl", "/opt/app/oracle/oradata/caacdb/control02.ctl")
###########################################
# Job Queues
###########################################
job_queue_processes=10
###########################################
# Miscellaneous
###########################################
compatible=10.2.0.1.0
###########################################
# Processes and Sessions
###########################################
processes=150
###########################################
# SGA Memory
###########################################
sga_target=285212672
###########################################
# Security and Auditing
###########################################
audit_file_dest=/opt/app/oracle/admin/caacdb/adump
remote_login_passwordfile=exclusive
###########################################
# Sort, Hash Joins, Bitmap Indexes
###########################################
pga_aggregate_target=94371840
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS
3. create oracle password file
$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle
4. create database
$ sqlplus /nolog
SQL> conn / as sysdba;
SQL> startup nomount pfile="/opt/app/oracle/admin/caacdb/pfile/init.ora";
SQL>
CREATE DATABASE caacdb
MAXINSTANCES 8
MAXLOGHISTORY 16
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 512
DATAFILE '/opt/app/oracle/oradata/caacdb/system01.dbf' SIZE 2048M REUSE
AUTOEXTEND OFF
EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/opt/app/oracle/oradata/caacdb/sysaux01.dbf' SIZE 1024M REUSE
AUTOEXTEND OFF
SMALLFILE DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/opt/app/oracle/oradata/caacdb/temp01.dbf' SIZE 4096M REUSE
AUTOEXTEND OFF
SMALLFILE UNDO TABLESPACE "UNDOTBS" DATAFILE '/opt/app/oracle/oradata/caacdb/undotbs01.dbf' SIZE 10000M REUSE
AUTOEXTEND OFF
CHARACTER SET zhs16cgb231280
NATIONAL CHARACTER SET AL16UTF16
LOGFILE GROUP 1 ('/opt/app/oracle/oradata/caacdb/redo01.log') SIZE 102400K,
GROUP 2 ('/opt/app/oracle/oradata/caacdb/redo02.log') SIZE 102400K,
GROUP 3 ('/opt/app/oracle/oradata/caacdb/redo03.log') SIZE 102400K
USER SYS IDENTIFIED BY "ora"
USER SYSTEM IDENTIFIED BY "ora";
SQL> @?/rdbms/admin/catalog.sql;
SQL> @?/rdbms/admin/catblock.sql;
SQL> @?/rdbms/admin/catproc.sql;
SQL> @?/rdbms/admin/catoctk.sql;
SQL> conn system/oracle;
SQL> @?/sqlplus/admin/pupbld.sql;
SQL> @?/sqlplus/admin/help/hlpbld.sql helpus.sql;
5. Add default user tablespace
SQL> conn sys/oracle as sysdba;
SQL> CREATE SMALLFILE TABLESPACE USERS
LOGGING
DATAFILE '/opt/app/oracle/oradata/caacdb/users01.dbf' SIZE 1000M REUSE
AUTOEXTEND OFF
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;
SQL> ALTER DATABASE DEFAULT TABLESPACE USERS;
6. Create spfile
SQL> create spfile from pfile='/opt/app/oracle/admin/caacdb/pfile/init.ora';
SQL> shutdown immediate;
7. set listener port to other (1521)
$ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = caacdb)
(ORACLE_HOME = /opt/app/oracle/product/10.2.0/db_1)
(SID_NAME = caacdb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST =0.0.0.0)(PORT = 1521))
)
)
$ sqlplus /nolog
SQL> alter system set local_listener="(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))" scope=spfile;
二、Set archive log mode
-----------------------------------------
1. Set Parameter
SQL> alter system set log_archive_format = 'caacdb_%r_%T_%S.ARC' scope=spfile;
**********************************
%s log sequence number
%S log sequence number, zero filled
%t thread number
%T thread number, zero filled
%a activation ID
%d database ID
%r resetlogs ID that ensures unique names are constructed for the archived log files across multiple incarnations of the database
**********************************
SQL> alter system set log_archive_dest_1 = 'LOCATION=USE_DB_RECOVERY_FILE_DEST' scope=spfile;
SQL> alter system set log_archive_dest_2 = 'LOCATION=/oracle/arch/caacdb' scope=spfile;
2. Switch log mode
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list;
3. Test archive log
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> show parameter db_recovery_file_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /oracle/flush_area/caacdb
db_recovery_file_dest_size big integer 2G
$ ls /oracle/arch/caacdb
caacdb_685304034_0001_0000000008.ARC
caacdb_685304034_0001_0000000010.ARC
caacdb_685304034_0001_0000000009.ARC
$ ls -R /oracle/flush_area/caacdb/
/oracle/flush_area/caacdb:
caacdb
/oracle/flush_area/caacdb/caacdb:
archivelog
/oracle/flush_area/caacdb/caacdb/archivelog:
2009_04_27
/oracle/flush_area/caacdb/caacdb/archivelog/2009_04_27:
o1_mf_1_10_4zc8jy8t_.arc o1_mf_1_8_4zc8jg2w_.arc o1_mf_1_9_4zc8jlnd_.arc
三、开启服务
1. 启动数据库:
sqlplus/ as sysdba (连接实例)
startup (启动数据库)
2. 启动监听:
lsnrctl start
验证数据库实例及监听状态: