第四章: 建立数据库
1、create database plan:
1、库类型:OLTP :在线事务处理系统
OLAP : 在线应用处理系统
DSS : 数据决策系统
2、数据库名字及字符集
3、存储空间
4、数据库的物理和逻辑的结构以及存储结构
2、建库的准备:
1)建立口令文件,用于sys用户远程登录的认证(remote_login_passwordfile=exclusive),位置 $ORACLE_HOME/dbs/orapwSID.创建命令: orapwd
[oracle@work dbs]$ orapwd file=orapwprod password=oracle entries=5 force=y
remote_login_passwordfile
1)none 拒绝sys用户从远程连接
2)exclusive sys用户可以从远程连接
3)share 多个库可以共享口令文件
2)创建init parameter 文件
[oracle@oracle dbs]$more initdw.ora |grep -v '^#'|grep -v '^$' >initlx02.ora
[oracle@oracle dbs]$ mkdir -p $ORACLE_BASE/admin/lx02/bdump
[oracle@oracle dbs]$ mkdir -p $ORACLE_BASE/admin/lx02/cdump
[oracle@oracle dbs]$ mkdir -p $ORACLE_BASE/admin/lx02/udump
[oracle@oracle dbs]$ mkdir -p $ORACLE_BASE/oradata/lx02
[oracle@oracle dbs]$ vi initlx02.ora
db_name = lx02
db_block_size = 8192
pga_aggregate_target = 30M
db_cache_size = 80M
shared_pool_size = 60M
parallel_threads_per_cpu = 4
optimizer_mode = choose
star_transformation_enabled = true
db_file_multiblock_read_count = 16
query_rewrite_enabled = true
query_rewrite_integrity = trusted
background_dump_dest = $ORACLE_BASE/admin/lx02/bdump
user_dump_dest = $ORACLE_BASE/admin/lx02/udump
core_dump_dest = $ORACLE_BASE/admin/lx02/cdump
control_files = $ORACLE_BASE/oradata/lx02/control01.ctl
undo_management = auto
undo_tablespace = rtbs
3)建立建库脚本
1、库名
2、表空间及数据文件的位置和大小
3、redo 日志文件的位置和大小
4、字符集
建库脚本:vi cr_db.sql
create database lx02
user sys identified by oracle
user system identified by oracle
datafile '$ORACLE_BASE/oradata/lx02/system01.dbf' size 300m
sysaux datafile '$ORACLE_BASE/oradata/lx02/sysaux01.dbf' size 100m
default temporary tablespace temp tempfile '$ORACLE_BASE/oradata/lx02/temp01.dbf' size 100m
undo tablespace rtbs datafile '$ORACLE_BASE/oradata/lx02/rtbs01.dbf' size 100m
logfile
group 1 '$ORACLE_BASE/oradata/lx02/redo01a.log' size 10m,
group 2 '$ORACLE_BASE/oradata/lx02/redo02a.log' size 10m
character set zhs16gbk;
告警日志信息:
create tablespace SYSTEM datafile '$ORACLE_BASE/oradata/test/system01.dbf' size 400m
default storage (initial 10K next 10K) online
Sat Aug 20 00:26:34 2011
Completed: create tablespace SYSTEM datafile '$ORACLE_BASE/oradata/test/system01.dbf' size 400m
default storage (initial 10K next 10K) EXTENT MANAGEMENT DICTIONARY online
Sat Aug 20 00:26:34 2011
create rollback segment SYSTEM tablespace SYSTEM
storage (initial 50K next 50K)
Completed: create rollback segment SYSTEM tablespace SYSTEM
storage (initial 50K next 50K)
Sat Aug 20 00:26:49 2011
Thread 1 advanced to log sequence 2
Current log# 2 seq# 2 mem# 0: /u01/app/oracle/oradata/test/redo02a.log
Sat Aug 20 00:26:50 2011
CREATE UNDO TABLESPACE RTBS DATAFILE '$ORACLE_BASE/oradata/test/rtbs01.dbf' size 100m
Sat Aug 20 00:26:51 2011
Successfully onlined Undo Tablespace 1.
Completed: CREATE UNDO TABLESPACE RTBS DATAFILE '$ORACLE_BASE/oradata/test/rtbs01.dbf' size 100m
Sat Aug 20 00:26:51 2011
create tablespace SYSAUX datafile '$ORACLE_BASE/oradata/test/sysaux01.dbf' size 100m
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO online
Completed: create tablespace SYSAUX datafile '$ORACLE_BASE/oradata/test/sysaux01.dbf' size 100m
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO online
Sat Aug 20 00:26:54 2011
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE '$ORACLE_BASE/oradata/test/temp01.dbf' size 100m
Completed: CREATE TEMPORARY TABLESPACE TEMP TEMPFILE '$ORACLE_BASE/oradata/test/temp01.dbf' size 100m
Sat Aug 20 00:26:55 2011
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP
Completed: ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP
Sat Aug 20 00:26:55 2011
ALTER DATABASE DEFAULT TABLESPACE SYSTEM
Completed: ALTER DATABASE DEFAULT TABLESPACE SYSTEM
Sat Aug 20 00:27:01 2011
SMON: enabling tx recovery
Sat Aug 20 00:27:02 2011
Threshold validation cannot be done before catproc is loaded.
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
QMNC started with pid=13, OS id=6485
Sat Aug 20 00:27:03 2011
Completed: create database test
user sys identified by **user system identified by *datafile '$ORACLE_BASE/oradata/test/system01.dbf' size 400m
sysaux datafile '$ORACLE_BASE/oradata/test/sysaux01.dbf' size 100m
undo tablespace rtbs datafile '$ORACLE_BASE/oradata/test/rtbs01.dbf' size 100m
default temporary tablespace temp tempfile '$ORACLE_BASE/oradata/test/temp01.dbf' size 100m
logfile
group 1 '$ORACLE_BASE/oradata/test/redo01a.log' size 10m,
group 2 '$ORACLE_BASE/oradata/test/redo02a.log' size 10m,
group 3 '$ORACLE_BASE/oradata/test/redo03a.log' size 10m
character set zhs16gbk
4)建立数据字典
数据字典脚本:vi cr_dict.sql
@$ORACLE_HOME/rdbms/admin/catalog.sql
@$ORACLE_HOME/rdbms/admin/catproc.sql
conn system/oracle
@$ORACLE_HOME/sqlplus/admin/pupbld.sql
5)创建users 表空间,作为普通用户的默认表空间
08:08:19 SQL> select tablespace_name from dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
RTBS
SYSAUX
TEMP
4 rows selected.
08:08:27 SQL> col file_name for a50
08:08:37 SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- -------------------------------------------------- ------------------------------
1 /u01/app/oracle/oradata/lx02/system01.dbf SYSTEM
2 /u01/app/oracle/oradata/lx02/rtbs01.dbf RTBS
3 /u01/app/oracle/oradata/lx02/sysaux01.dbf SYSAUX
08:09:56 SQL> create tablespace users
08:10:01 2 datafile '/u01/app/oracle/oradata/lx02/user01.dbf' size 100m;
Tablespace created.
08:10:41 SQL> alter database default tablespace users;
Database altered.
08:10:45 SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- -------------------------------------------------- ------------------------------
1 /u01/app/oracle/oradata/lx02/system01.dbf SYSTEM
2 /u01/app/oracle/oradata/lx02/rtbs01.dbf RTBS
3 /u01/app/oracle/oradata/lx02/sysaux01.dbf SYSAUX
4 /u01/app/oracle/oradata/lx02/user01.dbf USERS
4 rows selected.
6)添加scott 案例
08:11:45 SQL> @$ORACLE_HOME/rdbms/admin/utlsampl.sql
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@oracle ~]$