sql.bsq與資料庫的建立

eygle發表於2019-05-26

« 警惕騙子-以同學名義行騙 | Blog首頁 | 中國首屆傑出資料庫工程師評選前10名單 »


如果我們使用指令碼建立資料庫,那麼最先執行的是一個叫做CreateDB.sql的指令碼。
這個指令碼發出CREATE DATABASE的命令,具體類似如下的例子:

CREATE DATABASE eygle
MAXINSTANCES 1
MAXLOGHISTORY 1
MAXLOGFILES 5
MAXLOGMEMBERS 3
MAXDATAFILES 100
DATAFILE '/opt/oracle/oradata/eygle/system01.dbf'
SIZE 250M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE '/opt/oracle/oradata/eygle/temp01.dbf'
SIZE 40M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE "UNDOTBS1" DATAFILE '/opt/oracle/oradata/eygle/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
CHARACTER SET ZHS16GBK
NATIONAL CHARACTER SET AL16UTF16
LOGFILE GROUP 1 ('/opt/oracle/oradata/eygle/redo01.log') SIZE 10240K,
GROUP 2 ('/opt/oracle/oradata/eygle/redo02.log') SIZE 10240K,
GROUP 3 ('/opt/oracle/oradata/eygle/redo03.log') SIZE 10240K;
exit;

在這個過程中,Oracle會呼叫$ORACLE_HOME/rdbms/admin/sql.bsq指令碼,用於建立資料字典。

這個檔案的位置受到一個隱含的初始化引數 (_init_sql_file )的控制:

SQL> @GetParDescrb.sql
Enter value for par: init_sql
old 6: AND x.ksppinm LIKE '%&par%'
new 6: AND x.ksppinm LIKE '%init_sql%'

NAME VALUE DESCRIB
--------------- --------------------- ------------------------------------------------------------
_init_sql_file ?/rdbms/admin/sql.bsq File containing SQL statements to execute upon database creation

如果在建立過程中,Oracle無法找到sql.bsq檔案,則資料庫建立將會出錯.
如果我們移除sql.bsq檔案,再看這樣一個資料庫建立過程:

[oracle@jumper scripts]$ sqlplus "/ as sysdba"

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Aug 18 15:45:26 2006

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area 252777592 bytes
Fixed Size 451704 bytes
Variable Size 134217728 bytes
Database Buffers 117440512 bytes
Redo Buffers 667648 bytes
SQL> @CreateDB.sql
CREATE DATABASE eygle
*
ERROR at line 1:
ORA-01092: ORACLE instance terminated. Disconnection forced


Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production

此時日誌中會記錄:

Fri Aug 18 15:45:49 2006
Errors in file /opt/oracle/admin/eygle/udump/eygle_ora_3632.trc:
ORA-01501: CREATE DATABASE failed
ORA-01526: error in opening file '?/rdbms/admin/sql.bsq'
ORA-07391: sftopn: fopen error, unable to open text file.
Error 1526 happened during db open, shutting down database
USER: terminating instance due to error 1526
Fri Aug 18 15:45:49 2006
Errors in file /opt/oracle/admin/eygle/bdump/eygle_ckpt_3623.trc:
ORA-01526: error in opening file ''
Instance terminated by USER, pid = 3632
ORA-1092 signalled during: CREATE DATABASE eygle
MAXINSTANCES 1
MAXLOGHISTORY...

這就是sql.bsq檔案在資料庫建立過程中的作用。知道了這個內容之後,我們可以通過手工修改sql.bsq檔案來更改資料庫字典物件引數,從而實現特殊要求資料庫的建立或測試自定義庫。

我們也可以通過修改_init_sql_file引數來重定位sql.bsq檔案的位置。

ixora網站上有一篇文章可以參考:
http://www.ixora.com.au/tips/creation/bsq.htm
Itpub上的相關文章:
http://www.itpub.net/199099.html

-The End-


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/764/viewspace-120570/,如需轉載,請註明出處,否則將追究法律責任。

相關文章