Using RMAN in CDB or PDB

本文详细介绍了如何使用RMAN(恢复管理器)对Oracle数据库的CDB(容器数据库)和PDB(可插拔数据库)进行备份。包括通过连接到CDB$ROOT备份整个CDB、只备份根、单独备份PDB以及备份应用容器。同时,指出了直接连接到PDB备份的限制,如不能备份归档日志和执行某些恢复操作。此外,还涵盖了表空间和数据文件的备份方法。

  • Connecting as Target to a CDB/PDB
  1. 连接CDB$ROOT可以备份root、其下单个或多个PDB以及整个CDB, 如

BACKUP PLUGGABLE DATABASE sales, hr;

There are three most comon ways to connect as target to the root:

  1. Connecting locally as a common user:

$ rman target sys

  1. Connecting with operating system authentication:

$ rman target /

  1. Connecting as a common user through Oracle Net Services, using a net service name:

$ rman target c##bkuser@sales

  1. 连接PDB备份与一般Non-CDB备份命令相同,但有诸多限制并且不能使用catalog

Certain restrictions apply when you connect directly to a pluggable database (PDB):

The following operations are not available when you connect as target directly to a PDB:

  1. Back up archived logs
  2. Delete archived logs
  3. Delete archived log backups
  4. Restore archived logs (RMAN does restore archived logs when required during media recovery.)
  5. Point-in-time recovery (PITR) when using shared undo mode
  6. TSPITR
  7. Table recovery
  8. Duplicate database
  9. Flashback operations when using shared undo mode
  10. Running Data Recovery Advisor
  11. Report/delete obsolete
  12. Register database
  13. Import catalog
  14. Reset database
  15. Configuring the RMAN environment (using the CONFIGURE command)

Note: When you connect as TARGET to a PDB, you cannot connect to a recovery catalog.

直连PDB示例:

$ rman target hrbkup@hrpdb   (此用户可以common user也可是pdb自已用户)

  • Backing Up CDBs and PDBs
  1. Backing Up a Whole CDB

The BACKUP command is used to back up CDBs. You can then recover either the whole CDB, the root only, or one or more PDBs from the CDB backup. To backup up a whole CDB:

  1. Start RMAN and connect to the root as a common user with the SYSBACKUP or SYSDBA privilege and to a recovery catalog (if used)
  2. Ensure that the database is mounted or open.
  3. Issue the BACKUP DATABASE command at the RMAN prompt.

BACKUP DATABASE PLUS ARCHIVELOG;

Note: Proxy PDBs are not backed up while backing up a CDB.

  1. Backing Up the Root with RMAN

You can use RMAN to make a backup of only the root. Because the root contains critical metadata for the whole CDB, Oracle recommends that you back up the root or back up the whole CDB at regular intervals.

To back up the root with RMAN:

  1. Start RMAN and connect to the root as a common user with the SYSBACKUP or SYSDBA privilege.
  2. Enter the following command:

BACKUP DATABASE ROOT;

  1. Backing Up PDBs with RMAN

RMAN enables you to back up one or more PDBs in a CDB using the BACKUP command.

备份PDB可通过CDB$root或直连PDB备份,前者备份会有root及对应备份的PDB可见,而后者所有pdb的root均可见

There are two approaches to backing up a PDB with RMAN:

  1. Connect to the root and then use the BACKUP PLUGGABLE DATABASE command. This approach enables you to back up multiple PDBs with a single command.

When you connect to the root and back up a PDB, this backup is visible to the root and to that particular PDB but not to the other PDBs.

  1. Connect to the PDB and use the BACKUP DATABASE command. This approach backs up only a single PDB and enables you to use the same commands used for backing up non-CDBs.

Backups created when connected to any PDB are visible when connected to the root.

直连PDB的备份方式无法备份归档日志

When you back up individual PDBs, the archived redo logs are not backed up.

  1. To back up one or more PDBs while connected to the root:

Start RMAN and connect to the root as a common user with the SYSBACKUP or SYSDBA privilege.

Issue a BACKUP PLUGGABLE DATABASE command at the RMAN prompt.

BACKUP PLUGGABLE DATABASE sales, hr;

  1. To back up one PDB while connected to the PDB:

Start RMAN and connect to the PDB as a local user with the SYSBACKUP or SYSDBA privilege.

Issue a BACKUP DATABASE command at the RMAN prompt.

BACKUP DATABASE;

Note: Backing up a proxy PDB using RMAN is not supported.

  1. Backing Up Tablespaces and Data Files in a PDB

备份PDB的表空间与数据文件略有不同,因为表空间可能重名但数据文件号不会,表空间只能直接PDB备份,数据文件则可以在CDB$root中备份

Because tablespaces in different PDBs can have the same name, to eliminate ambiguity you must connect directly to a PDB to back up one or more of its tablespaces.

Ensure that the CDB is open or mounted. Tablespaces can be read-only or read-write.

In contrast, because data file numbers and paths are unique across the CDB, you can connect to either the root or a PDB to back up PDB data files. If you connect to the root, you can back up data files from multiple PDBs with a single command. If you connect to a PDB, you can back up only data files in that PDB.

To back up tablespaces in a PDB:

  1. Start RMAN and connect to the PDB as a local user with the SYSBACKUP or SYSDBA privilege.
  2. Issue a BACKUP TABLESPACE command.

