ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 实习日志第34天---手工建库

实习日志第34天---手工建库

原创 Linux操作系统 作者:大米嗵嗵 时间:2011-03-17 13:34:57 0 删除 编辑

昨天和今天对dbca建库时导出的scripts进行了研究,手工建库过程:

存在一种$ORACLE_HOME/dbs/hc_orcl.dat文件,(和参数文件同目录),大致的作用是记录一些上次实例异常的信息,会被重写

 

 

$ORACLE_BASE/admin/orcl/scripts目录下存在文件。。。。安装代码模版

CreateDBCatalog.sql  CreateDB.sql  init.ora  orcl.sql  CreateDBFiles.sql    emRepository.sql  orcl.sh   postDBCreation.sql

先执行orcl.sh //创建一些需要的目录,设置SID

#!/bin/sh

 

mkdir -p /home/u01/app/oracle/admin/orcl/adump

mkdir -p /home/u01/app/oracle/admin/orcl/bdump

mkdir -p /home/u01/app/oracle/admin/orcl/cdump

mkdir -p /home/u01/app/oracle/admin/orcl/dpdump

mkdir -p /home/u01/app/oracle/admin/orcl/pfile

mkdir -p /home/u01/app/oracle/admin/orcl/udump

mkdir -p /home/u01/app/oracle/oradata

mkdir -p /home/u01/app/oracle/product/10.2.0/cfgtoollogs/dbca/orcl

mkdir -p /home/u01/app/oracle/product/10.2.0/dbs

ORACLE_SID=orcl; export ORACLE_SID

echo You should Add this entry in the /etc/oratab: orcl:/home/u01/app/oracle/product/10.2.0:Y

/home/u01/app/oracle/product/10.2.0/bin/

sqlplus /nolog @/home/u01/app/oracle/admin/orcl/scripts/orcl.sql //*连接数据库,执行orcl.sql

 

orcl.sql文件的作用:设置SYS,SYSTEM用户的密码

set verify off

PROMPT specify a password for sys as parameter 1;

DEFINE sysPassword = &1

PROMPT specify a password for system as parameter 2;

DEFINE systemPassword = &2

host /home/u01/app/oracle/product/10.2.0/bin/orapwd file=/home/u01/app/oracle/product/10.2.0/dbs/orapworcl password=&&sysPassword force=y

//*orapwd工具创建密码文件

@/home/u01/app/oracle/admin/orcl/scripts/CreateDB.sql

@/home/u01/app/oracle/admin/orcl/scripts/CreateDBFiles.sql

@/home/u01/app/oracle/admin/orcl/scripts/CreateDBCatalog.sql

@/home/u01/app/oracle/admin/orcl/scripts/emRepository.sql

@/home/u01/app/oracle/admin/orcl/scripts/postDBCreation.sql

 

CreateDB.sql

connect "SYS"/"&&sysPassword" as SYSDBA      *SYSDBA角色登录数据库*

set echo on

spool /home/u01/app/oracle/admin/orcl/scripts/CreateDB.log     *过程记录到日志*

startup nomount pfile="/home/u01/app/oracle/admin/orcl/scripts/init.ora";  *pfile启动实例*

CREATE DATABASE "orcl"         *创建数据库,进行相关设置

MAXINSTANCES 8

MAXLOGHISTORY 1

MAXLOGFILES 16

MAXLOGMEMBERS 3

MAXDATAFILES 100              *表空间的创建*

DATAFILE SIZE 300M AUTOEXTEND ON NEXT  10240K MAXSIZE UNLIMITED

EXTENT MANAGEMENT LOCAL

SYSAUX DATAFILE SIZE 120M AUTOEXTEND ON NEXT  10240K MAXSIZE UNLIMITED

SMALLFILE DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE SIZE 20M AUTOEXTEND ON NEXT  640K MAXSIZE UNLIMITED

SMALLFILE UNDO TABLESPACE "UNDOTBS1" DATAFILE SIZE 200M AUTOEXTEND ON NEXT  5120K MAXSIZE UNLIMITED

CHARACTER SET WE8ISO8859P1         数据库语言

NATIONAL CHARACTER SET AL16UTF16    国家语言

LOGFILE GROUP 1  SIZE 51200K,

GROUP 2  SIZE 51200K,

GROUP 3  SIZE 51200K

USER SYS IDENTIFIED BY "&&sysPassword" USER SYSTEM IDENTIFIED BY "&&systemPassword";

set linesize 2048;

column ctl_files NEW_VALUE ctl_files;

