12C pdb cdb常用命令

1. create pdb from pdb$seed 

SQL> create pluggable database pdb01 admin user admin identified by oracle file_name_convert=('/oradata/CDB/pdbseed/','/oradata/CDB/pdb01/');

Pluggable database created.

2.pdb open&close

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  MOUNTED

--打开指定pdb
SQL> alter pluggable database pdb01 open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  READ WRITE NO

--关闭指定pdb
SQL> alter pluggable database pdb01 close immediate;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  MOUNTED

--关闭所有pdb
SQL> alter pluggable database all open;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  READ WRITE NO

--打开所有pdb
SQL> alter pluggable database all close;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  MOUNTED

3.unplug pdb

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  READ WRITE NO

SQL> alter pluggable database pdb01 close immediate;

Pluggable database altered.

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  MOUNTED

SQL> alter pluggable database pdb01 unplug into '/home/oracle/pdb01.xml';

Pluggable database altered.

4.drop pdb

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 4 PDB01			  MOUNTED

--默认保留数据文件
SQL> drop pluggable database pdb01;

Pluggable database dropped.

--删除数据文件
--drop pluggable database pdb01 including datafiles;

SQL> show pdbs

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

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/oradata/CDB/system01.dbf
/oradata/CDB/sysaux01.dbf
/oradata/CDB/undotbs01.dbf
/oradata/CDB/pdbseed/system01.dbf
/oradata/CDB/pdbseed/sysaux01.dbf
/oradata/CDB/users01.dbf
/oradata/CDB/pdbseed/undotbs01.dbf

7 rows selected.

oracle@19c:/home/oracle$ ll /oradata/CDB/pdb01/
total 716824
-rw-r----- 1 oracle oinstall 346038272 Jan 13 17:33 sysaux01.dbf
-rw-r----- 1 oracle oinstall 283123712 Jan 13 17:33 system01.dbf
-rw-r----- 1 oracle oinstall 104865792 Jan 13 17:33 undotbs01.dbf

5.plug pdb from unplug pdb xml

oracle@19c:/home/oracle$ ls
pdb01.xml

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
SQL> create pluggable database pdb01 using '/home/oracle/pdb01.xml' nocopy;

Pluggable database created.

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDB01			  MOUNTED

6.switch pdb

SQL> show pdbs

    CON_ID CON_NAME			  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
	 2 PDB$SEED			  READ ONLY  NO
	 3 PDB01			  MOUNTED

SQL> alter pluggable database pdb01 open;

Pluggable database altered.

SQL> show pdbs

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

SQL> show con_name

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

SQL> alter session set container=pdb01;

Session altered.

SQL> show con_name

CON_NAME
------------------------------
PDB01

SQL> alter session set container=cdb$root;

Session altered.

SQL> show con_name

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

7.sqlplus use tns

--配置TNS
oracle@19c:/u01/app/oracle/product/19.3.0/db_1/network/admin$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_CDB =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 19c)(PORT = 1521))


PDB01 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 19c)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = pdb01)
    )
  )

CDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 19c)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdb)
    )
  )

--配置监听
oracle@19c:/u01/app/oracle/product/19.3.0/db_1/network/admin$ lsnrctl stat

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 13-JAN-2021 17:46:08

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=19c)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                13-JAN-2021 13:48:59
Uptime                    0 days 3 hr. 57 min. 9 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/19.3.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/19c/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=19c)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "86b637b62fdf7a65e053f706e80a27ca" has 1 instance(s).
  Instance "cdb", status READY, has 1 handler(s) for this service...
Service "b8c5b3b863cd2810e053c838a8c0b484" has 1 instance(s).
  Instance "cdb", status READY, has 1 handler(s) for this service...
Service "cdb" has 1 instance(s).
  Instance "cdb", status READY, has 1 handler(s) for this service...
Service "cdbXDB" has 1 instance(s).
  Instance "cdb", status READY, has 1 handler(s) for this service...
Service "pdb01" has 1 instance(s).
  Instance "cdb", status READY, has 1 handler(s) for this service...
The command completed successfully


--测试tns连通性
oracle@19c:/home/oracle$ tnsping cdb

TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 13-JAN-2021 17:46:55

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

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


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 19c)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = cdb)))
OK (10 msec)
oracle@19c:/home/oracle$ tnsping pdb01

TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 13-JAN-2021 17:46:59

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

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


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 19c)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = pdb01)))
OK (10 msec)


--连接cdb
oracle@19c:/home/oracle$ sqlplus sys/oracle@cdb as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jan 13 17:47:43 2021
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show con_name

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


--连接pdb
oracle@19c:/home/oracle$ sqlplus admin/oracle@pdb01

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jan 13 17:48:59 2021
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show con_name

CON_NAME
------------------------------
PDB01

 

 

 

 

 

 

 

 

 

 

上一篇:基于Linux C上的TCP/IP协议完成的电子点餐系统


下一篇:jdbc工具类的书写,mvc设计模式