وبلاگ مسعود حاجی حسن پور

راهکار های عملی اوراکل

راهکار های عملی اوراکل

این وبلاگ جهت به اشتراک گذاری تجربیات و راهکار های عملی در زمینه پایگاه داده اوراکل می باشد.

دستاوردها
طبقه بندی موضوعی

۲ مطلب با موضوع «12c» ثبت شده است

unplug نمودن، بازیابی description xml file و plug نمودن pdb به cdb دیگر

با سلام خدمت دوستان عزیز
در Multitenant container database یکی از قابلیت های خیلی خوب، قابلیت unplug و plug نمودن pdb در یک cdb دیگر هست. برای این منظور لازم هست اول مقداری راجب به unplug نمودن pdb توضیح دهم. در زمانی که pdb را unplug میکنیم یک فایل xml  تولید میگردد که option های آن pdb را توصیف میکند. سپس با استفاده از همان description xml file آن pdb را به cdb دیگر متصل (plug) میکنیم. فرض کنید پس از unplug نمودن pdb فایل xml ما یا معیوب شده است یا از دست رفته است. پس با من همراه باشید که طی یک سناریو مطالب زیر را دنبال کنیم:

  1. چگونه pdb را unplug کنیم ؟
  2. چگونه description xml file را بازیابی کنیم ؟
  3. چگونه pdb  را با استفاده از description xml file به cdb دیگر plug کنیم ؟
