Professional Documents
Culture Documents
Mkplug
Mkplug
SET FEEDBACK 1
SET NUMWIDTH 10
SET LINESIZE 80
SET TRIMSPOOL ON
SET TAB OFF
SET PAGESIZE 999
SET ECHO OFF
SET CONCAT '.'
SET SHOWMODE OFF
PROMPT
PROMPT specify password for SYS as parameter 1:
DEFINE password_sys = &1
PROMPT
PROMPT specify password for HR as parameter 2:
DEFINE password_hr = &2
PROMPT
PROMPT specify password for OE as parameter 3:
DEFINE password_oe = &3
PROMPT
PROMPT specify password for PM as parameter 4:
DEFINE password_pm = &4
PROMPT
PROMPT specify password for IX as parameter 5:
DEFINE password_ix = &5
PROMPT
PROMPT specify password for SH as parameter 6:
DEFINE password_sh = &6
PROMPT
PROMPT specify password for BI as parameter 7:
DEFINE password_bi = &7
PROMPT
PROMPT specify INPUT metadata import file as parameter 8:
DEFINE imp_file = &8
PROMPT
PROMPT specify INPUT database backup file for tablespace EXAMPLE as parameter 9:
DEFINE data_file_backup = &9
PROMPT
PROMPT specify OUTPUT database file for tablespace EXAMPLE as parameter 10:
DEFINE data_file_name = &10
PROMPT
PROMPT specify OUTPUT log directory as parameter 11:
DEFINE log_path = &11
PROMPT
PROMPT specify OUTPUT dump file directory as parameter 12:
DEFINE dump_path = &12
PROMPT
PROMPT specify oe data file directory for loading oe data as parameter 13:
DEFINE oe_data_path = &13
PROMPT
PROMPT Sample Schemas are being plugged in ...
PROMPT
DEFINE vrs = v3
SPOOL &log_path.mkplug_&vrs._@.log
--
-- Running the instantiated mk_dir.sql, thus connecting
-- the DIRECTORY objects with the appropriate file system
-- paths on this specific system
--
--
-- Creating users and granting system privileges
--
@__SUB__CWD__/mk_dir
EXECUTE DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE( -
privilege => DBMS_RULE_ADM.CREATE_RULE_OBJ, -
grantee => 'ix', -
grant_option => FALSE);
--
-- Restoring database file backup
-- (Using RMAN works in OMF, OCFS, raw devices and in normal file systems)
--
begin
dbms_output.put_line(' ');
dbms_output.put_line(' Allocating device.... ');
dbms_output.put_line(' Specifying datafiles... ');
devicename := dbms_backup_restore.deviceAllocate;
dbms_output.put_line(' Specifing datafiles... ');
/*************************************************************************/
/* Note that the 'select 10' statement below here is a workaround for */
/* INSTALL and pdb databases. */
/* If you receive an error about not being able to find a tablespace */
/* the file_id needs to change from 10 to something else. */
/*************************************************************************/
-- Now get the real file name. It could be also OMF filename
SELECT name, stamp, resetlogs_change#, creation_change#,
checkpoint_change#,block_size
INTO real_file_name, stamp,resetlogs_change, creation_change,
checkpoint_change, blksize
FROM V$DATAFILE_COPY
WHERE recid = rec_id and rfile# = data_file_id;
--
-- Importing the metadata and plugging in the tablespace at the same
-- time, using the restored database file
--
REM
REM Now we rebuild the objects that cannot
REM be part of a transportable tablespace set
REM ==========================================
REM
PROMPT
PROMPT Creating sequences, views, procedures and objects privileges for HR ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
CONNECT hr/&&password_hr;
--
-- Sequences
--
CREATE SEQUENCE locations_seq
START WITH 3300
INCREMENT BY 100
MAXVALUE 9900
NOCACHE
NOCYCLE;
--
-- Views
--
--
-- Rebuilding procedural objects
--
@__SUB__CWD__/human_resources/hr_code
--
-- oe_main.sql creates and closes it's own log file. start part2 of mkplug here
--
-- the '.' is the sql concat charater - that's why there are 2 '.' before log
SPOOL &log_path.mkplug_p2_&vrs..log
--
-- Object privileges
--
connect hr/&&password_hr;
PROMPT
PROMPT Creating synonyms, sequences, views and functions for OE ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
CONNECT oe/&&password_oe;
--
-- Create cross-schema synonyms
--
PROMPT
PROMPT Creating dimensions, materialized views, external table and object
privileges for SH ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
CONNECT sh/&&password_sh;
--
-- External Table
--
PROMPT
PROMPT Creating OLAP metadata ...
--
-- Object Privileges
--
PROMPT
PROMPT Creating views, synonyms for BI ...
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;
@__SUB__CWD__/bus_intelligence/bi_views.sql &&password_bi
--
-- set up extra contraints in the PM schema
connect pm/&&password_pm;
-- renanalyze ix
EXECUTE dbms_stats.gather_schema_stats('IX');
-- clean up the directory object now that we're done with it.
drop directory SS_IMPEXP_DIR;
drop directory SS_LOGPATH_DIR;
PROMPT
PROMPT mkplug.sql DONE
SELECT TO_CHAR(systimestamp, 'YYYYMMDD HH:MI:SS') FROM dual;