BACKUP TABLESPACE users, examples;

To back up data files in a PDB:

  1. Do one of the following:

Start RMAN and connect to the root as a common user with the SYSBACKUP or SYSDBA privilege.

Start RMAN and connect to the PDB as a local user with the SYSBACKUP or SYSDBA privilege.

  1. Issue a BACKUP DATAFILE command.

BACKUP DATAFILE 10, 13;

  1. Backing Up Application Containers

RMAN enables you to use the BACKUP command to perform backup operations on the application root, one or more application PDBs, and the application container.

  1. Backing Up the Application Root

类似备份CDB$root

Use one of the following approaches to back up the application root:

  1. Connect to the application root and use the BACKUP DATABASE ROOT command

Start RMAN and connect to the application root as an application common user with the SYSDBA or SYSBACKUP privilege.

The application root has its own service name and you can connect to the application root in the same way that you connect to a PDB.

BACKUP DATABASE ROOT;

  1. Connect to the CDB root and use the BACKUP PLUGGABLE DATABASE command

Start RMAN and connect to the CDB root as a common user with the SYSDBA or SYSBACKUP privilege.

Use the BACKUP PLUGGABLE DATABASE command to back up the application root.

BACKUP PLUGGABLE DATABASE hr_appcont;

  1. Backing Up the Application Root and its Application PDBs

类似备份whole CDB

Start RMAN and connect to the application root as an application common user with the SYSDBA or SYSBACKUP privilege.

The application root has its own service name and you can connect to the application root in the same way that you connect to a PDB.

BACKUP DATABASE;

  1. Backing Up Application PDBs

Connect to the application root as an application common user with the SYSDBA or SYSBACKUP privilege.

The application root has its own service name and you can connect to the application root in the same way that you connect to a PDB.

Connect to the CDB root as a common user with the SYSDBA or SYSBACKUP privilege.

Use the BACKUP PLUGGABLE DATABASE command to back up the application PDB. To back up multiple application PDBs, use a comma-separated list of application PDB names.

BACKUP PLUGGABLE DATABASE hr_app_pdb;

### 介绍 - **CDB(Container Database)**:Oracle 12c引入的新概念,是多租户架构的基础。CDB包含多个独立的数据库,每个称为租户(PDB)。CDB本身只有一个控制文件、一个SGA和一个后台进程,这些资源可被所有租户共享。其主要优点是资源共享、多租户管理和数据隔离,能简化数据库管理和维护工作,提高数据库的可伸缩性和性能。CDB全称为Container Database,中文为数据库容器,相当于操作系统,调用并管理各个PDB [^1][^2][^3]。 - **PDB(Pluggable Database)**:同样是Oracle 12c引入的概念,是Oracle CDB中的一个独立数据库,可看作容器内的数据库。每个PDB有自己的系统表空间、用户表空间、数据文件、表、索引、视图等对象,且相互独立。PDB可与其他PDB共享一些资源,如共享表空间、共享服务、共享代码等。其主要优点是灵活性、可管理性和可移植性,管理员能更方便地管理多个数据库,也能更容易地将数据库从一个CDB迁移到另一个CDB,还提供了更好的资源隔离和更高的安全性。PDB全称为Pluggable Database,即可插拔数据库,相当于真正提供业务需求的数据库实例 [^1][^2][^3]。 ### 使用 - **查看当前是否处于容器CDB**:使用`show con_name;`命令,若结果为`CDB&ROOT`,则为容器状态(CBD);若结果为`ORCLPDB`(PDB名字根据实际情况而定),则为可插拔数据库(PDB) [^2]。 - **查看容器中的数据库名**:使用`show pdbs;`命令 [^2]。 - **切换到PDB**:使用`alter session set container=ORCLPDB`(PDB名字根据实际情况而定) [^2]。 - **切换到CDB**:使用`alter session set container=CDB&ROOT` [^2]。 - **管理工具**:Oracle提供了多种工具来监控和管理CDBPDB,包括Enterprise Manager、SQL*Plus、RMAN(Recovery Manager)等,可帮助数据库管理员了解数据库的性能、健康状况和安全性,并执行必要的维护任务 [^4]。 ### 区别 - **架构层面**:在ORACLE 12C之前,实例与数据库是一对一或多对一关系(RAC),即一个实例只能与一个数据库相关联,数据库可以被多个实例所加载,实例与数据库不可能是一对多的关系。进入ORACLE 12C后,实例与数据库可以是一对多的关系,一个CDB可承载多个PDB [^2]。 - **功能角色**:CDB相当于操作系统,负责调用并管理各个PDBPDB相当于真正提供业务需求的数据库实例 [^2]。 - **资源共享**:CDB的控制文件、SGA和后台进程等资源可被所有PDB共享;PDB有自己独立的系统表空间、用户表空间等对象,但也可与其他PDB共享一些资源,如共享表空间、共享服务、共享代码等 [^1]。 ### 代码示例 ```sql -- 查看当前是否处于容器CDB show con_name; -- 查看容器中的数据库名 show pdbs; -- 切换到PDB alter session set container=ORCLPDB; -- 切换到CDB alter session set container=CDB&ROOT; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值