اول وضعیت cdb مبدا و pdb ها ای که به آن متصل شده است را بررسی میکنیم:
[oracle@oel7 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Wed Jan 31 14:57:34 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> select name, cdb from v$database;

NAME      CDB
--------- ---
DB12C     YES

SQL> col name for a20;
SQL> select con_id, name, open_mode, restricted from v$pdbs;

    CON_ID NAME                 OPEN_MODE  RES
---------- -------------------- ---------- ---
         2 PDB$SEED             READ ONLY  NO
         3 MYPDB                READ WRITE NO
         4 MAS12C               READ WRITE NO

طی دستور های زیر mypdb  را از پایگاه داده مبدا unplug و سپس حذف میکنیم.

SQL> alter pluggable database mypdb close;
2018-01-31T15:10:55.443763+03:30
MYPDB(3):JIT: pid 40960 requesting stop
Pluggable database MYPDB closed
Completed: alter pluggable database mypdb close

Pluggable database altered.

SQL> alter pluggable database mypdb unplug into '/u01/mypdbfile.xml';
2018-01-31T15:11:04.127823+03:30
alter pluggable database mypdb unplug into '/u01/mypdbfile.xml'
MYPDB(3):Autotune of undo retention is turned on.
2018-01-31T15:11:04.248476+03:30
MYPDB(3):Endian type of dictionary set to little
MYPDB(3):[40960] Successfully onlined Undo Tablespace 2.
MYPDB(3):Undo initialization finished serial:0 start:95543809 end:95543858 diff:49 ms (0.0 seconds)
MYPDB(3):Database Characterset for MYPDB is AL32UTF8
2018-01-31T15:11:06.044436+03:30
MYPDB(3):Opatch XML is skipped for PDB MYPDB (conid=3)
MYPDB(3): AUDSYS.AUD$UNIFIED (SQL_TEXT) - CLOB populated
MYPDB(3):JIT: pid 40960 requesting stop
MYPDB(3):Autotune of undo retention is turned on.
MYPDB(3):Endian type of dictionary set to little
MYPDB(3):Undo initialization finished serial:0 start:95546119 end:95546119 diff:0 ms (0.0 seconds)
MYPDB(3):Database Characterset for MYPDB is AL32UTF8
MYPDB(3):Opatch XML is skipped for PDB MYPDB (conid=3)
2018-01-31T15:11:07.053863+03:30
MYPDB(3): AUDSYS.AUD$UNIFIED (SQL_TEXT) - CLOB populated
MYPDB(3):JIT: pid 40960 requesting stop
Completed: alter pluggable database mypdb unplug into '/u01/mypdbfile.xml'

Pluggable database altered.

SQL> drop pluggable database mypdb;
2018-01-31T15:15:43.286392+03:30
drop pluggable database mypdb
Completed: drop pluggable database mypdb

Pluggable database dropped.

SQL> select con_id, name, open_mode, restricted from v$pdbs;

    CON_ID NAME                 OPEN_MODE  RES
---------- -------------------- ---------- ---
         2 PDB$SEED             READ ONLY  NO
         4 MAS12C               READ WRITE NO

 همانگونه که گفتیم فرض مسئله معیوب بودن یا از دست رفتن description xml file هست پس این کار را انجام میدهیم:

[oracle@oel7 ~]$ mv /u01/mypdbfile.xml /u01/mypdbfile.xml.old
[oracle@oel7 ~]$ ll /u01/
total 8
drwxrwxr-x. 4 oracle oinstall   38 Jan 13 11:58 app
-rw-r--r--. 1 oracle oinstall 6957 Jan 31 15:11 mypdbfile.xml.old

در بالا دیدیم که چگونه pdb را unplug کنیم. حالا میخواهیم description xml file را بازیابی کنیم و سپس pdb را به cdb  دیگر متصل (plug) نماییم. در ادامه بر روی cdb مقصد کار خواهیم کرد، پس وضعیت cdb مذکور را بررسی میکنیم:

[oracle@oel7 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Wed Jan 31 16:04:15 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> select name, cdb from v$database;

NAME      CDB
--------- ---
MYCDB     YES

SQL> col name for a20;
SQL> select con_id, name, open_mode, restricted from v$pdbs;

    CON_ID NAME                 OPEN_MODE  RES
---------- -------------------- ---------- ---
         2 PDB$SEED             READ ONLY  NO
         3 NIMA                 READ WRITE NO

برای plug نمودن pdb که unplug  شده است، شما نیاز به description xml file  دارید. با یک dbms package با خواندن دوباره دیتا فایل ها میتوانید آن را بسازید. شکل package و argument  های آن به حالت زیر می باشد:

DBMS_PDB.RECOVER (
   pdb_descr_file    IN   VARCHAR2, 
   pdb_name          IN   VARCHAR2,
   filenames         IN   VARCHAR2);

pdb_descr_file:
Path of the XML file that contains description of a pluggable database

pdb_name:
Name of a pluggable database

filenames:
Comma-separated list of datafile paths and/or directories containing datafiles for the pluggable database

برای اطلاعات بیشتر در مورد dbms package  فوق به آدرس زیر مراجعه بفرمایید:

DBMS_PDB

حالا description xml file  را بازیابی میکنیم:

[oracle@oel7 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Wed Jan 31 16:20:54 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> 
1 begin
2    dbms_pdb.recover(
3    pdb_descr_file => '/home/oracle/mypdb.xml',
4    pdb_name => 'mypdb',
5    filenames => '/u01/app/oracle/oradata/db12c/mypdb'
6  );
7 end;
8 /

PL/SQL procedure successfully completed.

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@oel7 ~]$ ls -l mypdb.xml
-rw-r--r--. 1 oracle oinstall 4184 Jan 31 16:20 mypdb.xml

همانگونه که مشاهده نمودید description xml file بازیابی شد. حالا وقت این هست که pdb را به cdb مقصد متصل (plug) نماییم. پیش از این، یک مرحله optional را پیش میبریم تا ببینیم pdb ما با cdb  جدید سازگار میباشد یا خیر. برای این کار از dbms_pdb.check_plug_compatibility استفاده میکنیم:

[oracle@oel7 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Wed Jan 31 16:20:54 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> set serverout on;
SQL>
1 DECLARE
2   theResult BOOLEAN;
3 BEGIN
4   l_result := DBMS_PDB.check_plug_compatibility(
5                 pdb_descr_file => '/home/oracle/mypdb.xml',
6                 pdb_name       => 'mypdb');
7 
8   IF theResult THEN
9     DBMS_OUTPUT.PUT_LINE('pdb is compatible');
10   ELSE
11     DBMS_OUTPUT.PUT_LINE('dpb is not incompatible');
12   END IF;
13 END;
14 /
pdb is compatible

PL/SQL procedure successfully completed.

در procedure  بالا مشخص شد که pdb ما با cdb مقصد سازگار میباشد. در مرحله آخر pdb  را به cdb متصل (plug) میکنیم.
SQL> create pluggable database mypdb using '/home/oracle/mypdb.xml'
  2  file_name_convert=('/u01/app/oracle/oradata/db12c/mypdb','/u01/app/oracle/oradata/mycdb/mypdb')
  3  tempfile reuse;

Pluggable database created.

SQL> alter pluggable database mypdb open;

Pluggable database altered.

SQL> col name for a20;
SQL> select con_id, name, open_mode, restricted from v$pdbs;

    CON_ID NAME                 OPEN_MODE  RES
---------- -------------------- ---------- ---
         2 PDB$SEED             READ ONLY  NO
         3 NIMA                 READ WRITE NO
         4 MYPDB                READ WRITE NO

SQL> select name from v$datafile where con_id=4;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/mycdb/mypdb/undotbs01.dbf
/u01/app/oracle/oradata/mycdb/mypdb/system01.dbf
/u01/app/oracle/oradata/mycdb/mypdb/sysaux01.dbf
/u01/app/oracle/oradata/mycdb/mypdb/users01.dbf

در بالا مشاهده نمودید که pdb  به درستی به cdb مقصد متصل (plug) شد.


دوستان عزیز امیدوارم مطلب کاربردی بوده باشد.

شاد و پیروز باشید.

آسان ترین راه برای مهاجرت از 11g به 12c Multitenant mode

سلام خدمت دوستان عزیز امروز میخواهم در مورد ساده ترین راه ( استفاده از دستورات پرکاربرد و آشنا برای شما نه لزوما بهترین و کم هزینه ترین روش ) مهاجرت از 11g به 12c pdb بگویم پس با من همراه باشید تا با یک سناریو این کار را انجام دهیم:

  • وضعیت جاری:
Oracle 11g:

Hostname: RestoreDB
SID: RCIS
Schema:mas11g


Oracle 12c:

Hostname: oel7
SID:  DB12C
pdb: mas12c

  • در پایگاه داده و ماشین مبدا (11g)
در این جا فرض میکنیم که در سایت عملیاتی schema اصلی ما mas11g هست و نیاز هست پایگاه داده جدید این schema را دارا باشد. پس در اولین قدم برای شروع سناریو یک schema را می سازیم:
[oracle@RestoreDB ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Jan 16 10:11:25 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SYS@RCIS> def;
DEFINE _DATE           = "16-JAN-18" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "RCIS" (CHAR)
DEFINE _USER           = "SYS" (CHAR)
DEFINE _PRIVILEGE      = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1102000400" (CHAR)
DEFINE _EDITOR         = "ed" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options" (CHAR)
DEFINE _O_RELEASE      = "1102000400" (CHAR)

SYS@RCIS> create tablespace mas11g;

Tablespace created.

SYS@RCIS> select ts#, name from v$tablespace where name='MAS11G';

       TS# NAME
---------- ------------------------------
         9 MAS11G

1 rows selected.

SYS@RCIS> select name from v$datafile where ts#=9;

NAME
--------------------------------------------------------------------------------
+DATA/rcis/datafile/mas11g.422.965556953

SYS@RCIS> create user mas11g account unlock identified by mas default tablespace mas11g temporary tablespace temp quota unlimited on mas11g;

User created.

SYS@RCIS> grant create session, create table, connect, create sequence to mas11g;

Grant succeeded.

SYS@RCIS> disc;

@> conn mas11g/mas
Connected.
MAS11G@RCIS> create table masoud (c1 number primary key, c2 date);

Table created.

MAS11G@RCIS> insert into masoud values (1, sysdate);

1 row created.

MAS11G@RCIS> insert into masoud values (2, sysdate);

1 row created.

MAS11G@RCIS> commit;

Commit complete.

MAS11G@RCIS> create sequence mas_seq start with 3;

Sequence created.

بسیار خوب حالا یک dump از پایگاه داده 11g از schema مورد نظر میگیریم:

[oracle@RestoreDB ~]$ expdp schemas=mas11g dumpfile=mas11g.dmp logfile=mas11g.log

Export: Release 11.2.0.4.0 - Production on Tue Jan 16 10:50:04 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Username: / as sysdba

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Starting "SYS"."SYS_EXPORT_SCHEMA_01":  /******** AS SYSDBA schemas=mas11g dumpfile=mas11g.dmp logfile=mas11g.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
. . exported "MAS11G"."MASOUD"                           5.437 KB       3 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
  /u01/app/oracle/admin/RCIS/dpdump/mas11g.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Tue Jan 16 10:50:25 2018 elapsed 0 00:00:15

دقت کنید در دستور schema آورده ایم یعنی تمام object ها ای که در این schema وجود دارد. سپس فایل dump را به ماشین مقصد oel7 منتقل میکنیم:

scp /u01/app/oracle/admin/RCIS/dpdump/mas11g.dmp oracle@oel7:/tmp


  • درپایگاه داده و ماشین مقصد (12c):
اول وضعیت پایگاه داده مقصد را بررسی میکنیم:
[oracle@oel7 ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 16 12:31:52 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> def;
DEFINE _DATE           = "16-JAN-18" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "db12c" (CHAR)
DEFINE _USER           = "SYS" (CHAR)
DEFINE _PRIVILEGE      = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1202000100" (CHAR)
DEFINE _EDITOR         = "vi" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production" (CHAR)
DEFINE _O_RELEASE      = "1202000100" (CHAR)
SQL> show pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 MYPDB                          READ WRITE NO
SQL>

همانگونه که میبینید پایگاه داده ما تنها یک pdb قابل استفاده دارد به نام mypdb که برای یکی دیگر از بیزینس های ما در حال استفاده است. حالا برای پایگاه داده جدید یک pdb میسازیم و در نظر داریم که OMF نباشد:

SQL> select name from v$datafile where con_id=2;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/db12c/pdbseed/system01.dbf
/u01/app/oracle/oradata/db12c/pdbseed/sysaux01.dbf
/u01/app/oracle/oradata/db12c/pdbseed/undotbs01.dbf

SQL> create pluggable database mas12c admin user pdb_mas identified by mas
  2  file_name_convert=('/u01/app/oracle/oradata/db12c/pdbseed/','/u01/app/oracle/oradata/db12c/mas12c/');

Pluggable database created.

SQL> select name from v$datafile where con_id=4;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/db12c/mas12c/system01.dbf
/u01/app/oracle/oradata/db12c/mas12c/sysaux01.dbf
/u01/app/oracle/oradata/db12c/mas12c/undotbs01.dbf

SQL> alter pluggable database mas12c open;

Pluggable database altered.

SQL> sho pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 MYPDB                          READ WRITE NO
         4 MAS12C                         READ WRITE NO

SQL> select name from v$active_services;

NAME
----------------------------------------------------------------
mas12c
db12c
SYS$BACKGROUND
SYS$USERS
db12cXDB
mypdb

6 rows selected.

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@oel7 ~]$ lsnrctl  status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 16-JAN-2018 12:50:04

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oel7)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                13-JAN-2018 12:29:24
Uptime                    3 days 0 hr. 20 min. 40 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/oel7/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oel7)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=oel7)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/db12c/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "62a5b72ff0115788e05380efa8c0a311" has 1 instance(s).
  Instance "db12c", status READY, has 1 handler(s) for this service...
Service "62e227d3146a2b60e05380efa8c0bc3a" has 1 instance(s).
  Instance "db12c", status READY, has 1 handler(s) for this service...
Service "db12c" has 1 instance(s).
  Instance "db12c", status READY, has 1 handler(s) for this service...
Service "db12cXDB" has 1 instance(s).
  Instance "db12c", status READY, has 1 handler(s) for this service...
Service "mas12c" has 1 instance(s).
  Instance "db12c", status READY, has 1 handler(s) for this service...
Service "mypdb" has 1 instance(s).
  Instance "db12c", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oel7 ~]$

همانگون که مشاهده نمودید pdb mas12c ایجاد شده و سرویس آن نیز قابل استفاده می باشد:


به نظر من بهترین راه وصل شدن به pdb ها استفاده از tns میباشد پس برای mas12c نیز یک tns میسازیم و به آن متصل میشویم:

vi $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.2/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_DB12C =
  (ADDRESS = (PROTOCOL = TCP)(HOST = oel7)(PORT = 1521))


DB12C =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oel7)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = db12c)
    )
  )

MYPDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oel7)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mypdb)
    )
  )

# new masoud's pdb
MAS12C =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oel7)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = mas12c)
    )
  )
[oracle@oel7 ~]$ tnsping mas12c 3

TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 16-JAN-2018 12:58:38

Copyright (c) 1997, 2016, Oracle.  All rights reserved.

Used parameter files:
/u01/app/oracle/product/12.2/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oel7)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mas12c)))
OK (0 msec)
OK (0 msec)
OK (0 msec)
[oracle@oel7 ~]$ sqlplus sys@mas12c as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 16 12:59:27 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Enter password:

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>
SQL>
SQL> def;
DEFINE _DATE           = "16-JAN-18" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "mas12c" (CHAR)
DEFINE _USER           = "SYS" (CHAR)
DEFINE _PRIVILEGE      = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1202000100" (CHAR)
DEFINE _EDITOR         = "vi" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production" (CHAR)
DEFINE _O_RELEASE      = "1202000100" (CHAR)
SQL>

بسیار خوب الان آماده هستیم که dump  را بر روی pdb جدید یعنی mas12c برگردانیم. پس شروع میکنیم:


اول یک directory برای import یا انتخاب میکنیم یا میسازیم. لازم به ذکر است در pdb ها از چیزی به نام GUID برای unique ساختن pdb ها استفاده میشود که در نام مسیر OMF فایل ها و همچنین directory پیشفرض استفاده میشود:

 SQL> select GUID from v$containers where name='MAS12C';

GUID
--------------------------------
62E227D3146A2B60E05380EFA8C0BC3A

SQL> select DIRECTORY_PATH from dba_directories where DIRECTORY_NAME='DATA_PUMP_DIR';

DIRECTORY_PATH
--------------------------------------------------------------------------------
/u01/app/oracle/admin/db12c/dpdump/62E227D3146A2B60E05380EFA8C0BC3A

ما میخواهیم از directory پیشفرض استفاده کنیم پس فقط اطمینان حاصل میکینم که مسیر وجود داشته باشد:

SQL> ! mkdir -p /u01/app/oracle/admin/db12c/dpdump/62E227D3146A2B60E05380EFA8C0BC3A

SQL> ! ls -ltr /u01/app/oracle/admin/db12c/dpdump/
total 4
-rw-r-----. 1 oracle oinstall 116 Jan 13 12:34 dp.log
drwxr-x---. 2 oracle oinstall   6 Jan 14 09:33 62A5B72FF0115788E05380EFA8C0A311
drwxr-x---. 2 oracle oinstall   6 Jan 16 13:18 62E227D3146A2B60E05380EFA8C0BC3A

الان import میکنیم:

[oracle@oel7 tmp]$ cp mas11g.dmp $ORACLE_BASE/admin/db12c/dpdump/62E227D3146A2B60E05380EFA8C0BC3A/

[oracle@oel7 tmp]$ sqlplus sys@mas12c as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 16 13:34:42 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Enter password:

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> create tablespace mas12c datafile '/u01/app/oracle/oradata/db12c/mas12c/mas12c01.dbf' size 100m autoextend on;

Tablespace created.

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@oel7 tmp]$ impdp schemas=mas11g dumpfile=mas11g.dmp remap_tablespace=MAS11G:mas12c;

Import: Release 12.2.0.1.0 - Production on Tue Jan 16 13:33:18 2018

Copyright (c) 1982, 2017, Oracle and/or its affiliates.  All rights reserved.

Username: sys@mas12c as sysdba
Password:

Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
Master table "SYS"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYS"."SYS_IMPORT_SCHEMA_01":  sys/********@mas12c AS SYSDBA schemas=mas11g dumpfile=mas11g.dmp remap_tablespace=MAS11G:mas12c
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "MAS11G"."MASOUD"                           5.437 KB       3 rows
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Job "SYS"."SYS_IMPORT_SCHEMA_01" successfully completed at Tue Jan 16 13:33:36 2018 elapsed 0 00:00:08

به نظر میاد که همه چی به درستی انجام شده، الان وقت آن هست که بررسی کنیم:

Alert log:
#########
create pluggable database mas12c admin user pdb_mas identified by *
file_name_convert=('/u01/app/oracle/oradata/db12c/pdbseed/','/u01/app/oracle/oradata/db12c/mas12c/')
2018-01-16T12:44:26.729345+03:30
PDB$SEED(2): AUDSYS.AUD$UNIFIED (SQL_TEXT) - CLOB populated
2018-01-16T12:44:35.081448+03:30
Warning: VKTM detected a forward time drift.
Please see the VKTM trace file for more details:
/u01/app/oracle/diag/rdbms/db12c/db12c/trace/db12c_vktm_23694.trc
2018-01-16T12:44:48.237126+03:30
MAS12C(4):Endian type of dictionary set to little
****************************************************************
Pluggable Database MAS12C with pdb id - 4 is created as UNUSABLE.
If any errors are encountered before the pdb is marked as NEW,
then the pdb must be dropped
local undo-1, localundoscn-0x00000000000000e1
****************************************************************
2018-01-16T12:44:51.934213+03:30
MAS12C(4):Autotune of undo retention is turned on.
2018-01-16T12:44:58.236021+03:30
MAS12C(4):[76640] Successfully onlined Undo Tablespace 2.
MAS12C(4):Undo initialization finished serial:0 start:264185920 end:264186491 diff:571 ms (0.6 seconds)
MAS12C(4):Database Characterset for MAS12C is AL32UTF8
MAS12C(4):JIT: pid 76640 requesting stop
2018-01-16T12:45:02.884741+03:30
Completed: create pluggable database mas12c admin user pdb_mas identified by *
file_name_convert=('/u01/app/oracle/oradata/db12c/pdbseed/','/u01/app/oracle/oradata/db12c/mas12c/')
2018-01-16T12:47:40.722781+03:30
alter pluggable database mas12c open
MAS12C(4):Autotune of undo retention is turned on.
2018-01-16T12:47:40.858347+03:30
MAS12C(4):Endian type of dictionary set to little
2018-01-16T12:47:44.292991+03:30
MAS12C(4):[76640] Successfully onlined Undo Tablespace 2.
MAS12C(4):Undo initialization finished serial:0 start:264350366 end:264352556 diff:2190 ms (2.2 seconds)
MAS12C(4):Deleting old file#5 from file$
MAS12C(4):Deleting old file#6 from file$
MAS12C(4):Deleting old file#8 from file$
MAS12C(4):Adding new file#13 to file$(old file#5)
MAS12C(4):Adding new file#14 to file$(old file#6)
MAS12C(4):Adding new file#15 to file$(old file#8)
2018-01-16T12:47:45.465437+03:30
MAS12C(4):Successfully created internal service mas12c at open
****************************************************************
Post plug operations are now complete.
Pluggable database MAS12C with pdb id - 4 is now marked as NEW.
****************************************************************
MAS12C(4):Database Characterset for MAS12C is AL32UTF8
2018-01-16T12:47:47.163318+03:30
MAS12C(4):Opatch validation is skipped for PDB MAS12C (con_id=0)
2018-01-16T12:48:14.999355+03:30
MAS12C(4):Opening pdb with no Resource Manager plan active
2018-01-16T12:48:18.120379+03:30
Pluggable database MAS12C opened read write
Completed: alter pluggable database mas12c open
2018-01-16T13:08:26.870085+03:30
MAS12C(4):Resize operation completed for file# 14, old size 337920K, new size 358400K
2018-01-16T13:27:02.656796+03:30

Schema Objets:
#########
[oracle@oel7 ~]$ sqlplus mas11g@mas12c

SQL*Plus: Release 12.2.0.1.0 Production on Tue Jan 16 13:51:55 2018

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Enter password:
Last Successful login time: Tue Jan 16 2018 13:51:49 +03:30

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> def;
DEFINE _DATE           = "16-JAN-18" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "mas12c" (CHAR)
DEFINE _USER           = "MAS11G" (CHAR)
DEFINE _PRIVILEGE      = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1202000100" (CHAR)
DEFINE _EDITOR         = "vi" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production" (CHAR)
DEFINE _O_RELEASE      = "1202000100" (CHAR)
SQL> select object_name, object_type from user_objects order by object_type;

OBJECT_NAME                              OBJECT_TYPE
---------------------------------------- --------------------------------------------------
SYS_C007400                              INDEX
MAS_SEQ                                  SEQUENCE
MASOUD                                   TABLE

SQL> select segment_name, segment_type, tablespace_name from user_segments;

SEGMENT_NAME                             SEGMENT_TYPE                             TABLESPACE_NAME
---------------------------------------- ---------------------------------------- ------------------------------
MASOUD                                   TABLE                                    MAS12C
SYS_C007400                              INDEX                                    MAS12C

SQL> select * from masoud;

        C1 C2
---------- ---------
         1 16-JAN-18
         2 16-JAN-18
         4 16-JAN-18

همانگونه که مشاهده نمودید به درستی و کامل از 11g به 12c مهاجرت کردیم.


دوستان عزیز امیدوارم مطلب کاربردی بوده باشد.


شاد و پیروز باشید.