8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Oracle Cloud] PDBにユーザーを作成して接続する手順まとめ

Last updated at Posted at 2020-08-04

はじめに

Oracle Cloud で提供されている Database Cloud Service では、PDB(Pluggable Database) が利用可能です。Default で作成される PDB にユーザーを作成して、接続する手順を備忘録で残しておきます。

PDB に ユーザーの作成

アプリケーションから接続するために、PDB にユーザを作成します。
DBCS へ SSH ログインしたのちに、oracle ユーザーへスイッチします。

[opc@oradb19ee ~]$ sudo su - oracle
Last login: Tue Aug  4 21:54:39 UTC 2020
[oracle@oradb19ee ~]$

SQL PLUS を起動して、CDB(Container Database) へ接続します

sqlplus / as sysdba

接続先が CDB か確認します

SQL> show con_name;

CON_NAME
------------------------------
CDB$ROOT

PDB の一覧を確認します

SQL> show pdbs;

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

PDB (PDB01) へ接続します

alter session set container=PDB01;

PDB に接続されているか確認します

SQL> show con_name;

CON_NAME
------------------------------
PDB01
SQL>

以下コマンドを実行して、PDB 上で、ユーザーの作成・権限の付与・表領域の上限解除を行います
また、プロファイルを変更してパスワードの有効期限を無制限にします。

CREATE USER sugi IDENTIFIED BY Sug1_Passw0rd_dayo;
GRANT CONNECT, RESOURCE TO sugi;
ALTER USER sugi quota unlimited on USERS;
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;

SQL*PLUS を終了します。

exit

PDB の Service Name 確認

lsnrctl status で、DBCS に Default で作成されているサービス名を表示します

[oracle@oradb19ee ~]$ lsnrctl status

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 04-AUG-2020 22:16:06

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

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                04-AUG-2020 08:57:59
Uptime                    0 days 13 hr. 18 min. 6 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/19.0.0.0/grid/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/oradb19ee/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.0.0.71)(PORT=1521)))
Services Summary...
Service "+APX" has 1 instance(s).
  Instance "+APX1", status READY, has 1 handler(s) for this service...
Service "+ASM" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_DATA" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "+ASM_RECO" has 1 instance(s).
  Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "a32a6f1b654541a5e053c105f40a57f6.pubsubnet01.vcn.oraclevcn.com" has 1 instance(s).
  Instance "oradb19", status READY, has 2 handler(s) for this service...
Service "ac0abef76ce358cee0534700000a887a.pubsubnet01.vcn.oraclevcn.com" has 1 instance(s).
  Instance "oradb19", status READY, has 2 handler(s) for this service...
Service "oradb19XDB.pubsubnet01.vcn.oraclevcn.com" has 1 instance(s).
  Instance "oradb19", status READY, has 1 handler(s) for this service...
Service "oradb19_nrt1r2.pubsubnet01.vcn.oraclevcn.com" has 1 instance(s).
  Instance "oradb19", status READY, has 2 handler(s) for this service...
Service "pdb01.pubsubnet01.vcn.oraclevcn.com" has 1 instance(s).
  Instance "oradb19", status READY, has 2 handler(s) for this service...
The command completed successfully
[oracle@oradb19ee ~]$

表示結果の中で一番下に pdb01.pubsubnet01.vcn.oraclevcn.com と表示されております。自分は、DBCS を作成する際に pdb の名前を odb01 と指定しており、pdb名でサービスが作成されています。

接続

Oracle Client 側から、Oracle Database の PDB で作成した sugi ユーザーに接続をしていきます。まずは、Client 側で tnsnames.ora を作成します。

vim $ORACLE_HOME/network/admin/tnsnames.ora

編集例

pdb01=
(DESCRIPTION=
  (LOAD_BALANCE=off) 
  (ADDRESS=
    (PROTOCOL=tcp)  
    (HOST=<oracle db ip address>)  
    (PORT=1521)
  ) 
  (CONNECT_DATA=
    (SERVICE_NAME=pdb01.pubsubnet01.vcn.oraclevcn.com) 
    (FAILOVER_MODE=
      (TYPE=select) 
      (METHOD=basic)
    )
  )
)

tnsping で正常に接続できるか確認できます。一番下に OK と表示されていれば大丈夫です。

[oracle@oradb19ee ~]$ tnsping pdb01

TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 04-AUG-2020 22:29:46

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

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


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (LOAD_BALANCE=off) (ADDRESS= (PROTOCOL=tcp) (HOST=<oracle db ip address>) (PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=pdb01.pubsubnet01.vcn.oraclevcn.com) (FAILOVER_MODE= (TYPE=select) (METHOD=basic))))
OK (0 msec)
[oracle@oradb19ee ~]$

接続するときは次の形式です。ユーザー名/パスワード@tnsname を指定します。

sqlplus sugi/Sug1_Passw0rd_dayo@pdb01
8
3
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
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?