1. 程式人生 > >David Dai -- Focus on Oracle

David Dai -- Focus on Oracle

手工新建資料庫create database
身為DBA,要永遠記住甚用或者禁止使用rm命令,萬不得以的情況下,使用時在敲enter也要看了又看、慎重又慎重才行!
Red Hat Enterprise 3 + Oracle 10g Release 2
$su – oracle
1---設定系統環境變數:
ORACLE_HOME=/opt/oracle/product/10.2
ORACLE_BASE=/opt/oracle
ORACLE_SID=dbtest
......
2---系統規劃:
例項名稱ORACLE_SID=dbtest
資料庫名稱DB_NAME=dbtest
3---手工建立如下目錄:
/opt/oracle/admin/dbtest/cdump
/opt/oracle/admin/dbtest/bdump
/opt/oracle/admin/dbtest/udump
/opt/oracle/admin/dbtest/pfile
/opt/oracle/oradata/dbtest/
/opt/oracle/oradata/dbtest/archive
4---建立密碼檔案:
orapwd file=/opt/oracle/product/10.2/dbs/orapwd_dbtest password=superman
5---修改引數檔案:
格式:/opt/oracle/product/10.2/dbs/init.ora
例項:/opt/oracle/product/10.2/dbs/initdbtest.ora
內容如下:
---------------------------------------------------
dbtest.__db_cache_size=331350016
dbtest.__java_pool_size=4194304
dbtest.__large_pool_size=8388608
dbtest.__shared_pool_size=138412032
dbtest.__streams_pool_size=0
*._kgl_large_heap_warning_threshold=8388608
*.audit_file_dest='/opt/oracle/admin/dbtest/adump'
*.background_dump_dest='/opt/oracle/admin/dbtest/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/opt/oracle/oradata/dbtest/control01.ctl','/opt/oracle/oradata/dbtest/control02.ctl','/opt/oracle/oradata/dbtest/control03.ctl'
*.core_dump_dest='/opt/oracle/admin/dbtest/cdump'
*.db_2k_cache_size=33554432
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=128
*.db_files=4000
*.db_name='dbtest'
*.db_recovery_file_dest_size=4294967296
*.db_recovery_file_dest=''
*.log_archive_dest='/opt/oracle/oradata/dbtest/archive'
*.log_checkpoints_to_alert=FALSE
*.open_cursors=300
*.parallel_execution_message_size=65535
*.parallel_max_servers=128
*.pga_aggregate_target=209715200
*.processes=150
*.recyclebin='OFF'
*.remote_login_passwordfile='EXCLUSIVE'
*.replication_dependency_tracking=FALSE
*.session_cached_cursors=100
*.sga_target=500m
*.shared_pool_size=100m
*.undo_management='AUTO'
*.undo_retention=0
*.undo_tablespace='UNDOTS'
*.user_dump_dest='/opt/oracle/admin/dbtest/udump'
*.workarea_size_policy='AUTO'
_allow_resetlogs_corruption=true
---------------------------------------------------
可將此檔案複製到:/opt/oracle/admin/dbtest/pfile/init.ora
6---登陸oracle:
> sqlplus “/ as sysdba”
7---啟動例項:
SQL> startup nomount pfile=/opt/oracle/admin/dbtest/pfile/init.ora
8---建立資料庫的指令碼:
-----------------------------------------------------------
CREATE DATABASE dbtest
LOGFILE
GROUP 1 ('/opt/oracle/oradata/dbtest/redo01.log','/opt/oracle/oradata/dbtest/redo01_1.log') size 100m reuse,
GROUP 2 ('/opt/oracle/oradata/dbtest/redo02.log','/opt/oracle/oradata/dbtest/redo02_1.log') size 100m reuse,
GROUP 3 ('/opt/oracle/oradata/dbtest/redo03.log','/opt/oracle/oradata/dbtest/redo03_1.log') size 100m reuse
MAXLOGFILES 50
MAXLOGMEMBERS 5
MAXLOGHISTORY 200
MAXDATAFILES 500
MAXINSTANCES 5
ARCHIVELOG
CHARACTER SET UTF8
NATIONAL CHARACTER SET UTF8
DATAFILE '/opt/oracle/oradata/dbtest/system01.dbf' SIZE 1000M EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE '/opt/oracle/oradata/dbtest/sysaux01.dbf' SIZE 1000M
UNDO TABLESPACE UNDOTS DATAFILE '/opt/oracle/oradata/dbtest/undo.dbf' SIZE 500M
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/opt/oracle/oradata/dbtest/temp.dbf' SIZE 500M

9---執行如下檔案

(安裝下面的先後順序)
/opt/oracle/product/10.2/rdbms/admin/catalog.sql
/opt/oracle/product/10.2/rdbms/admin/catproc.sql
10---建立相關表空間與使用者:
CREATE TABLESPACE USERS DATAFILE '/opt/oracle/oradata/dbtest/users01.dbf' SIZE 1000M;---資料表空間
CREATE TABLESPACE INDX DATAFILE '/opt/oracle/oradata/dbtest/indx01.dbf' SIZE 1000M;---在建立索引的時候把此表空間作為儲存空間,即單獨用一個表空間來儲存索引,這是個好習慣,雖然我們沒有辦法建立一個預設的索引表空間!
CREATE USER test IDENTIFIED BY test DEFAULT TABLESPACE users ;---測試使用者
GRANT CONNECT,RESOURCE TO test;
11---一點注意的地方:

1>.相關檔案的目錄要設定正確,有資料檔案,控制檔案,引數檔案等,還有就是它們的位置要與控制檔案中指定的要一致。
2>.init.ora中的undo_tablespace的名字必須要與create database的相同,包括大小寫等注意。否則很麻煩,報的錯誤你都不知道是不是在忽悠你!總之,一句話,控制檔案中的內容要和init檔案中的內容以及要和實際檔案的實際情況要相同。
3>.分析資料庫出錯可以到/opt/oracle/admin/dbtest/bdump/alert_dbtest.log中查詢。
再次提醒:身為DBA,甚用rm命令