2016年12月23日 星期五

Oracle Database 12c Release 1 (12.1) Multitenant: Oracle Pluggable Database

Using DBMS_PDB:

最近研究下Oracle 12c中的新特性,下面主要是記錄 convert non-cdb to cdb

1. orcl is non-cdb database
2. orclcdb is cdb database

可以先建立好 CDB 空殼即可

SQL> select name,CDB from v$database;
NAME      CDB
--------- ---
orclcdb      YES

SQL> select name,CDB from v$database;
NAME      CDB
--------- ---
orcl      NO

[oracle@oracle12c ~]$ echo $ORACLE_SID
orcl
[oracle@oracle12c ~]$ sqlplus  / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Fri Dec 23 11:39:18 2016
Copyright (c) 1982, 2014, Oracle.  All rights reserved.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup open read only;
ORACLE instance started.

Total System Global Area 2315255808 bytes
Fixed Size                  2926952 bytes
Variable Size            1409287832 bytes
Database Buffers          889192448 bytes
Redo Buffers               13848576 bytes
Database mounted.
Database opened.



Datafile Location
SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u02/oradata/orcl/system01.dbf
/u02/oradata/orcl/gp_data01.dbf
/u02/oradata/orcl/sysaux01.dbf
/u02/oradata/orcl/undotbs01.dbf
/u02/oradata/orcl/gerp01.dbf
/u02/oradata/orcl/users01.dbf
/u02/oradata/orcl/perfstat.dbf
/u02/oradata/orcl/data_03.dbf
/u02/oradata/orcl/duty_03.dbf
/u02/oradata/orcl/duty_01.dbf
/u02/oradata/orcl/gerp02.dbf
/u02/oradata/orcl/data_02.dbf
/u02/oradata/orcl/users02.dbf
/u02/oradata/orcl/users03.dbf
/u02/oradata/orcl/users04.dbf
/u02/oradata/orcl/users05.dbf
/u02/oradata/orcl/users06.dbf
/u02/oradata/orcl/users07.dbf
/u02/oradata/orcl/users08.dbf
/u02/oradata/orcl/users09.dbf
/u02/oradata/orcl/data_01.dbf
/u03/oraindx/orcl/indx01.dbf
/u03/oraindx/orcl/indx02.dbf
/u02/oradata/orcl/duty_02.dbf

24 rows selected.



使用DBMS_PDB.DESCRIBE  non-CDB    創建 XML 描述文件。
SQL> BEGIN
  DBMS_PDB.DESCRIBE(
    pdb_descr_file => '/cdb/orcl.xml');      --> 此路徑自己設定
END;
/
PL/SQL procedure successfully completed.



Execute the Plug In Check and check PDB_PLUG_IN_VIOLATIONS when the result of the plug in check is
"NO":
SQL> SET SERVEROUTPUT ON
DECLARE
compatible CONSTANT VARCHAR2(3) := CASE
DBMS_PDB.CHECK_PLUG_COMPATIBILITY(
pdb_descr_file => '/cdb/orcl.xml',
pdb_name => 'pdborcl2')
WHEN TRUE THEN 'YES' ELSE 'NO'
END;
BEGIN
DBMS_OUTPUT.PUT_LINE(compatible);
END;
/

PL/SQL procedure successfully completed.

select message, type, status from pdb_plug_in_violations where type like '%ERR%';


Shutdown the non-CDB database.
export ORACLE_SID=orcl
sqlplus / as sysdba
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.



連接到 CDB 並使用 non-CDB 描述數據庫的XML文件創建新的PDB。 請記得配置FILE_NAME_CONVERT參數將現有文件轉換為新位置。
[oracle@oracle12c ~]$ export ORACLE_SID=orclcdb
[oracle@oracle12c ~]$ echo $ORACLE_SID
orclcdb

sqlplus / as sysdba

SQL> CREATE PLUGGABLE DATABASE pdborcl USING '/cdb/orcl.xml'
COPY
FILE_NAME_CONVERT = ('/u02/oradata/orcl/','/cdb/oradata/orclcdb/pdborcl/','/u03/oraindx/orcl/','/cdb/oradata/orclcdb/pdborcl/');

Pluggable database created.

切換到 PDB container 並且執行 "$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql" script 
ALTER SESSION SET CONTAINER=pdborcl;

@$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql

開啟 PDB 並且確認
ALTER SESSION SET CONTAINER=pdborcl;
ALTER PLUGGABLE DATABASE OPEN;

SQL> SELECT name, open_mode FROM v$pdbs;

NAME                           OPEN_MODE
------------------------------ ----------
PDBORCL                        READ WRITE

1 row selected.

SQL>

確認目前狀態沒問題,最好備份一次。
SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         3 PDBORCL                        READ WRITE NO

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

1 row selected.

SQL> select name, CDB from v$database;

NAME      CDB
--------- ---
ORCLCDB   YES

1 row selected.

2015年11月25日 星期三

nfs server step

Server 端

Using NFS to Share Files

NFS (Network File System) is another way of sharing files across a network. It is used primarily in Linux and UNIX systems, although there are NFS clients for Windows.

Installing NFS

1. Use the following command to install NFS:
   rpm -qa nfs-utils nfs-utils-lib 檢查有無安裝 NFS Package
 
   or

   yum -y install nfs-utils nfs-utils-lib

Configuring NFS

Configuration of NFS is pretty simple. You add the directories you wish to export to the file /etc/exports.

2. Create a directory called /public with the following command:

   mkdir -p /u01/app/oracle/oradata/arch

3. Next, edit the file /etc/exports:

   vi /etc/exports

4. Add the following line to /etc/exports:
   
   ex: /public    *(ro,sync)

   /u01/app/oracle/oradata/arch 10.1.1.59(rw,no_root_squash,no_all_squash,sync)

5. Mount
   [root@standby ~]# exportfs -r 重新掛載 /etc/exports 裡面的設定
   [root@standby ~]# exportfs -v
   /u01/app/oracle/oradata/arch 10.1.1.59(rw,wdelay,no_root_squash,no_subtree_check,anonuid=65534,anongid=65534)
   [root@standby ~]# showmount -e localhost
   Export list for localhost:
   /u01/app/oracle/oradata/arch 10.1.1.59

Then, start the nfs server:

        /etc/rc.d/init.d/nfs start

Client 端

確認是否有 server 端是否有提供 NFS 掛載
[root@primary ~]$ showmount -e 10.1.1.60
Export list for 10.1.1.60:
/u01/app/oracle/oradata/arch 10.1.1.59

--add parameter
vim /etc/fstab
10.1.1.60:/u01/app/oracle/oradata/arch    /u01/app/oracle/oradata/arch               nfs     rw              0 0

手動 mount
# mount -t nfs 10.1.1.60:/u01/app/oracle/oradata/arch /u01/app/oracle/oradata/arch

若 alert log file 出現下面錯誤訊息
ORA-27086: unable to lock file - already in use
Linux-x86_64 Error: 37: No locks available
Additional information: 10

解决方法:掛載時使用 nolock 參數
# umount /u02/arch/
# mount -o nolock -t nfs 10.1.1.60:/backup/arch /u02/arch/