本文描述
1.本文描述如何在Oracle 19C及以上版本导出PDB中的数据
2.本文中使用的19.3 RAC初始版本为示例未打补丁
基本环境
PDB Name: pdb
Schema Name:Scott
当前数据库服务器环境
[oracle@rac02 ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
PDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PDB)
)
)
--当前环境变量
[oracle@rac02 ~]$ env |grep ORACLE
ORACLE_UNQNAME=orcl
ORACLE_SID=orcl2
ORACLE_BASE=/u01/app/oracle
ORACLE_TERM=xterm
ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
--登陆查看当前数据库CDB&PDB情况
[oracle@rac02 ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Jan 15 08:25:09 2025
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
/******堆代码 duidaima.com ******/
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> SHOW PDBS;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB READ WRITE NO
--当前监听状态
[oracle@rac01 ~]$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 15-JAN-2025 08:42:15
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 15-JAN-2025 20:24:07
Uptime 0 days 1 hr. 18 min. 8 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/19.3.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/rac01/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.90)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.92)(PORT=1521)))
Services Summary...
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_OCR" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "0b74bb4121154089e0635a38a8c06ef6" has 1 instance(s).
Instance "orcl1", status READY, has 1 handler(s) for this service...
Service "86b637b62fdf7a65e053f706e80a27ca" has 1 instance(s).
Instance "orcl1", status READY, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl1", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl1", status READY, has 1 handler(s) for this service...
Service "pdb" has 1 instance(s).
Instance "orcl1", status READY, has 1 handler(s) for this service...
The command completed successfully
操作步骤
Step:1 创建目录directory
export ORACLE_PDB_SID=PDB
sqlplus / as sysdba
create directory expdp2025 as '/u01/expdp';
grant read,write on directory expdp2025 to public;
Step 2 在操作系统下创建对应目录并赋予权限
--root登陆操作系统
mkdir -p /u01/expdp
chown oracle:dba /u01/expdp
Step:3 导出PDB下Scott,cluster=no参数在一个节点导出数据时使用
expdp SCOTT/TIGGER@pdb directory=expdp2025 CLUSTER=no dumpfile=scott.dmp LOGFILE=scott.log
或者使用sysdba用户导出
export ORACLE_PDB_SID=PDB
expdp \'/ as sysdba\' directory=expdp2025 schemas=SCOTT CLUSTER=no dumpfile=scott.dmp LOGFILE=scott.log </dev/null
这里加</dev/null是因为有一个小BUG导致的,不加就会仍提示要sys密码。在19.7中修复该BUG。
执行导出结果
[oracle@rac02 admin]$ expdp \'/ as sysdba\' directory=expdp2025 schemas=SCOTT CLUSTER=no dumpfile=scott.dmp LOGFILE=scott.log </dev/null
Export: Release 19.0.0.0.0 - Production on Wed Jan 15 09:25:21 2025
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
Password:
Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Starting "SYS"."SYS_EXPORT_SCHEMA_02": "/******** AS SYSDBA" directory=expdp2025 schemas=SCOTT CLUSTER=no dumpfile=scott.dmp LOGFILE=scott.log
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
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/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."BONUS" 0 KB 0 rows
. . exported "SCOTT"."DEPT" 6.023 KB 4 rows
. . exported "SCOTT"."EMP" 8.695 KB 12 rows
. . exported "SCOTT"."SALGRADE" 5.953 KB 5 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_02" successfully loaded/unloaded
******************************************************************************
Dump file setfor SYS.SYS_EXPORT_SCHEMA_02 is:
/u01/expdp/scott.dmp
Job "SYS"."SYS_EXPORT_SCHEMA_02" successfully completed at Wed Jan 15 22:26:57 2025 elapsed 0 00:01:27
[oracle@rac02 admin]$