2.10 最后的脚本

在完成了主要脚本的工作之后,剩下的就是最后的维护工作。这里还有两个脚本需要执行,首先执行的是postScripts.sql脚本,这个脚本主要对部分用户及部分数据库选件进行维护:

SET VERIFY OFF

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

set echo on

spool D:\Oracle\admin\eygle\scripts\postScripts.log append

@D:\Oracle\11.2.0\rdbms\admin\dbmssml.sql;

execute dbms_datapump_utl.replace_default_dir;

commit;

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

alter session set current_schema=ORDSYS;

@D:\Oracle\11.2.0\ord\im\admin\ordlib.sql;

alter session set current_schema=SYS;

create or replace directory XMLDIR as 'D:\Oracle\11.2.0\rdbms\xml';

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

alter user CTXSYS account unlock identified by &&sysPassword;

connect "CTXSYS"/"&&sysPassword"

@D:\Oracle\11.2.0\ctx\admin\defaults\dr0defdp.sql;

@D:\Oracle\11.2.0\ctx\admin\defaults\dr0defin.sql "SIMPLIFIED CHINESE";

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

alter user CTXSYS password expire account lock;

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

execute ORACLE_OCM.MGMT_CONFIG_UTL.create_replace_dir_obj;

最后,执行的脚本是postDBCreation.sql,在这个脚本中将创建SPFILE,重启数据库:

SET VERIFY OFF

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

set echo on

spool D:\Oracle\admin\eygle\scripts\postDBCreation.log append

@D:\Oracle\11.2.0\rdbms\admin\catbundle.sql psu apply;

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;

execute dbms_swrf_internal.cleanup_database(cleanup_local => FALSE);

commit;

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

set echo on

create spfile='D:\Oracle\11.2.0\database\spfileeygle.ora' FROM pfile='D:\Oracle\admin\eygle\scripts\init.ora';

shutdown immediate;

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

startup ;

spool off

exit;

根据配置选项的不同,这个过程的脚本可能不同,如果选择了EM,则脚本末尾可能包含创建和配置EM选件的语句,例如:

host 'D:\Oracle\11.2.0\bin\emca.bat -config dbcontrol db -silent -DB_UNIQUE_NAME eygle -PORT 1521 -EM_HOME 'D:\Oracle\11.2.0 -LISTENER LISTENER -SERVICE_NAME eygle -SYS_PWD &&sysPassword -SID eygle -ORACLE_HOME 'D:\Oracle\11.2.0 -DBSNMP_PWD &&dbsnmpPassword -HOST gqgai -LISTENER_OH 'D:\Oracle\11.2.0 -LOG_FILE 'D:\Oracle\admin\eygle\scripts\emConfig.log -SYSMAN_PWD &&sysmanPassword;

这样使用模板创建数据库就完成了。