select concat('control_files=''', concat(replace(value, ', ', ''','''), '''')) ctl_files from v$parameter where name ='control_files';

host echo &ctl_files >>/home/u01/app/oracle/admin/orcl/scripts/init.ora;ctl的位置追加到init

spool off

 

CreateDBFiles.sql

connect "SYS"/"&&sysPassword" as SYSDBA

set echo on

spool /home/u01/app/oracle/admin/orcl/scripts/CreateDBFiles.log

CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE SIZE 5M AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT  AUTO;ALTER DATABASE DEFAULT TABLESPACE "USERS";

spool off

 

CreateDBCatalog.sql

connect "SYS"/"&&sysPassword" as SYSDBA

set echo on

spool /home/u01/app/oracle/admin/orcl/scripts/CreateDBCatalog.log

@/home/u01/app/oracle/product/10.2.0/rdbms/admin/catalog.sql;

@/home/u01/app/oracle/product/10.2.0/rdbms/admin/catblock.sql;

@/home/u01/app/oracle/product/10.2.0/rdbms/admin/catproc.sql;

@/home/u01/app/oracle/product/10.2.0/rdbms/admin/catoctk.sql;

@/home/u01/app/oracle/product/10.2.0/rdbms/admin/owminst.plb;

connect "SYSTEM"/"&&systemPassword"

@/home/u01/app/oracle/product/10.2.0/sqlplus/admin/pupbld.sql;

connect "SYSTEM"/"&&systemPassword"

set echo on

spool /home/u01/app/oracle/admin/orcl/scripts/sqlPlusHelp.log

@/home/u01/app/oracle/product/10.2.0/sqlplus/admin/help/hlpbld.sql helpus.sql;

spool off

spool off

 

postDBCreation.sql    结尾工作

connect "SYS"/"&&sysPassword" as SYSDBA

set echo on

spool /home/u01/app/oracle/admin/orcl/scripts/postDBCreation.log

connect "SYS"/"&&sysPassword" as SYSDBA

set echo on

create spfile='/home/u01/app/oracle/product/10.2.0/dbs/spfileorcl.ora' FROM pfile='/home/u01/app/oracle/admin/orcl/scripts/init.ora';

shutdown immediate;

connect "SYS"/"&&sysPassword" as SYSDBA

startup ;

select 'utl_recomp_begin: ' || to_char(sysdate, 'HH:MI:SS') from dual;

execute utl_recomp.recomp_serial();

select 'utl_recomp_end: ' || to_char(sysdate, 'HH:MI:SS') from dual;

spool /home/u01/app/oracle/admin/orcl/scripts/postDBCreation.log

exit;

 

以上仅仅是最简单的建库,如果还要添加组件或者其他设置的话可能还会执行其它文件比如emRepository.sql / JVM / OLAP的相关文件等等

 

执行下试试:. orcl.sh

过程太多记录不下来,应该创建数据字典并赋予权限时用了大量的屏幕

 

 

删除数据库:

1.删除数据文件控制文件日志文件  oradata下)

2.删除参数文件密码文件等   $ORACLE_HOME/dbs下)

3.删除admin目录下的创建数据库目录 ORACLE_BASE/admin/orcl

 

 

手动安装数据库:

     创建目录:

mkdir -p /home/u01/app/oracle/admin/test/adump

mkdir -p /home/u01/app/oracle/admin/test/bdump

mkdir -p /home/u01/app/oracle/admin/test/cdump

mkdir -p /home/u01/app/oracle/admin/test/dpdump

mkdir -p /home/u01/app/oracle/admin/test/pfile

mkdir -p /home/u01/app/oracle/admin/test/udump

mkdir -p /home/u01/oradata/test

    

设置环境变量ORACLE_SID=test

ORACLE_HOMEORACLE_BASE.bash_profile里设置正确了就不需要重新设置

     创建初始化参数文件

$vi $ORACLE_HOME/dbs/inittest.ora

这里参照了之前建库使用的初始化参数文件内容进行修改

db_block_size=8192

db_file_multiblock_read_count=16

open_cursors=300

db_domain=com

db_name=test

background_dump_dest=/home/u01/app/oracle/admin/test/bdump

core_dump_dest=/home/u01/app/oracle/admin/test/cdump

user_dump_dest=/home/u01/app/oracle/admin/test/udump

control_files=("/home/u01/oradata/test/control01.ctl","/home/u01/oradata/test/control02.ctl","/home/u01/oradata/test/control03.ctl")

db_create_file_dest=/home/u01/oradata/test

job_queue_processes=10

compatible=10.2.0.1.0

processes=150

sga_target=285212672

audit_file_dest=/home/u01/app/oracle/admin/test/adump

remote_login_passwordfile=EXCLUSIVE

pga_aggregate_target=94371840

undo_management=AUTO

undo_tablespace=UNDOTBS1

 

④启动实例试试:

sqlplus / as sysdba

⑤创建建库脚本createDB.sql,也可以直接在SQL下输入脚本里的命令

create database test

user sys identified by oracle

user system identified by oracle

datafile size 300m autoextend on next 10240K maxsize unlimited

EXTENT MANAGEMENT LOCAL

sysaux datafile size 300m autoextend on next 10240K maxsize unlimited

undo tablespace undotbs1 datafile size 100m autoextend on next 5M maxsize unlimited

default temporary tablespace temp tempfile size 20m autoextend on next 640K maxsize unlimited

logfile group 1 size 50m,

         group 2 size 50m,

         group 3 size 50m

         maxlogfiles 5

character set WE8ISO8859P1

national character set AL16UTF16;

在创建完数据库我们发现数据库已经打开

⑥执行一些必需的脚本  SQL>start ~

/home/u01/app/oracle/product/10.2.0/rdbms/admin/catalog.sql;    (建数据字典视图)

/home/u01/app/oracle/product/10.2.0/rdbms/admin/catblock.sql;   (建锁相关的几个视图)

/home/u01/app/oracle/product/10.2.0/rdbms/admin/catproc.sql;    (建存储过程包)

$ORACLE_HOME/rdbms/admin/catoctk.sql;   (建密码工具包dbms_crypto_toolkit

$ORACLE_HOME/rdbms/admin/owminst.plb; (建工作空间管理相关对象,如dmbs_wm

$ORACLE_HOME/sqlplus/admin/pupbld.sql;  (系统环境文件,是所有用户可以使用sqlplus

@/home/u01/app/oracle/product/10.2.0/sqlplus/admin/help/hlpbld.sql helpus.sql;

 

⑦创建USER用户表空间

CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE SIZE 5M AUTOEXTEND ON NEXT  1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT  AUTO;

ALTER DATABASE DEFAULT TABLESPACE "USERS";

 

⑧创建spfile

 

start $ORACLE_HOME/rdbms/admin/utlsampl.sql   导入模版,那个dept,hr的数据库的表,可进行测试

 

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24005010/viewspace-689720/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-31

  • 博文量
    75
  • 访问量
    134421