0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[23c] PDBのRELOCATE(再配置)を試す

Posted at

PDBのRELOCATE(再配置)を試す

PDBの再配置を試してみます。
機能自体は12cから使用可能ですが、23c(Cloud)環境ということで
多少気にする部分がでてきます。

再配置の動作イメージ

image.png

再配置の目的
・PDBの停止時間なし、または停止時間最小で移動する最速の方法です
・特にCLONEやCOPYを行うと大規模データベースではデータファイルのコピーに時間がかかるため、それらを簡略化できます

再配置の仕組み
・事前にPDBをコピーし、RELOCATE時にUNDO,REDOを含めたデータを同期します

詳しくはマニュアルを参照してください。
Oracle Database 23c 管理者(Multitenant)マニュアル

RELOCATE実装例

①ソースDBでの設定

ソースPDBがあるCDBに接続して、リンク用DBユーザを作成します。
SYSTEMユーザーを使用することも可能ですが、下記権限は付与してください。

・create user c##relocateuser1 identified by Test#1Test#1;
・grant create session , create pluggable database , sysoper to c##relocateuser1 container=all;

実行例

[oracle@db23c1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 23.0.0.0.0 - Production on Fri Jan 26 04:58:40 2024
Version 23.3.0.23.09

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


Connected to:
Oracle Database 23c Enterprise Edition Release 23.0.0.0.0 - Production
Version 23.3.0.23.09


SQL> create user c##relocateuser1 identified by Test#1Test#1;

User created.

SQL> grant create session , create pluggable database , sysoper to c##relocateuser1 container=all;

Grant succeeded.

SQL> show pdbs

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

②ターゲットDBでの設定

再配置先のCDBに接続して、ソースDBに向けたDBリンクを作成します。
その後、RELOCATEのPDBを作成します。

・TNSの定義
・alter session set global_names = FALSE;
・create database link relocatelink1 connect to c##relocateuser1 identified by Test#1Test#1 using 'CDB1';
・create pluggable database pdb1 from pdb1@relocatelink1 keystore identified by Test#2Test#2 relocate AVAILABILITY MAX;

実行例

★ソースPDBがあるCDBに対して接続識別子を定義します★

[oracle@db23c2 ~]$ cd $ORACLE_HOME/network/admin
[oracle@db23c2 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/23.0.0.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_CDB2 =
  (ADDRESS = (PROTOCOL = TCP)(HOST = db23c2)(PORT = 1521))


CDB2_ZSX_NRT =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = db23c2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = CDB2_zsx_nrt.xxx.xxx.oraclevcn.com)
    )
  )

[oracle@db23c2 admin]$ vi tnsnames.ora


CDB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 111.222.111.222)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)                                                            (SERVICE_NAME = CDB1_8hk_nrt.xxx.xxx.oraclevcn.com)
    )
  )



[oracle@db23c2 admin]$ tnsping cdb1

TNS Ping Utility for Linux: Version 23.0.0.0.0 - Production on 26-JAN-2024 04:41:01

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

Used parameter files:
/u01/app/oracle/product/23.0.0.0/dbhome_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 111.222.111.222)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = CDB1_8hk_nrt.xxx.xxx.oraclevcn.com)))
OK (0 msec)
[oracle@db23c2 admin]$


★ターゲットCDBにDBリンクを作成し、それを使ってリロケートPDBを作成します★

[oracle@db23c2 admin]$ sqlplus / as sysdba

SQL*Plus: Release 23.0.0.0.0 - Production on Fri Jan 26 04:41:16 2024
Version 23.3.0.23.09

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


Connected to:
Oracle Database 23c Enterprise Edition Release 23.0.0.0.0 - Production
Version 23.3.0.23.09

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB2                           READ WRITE NO

SQL> alter session set  global_names = FALSE;

Session altered.


SQL> create database link relocatelink1 connect to  c##relocateuser1 identified by Test#1Test#1 using 'CDB1';

Database link created.

SQL> select * from dual@relocatelink1;

D
-
X

★ Cloud環境ではkeystoreでTDEパスワードが必要になってきます。CDB2側のパスワードです。 ★
SQL> create pluggable database pdb1 from pdb1@relocatelink1 keystore identified by Test#2Test#2 relocate AVAILABILITY MAX;

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB2                           READ WRITE NO
         4 PDB1                           MOUNTED
SQL>


③テスト用データ挿入

テスト用のデータ挿入した例です。
RELOCATE用のPDBを作成した後にユーザやテーブルを作成し、
データが引き継がれるかを確認します。

実行例



SQL> create user test identified by Test#1Test#1;

User created.


SQL> grant create session,create table ,unlimited tablespace to test;

Grant succeeded.
SQL> conn test/Test#1Test#1@PDB1
Connected.
SQL> create table t1 ( id number );

Table created.

SQL> insert into t1 values(1);
c
1 row created.

SQL>
SQL> commit;

Commit complete.

SQL> select * from t1;

        ID
----------
         1

④PDBのリロケート(再配置)実行

ターゲット側のPDBをOPENすると、RELOCATEが実行されます。
ソース側のPDBはMOUNTとなります。

・alter pluggable database pdb1 open;

実行例


SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB2                           READ WRITE NO
         4 PDB1                           MOUNTED
SQL> alter pluggable database pdb1 open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB2                           READ WRITE NO
         4 PDB1                           READ WRITE NO
SQL> alter session set container=pdb1;

Session altered.

SQL> select * from test.t1;

        ID
----------
         1

SQL>

ソース側の確認(PDBがMOUNTになった)

SQL> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB1                           MOUNTED
SQL>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?