三、新建主库(主机vmone)
3.1 准备主库初始化参数
$ vi $ORACLE_HOME/dbs/init$ORACLE_SID.ora
#以下为建库必需参数
control_files='/orahome/oradata/WENDING/control01.ctl','/orahome/oradata/WENDING/control02.ctl','/orahome/oradata/WENDING/control03.ctl'
db_block_size = 8192
db_name = ORCLDB
db_unique_name = WENDING
sga_max_size = 256M
sga_target = 256M
undo_management = AUTO
undo_tablespace = UNDOTBS1
#以下为一般建库需设置的参数,不设置就采用默认值
audit_file_dest = /u01/app/oracle/admin/WENDING/adump
background_dump_dest = /u01/app/oracle/admin/WENDING/bdump
core_dump_dest = /u01/app/oracle/admin/WENDING/cdump
user_dump_dest = /u01/app/oracle/admin/WENDING/udump
db_domain = LK
db_recovery_file_dest=/orahome/flash_recovery_area
db_recovery_file_dest_size=2G
job_queue_processes = 10
log_archive_format = 'log_%t_%s_%r.arc'
open_cursors = 1500
processes = 500
undo_retention = 10800
audit_sys_operations = TRUE #如果需要开通审计功能需设置
audit_trail = os #这里注意,如果将来会转换成物理备库,这里就不能设置db,否则将来物理备库没法打开read only模式
#以下为建备库必需的设置,每增加一个备库,就在log_archive_config里增加备库的db_unique_name,并后续增设一个log_archive_dest_x参数
remote_login_passwordfile='EXCLUSIVE'
log_archive_config='DG_CONFIG=(WENDING,PHYSTDBY,LOGSTDBY)'
log_archive_dest_1='LOCATION=/orahome/arch/WENDING VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=WENDING'
log_archive_dest_state_1='ENABLE'
3.2 建立密码文件,一定是要用格式orapw<SID>
$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=iamwangnc force=y
3.3 建spfile,启动实例并开始建库
$ sqlplus '/as sysdba'
SQL> create spfile from pfile='$ORACLE_HOME/dbs/init$ORACLE_SID.ora';
SQL> startup nomount
SQL> create database ORCLDB controlfile reuse
character set ZHS16GBK national character set AL16UTF16
logfile group 1 ('/orahome/oradata/WENDING/redo1.log') size 50M reuse,
group 2 ('/orahome/oradata/WENDING/redo2.log') size 50M reuse,
group 3 ('/orahome/oradata/WENDING/redo3.log') size 50M reuse
datafile '/orahome/oradata/WENDING/system.dbf' size 500M reuse autoextend on next 10M maxsize unlimited extent management local
sysaux datafile '/orahome/oradata/WENDING/sysaux.dbf' size 100M autoextend on next 10M maxsize unlimited
default temporary tablespace temp tempfile '/orahome/oradata/WENDING/temp01.dbf' size 100M reuse autoextend on next 10M maxsize unlimited
undo tablespace undotbs1 datafile '/orahome/oradata/WENDING/undotbs1.dbf' size 100M reuse autoextend on next 10M maxsize unlimited
user sys identified by "iamwangnc" user system identified by "iamwangnc";
3.4 运行数据字典脚本,其中catalog.sql和catproc.sql是必需的,其它可选
SQL> spool /orahome/cat.log
SQL> @?/rdbms/admin/catalog.sql (建数据字典视图)
SQL> @?/rdbms/admin/catproc.sql (建存储过程包)
SQL> @?/rdbms/admin/catblock.sql (建锁相关的几个视图)
SQL> @?/rdbms/admin/catoctk.sql (建密码工具包dbms_crypto_toolkit)
SQL> @?/rdbms/admin/owminst.plb (建工作空间管理相关对象,如dmbs_wm)
SQL> spool off
3.5 新建sqlplus属性和帮助、USERS表空间、EM资料库
SQL> connect system/iamwangnc
SQL> @?/sqlplus/admin/pupbld.sql
SQL> @?/sqlplus/admin/help/hlpbld.sql helpus.sql
SQL> connect /as sysdba
SQL> CREATE TABLESPACE USERS LOGGING DATAFILE '/orahome/oradata/WENDING/users01.dbf' SIZE 100M REUSE AUTOEXTEND ON NEXT 10m MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
SQL> ALTER DATABASE DEFAULT TABLESPACE USERS;
建立和配置EM资料库(可选):
SQL> @?/sysman/admin/emdrep/sql/emreposcre /u01/app/oracle/product/10.2.0/db_1 SYSMAN iamwangnc TEMP ON;
3.6. 最后修改为归档模式并重启
SQL> shutdown immediate;
SQL> connect /as sysdba
SQL> startup mount;
SQL> alter database archivelog;
SQL> alter database open;
重新编译所有失效过程:
SQL> execute utl_recomp.recomp_serial();
配置EM(可选):
SQL> alter user SYSMAN identified by "iamwangnc" account unlock;
SQL> alter user DBSNMP identified by "iamwangnc" account unlock;
SQL> exit
$ emca -config dbcontrol db -silent -DB_UNIQUE_NAME WENDING -PORT 1521 -EM_HOME /u01/app/oracle/product/10.2.0/db_1 -LISTENER LISTENER -SERVICE_NAME WENDING.LK -SYS_PWD iamwangnc -SID WENDING -ORACLE_HOME /u01/app/oracle/product/10.2.0/db_1 -DBSNMP_PWD iamwangnc -HOST game -LISTENER_OH /u01/app/oracle/product/10.2.0/db_1 -LOG_FILE /u01/app/oracle/product/10.2.0/db_1/log/emConfig.log -SYSMAN_PWD iamwangnc
到此建库完毕!
3.6 查询主库信息
$ sqlplus '/as sysdba'
SQL> select name,database_role,db_unique_name,open_mode,protection_mode,protection_level,switchover_status,supplemental_log_data_pk,supplemental_log_data_ui from v$database;
NAME DATABASE_ROLE DB_UNIQUE_NAME OPEN_MODE PROTECTION_MODE PROTECTION_LEVEL SWITCHOVER_STATUS SUP SUP
-------- ---------------- ------------------------------ ---------- -------------------- -------------------- -------------------- --- ---
ORCLDB PRIMARY WENDING READ WRITE MAXIMUM PERFORMANCE MAXIMUM PERFORMANCE SESSIONS ACTIVE NO NO
SQL> archive log list;
数据库日志模式 存档模式
自动存档 启用
存档终点 /orahome/arch/WENDING
最早的联机日志序列 10
下一个存档日志序列 12
当前日志序列 12
--End--
from:http://hi.baidu.com/edeed/blog/item/e879269733c1276a55fb961f.html