Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
oracle_multitenant_overview [2021/11/11 21:25] – [Hot clone] andonovj | oracle_multitenant_overview [2021/11/13 21:51] (current) – andonovj | ||
---|---|---|---|
Line 13: | Line 13: | ||
* Application Container - Container which consist of 1 or many PDBs which host a specific application. We are able to assign versions and name to such container, furthermore we can initiate installation and upgrade modes. | * Application Container - Container which consist of 1 or many PDBs which host a specific application. We are able to assign versions and name to such container, furthermore we can initiate installation and upgrade modes. | ||
- | =====Creation===== | + | ===== Using SQL ===== |
Firstly, we need to create our container. From 12c, we can create a database to be either as it always has been, a normal database, OR we can create it to allow other databases as well. So it will be a container, let's see how we can do both: | Firstly, we need to create our container. From 12c, we can create a database to be either as it always has been, a normal database, OR we can create it to allow other databases as well. So it will be a container, let's see how we can do both: | ||
- | ==== Create Normal DB === | + | ==== Creation |
Actually, the creation of a normal database isn't that hard, you can just type: | Actually, the creation of a normal database isn't that hard, you can just type: | ||
Line 94: | Line 94: | ||
Furthermore, | Furthermore, | ||
- | ===== Management | + | ===== Using DBCA ===== |
- | We can perform several actions with a PDB: | + | We can use DBCA to create and delete CDB and PDBs as follows: |
- | * OPEN | + | < |
- | * Plug & Unplig | + | # Local container (cdb1). |
- | * Close | + | dbca -silent -createDatabase \ |
- | * Restore | + | -templateName General_Purpose.dbc \ |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
- | ==== Open ==== | + | # Remote container (cdb3) with PDB (pdb5). |
- | After we create a CDB, we need to open it, as follows: | + | dbca -silent -createDatabase \ |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | -ignorePreReqs | ||
- | < | + | # Non-CDB instance (db12c). |
- | SQL> ALTER PLUGGABLE DATABASE pdb2 OPEN; | + | dbca -silent -createDatabase \ |
- | </ | + | -templateName General_Purpose.dbc \ |
- | + | -gdbname db12c -sid db12c -responseFile NO_VALUE \ | |
- | That command, will open us a database and it will become available to the users. | + | -characterSet AL32UTF8 \ |
- | We can also close a pluggable database as follows: | + | -sysPassword SysPassword1 \ |
- | + | -systemPassword SysPassword1 \ | |
- | < | + | -createAsContainerDatabase false \ |
- | ALTER PLUGGABLE DATABASE pdb2 CLOSE IMMEDIATE; | + | -databaseType MULTIPURPOSE \ |
- | </Code> | + | -memoryMgmtType auto_sga \ |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
- | ==== Unplug a PDB ==== | + | # Delete |
- | In 12.1 we could unplug a PDB into .xml file and the migration of the PDB, would be the migration of that XML file AND the relevant database files. | + | #dbca -silent -deleteDatabase -sourceDB cdb1 -sysDBAUserName sys -sysDBAPassword SysPassword1 |
- | From 12.2 we can also unplug the PDB into a .pdb archive file, which contains information about the PDB AND the relevant database files. That will ease our migration. | + | dbca -silent -deleteDatabase -sourceDB cdb3 -sysDBAUserName sys -sysDBAPassword SysPassword1 |
+ | dbca -silent -deleteDatabase -sourceDB db12c -sysDBAUserName sys -sysDBAPassword SysPassword1 | ||
- | < | + | #Configure OMF |
export ORAENV_ASK=NO | export ORAENV_ASK=NO | ||
export ORACLE_SID=cdb3 | export ORACLE_SID=cdb3 | ||
Line 126: | Line 169: | ||
export ORAENV_ASK=YES | export ORAENV_ASK=YES | ||
- | sqlplus / as sysdba | + | sqlplus / as sysdba <<EOF |
- | ALTER PLUGGABLE DATABASE pdb5 CLOSE; | + | |
- | ALTER PLUGGABLE DATABASE pdb5 UNPLUG INTO '/ | + | |
- | </Code> | + | |
- | That assumes, you are using OMF file. The resulting file contains all the necessary data: | + | ALTER SYSTEM |
- | + | ||
- | < | + | |
- | HOST ls -al / | + | |
- | -rw-r--r--. 1 oracle oinstall 161702502 Jan 7 21:01 / | + | |
- | + | ||
- | SQL> | + | |
- | </ | + | |
- | + | ||
- | ====Plug a PDB==== | + | |
- | To plug a database, we need the file from above and we need to verify the compatibility as follows: | + | |
- | < | + | |
- | SET SERVEROUTPUT ON | + | |
- | DECLARE | + | |
- | l_result BOOLEAN; | + | |
- | BEGIN | + | |
- | l_result := DBMS_PDB.check_plug_compatibility( | + | |
- | pdb_descr_file => '/u01/ | + | |
- | pdb_name | + | |
- | + | ||
- | IF l_result THEN | + | |
- | DBMS_OUTPUT.PUT_LINE(' | + | |
- | ELSE | + | |
- | DBMS_OUTPUT.PUT_LINE(' | + | |
- | END IF; | + | |
- | END; | + | |
- | / | + | |
- | compatible | + | |
- | + | ||
- | PL/SQL procedure successfully completed. | + | |
- | + | ||
- | SQL> | + | |
- | </ | + | |
- | + | ||
- | === Create a PDB using the source file === | + | |
- | Then we can create a PDB using the .pdb file as follows: | + | |
- | + | ||
- | < | + | |
- | CREATE PLUGGABLE DATABASE pdb5 USING '/ | + | |
- | + | ||
- | ALTER PLUGGABLE DATABASE pdb5 OPEN READ WRITE; | + | |
- | + | ||
- | SELECT name, open_mode | + | |
- | FROM | + | |
- | ORDER BY name; | + | |
- | + | ||
- | NAME | + | |
- | ------------------------------ ---------- | + | |
- | PDB$SEED | + | |
- | PDB5 | + | |
- | + | ||
- | SQL> | + | |
- | </ | + | |
- | + | ||
- | ====Clone a PDB==== | + | |
- | We can clone a PDB as follows: | + | |
- | + | ||
- | < | + | |
- | -- Setting the source to read-only is not necessary for Oracle 12cR2 with local undo, if you use 12.1 or 12.2 without local undo, it is needed: | + | |
- | ALTER PLUGGABLE DATABASE pdb3 CLOSE; | + | |
- | ALTER PLUGGABLE DATABASE pdb3 OPEN READ ONLY; | + | |
- | + | ||
- | + | ||
- | + | ||
- | CREATE PLUGGABLE DATABASE pdb4 FROM pdb3 | + | |
- | FILE_NAME_CONVERT=('/ | + | |
- | + | ||
- | ALTER PLUGGABLE DATABASE pdb4 OPEN READ WRITE; | + | |
- | + | ||
- | + | ||
- | + | ||
- | -- Switch the source PDB back to read/write if you made it read-only. | + | |
- | ALTER PLUGGABLE DATABASE pdb3 CLOSE; | + | |
- | ALTER PLUGGABLE DATABASE pdb3 OPEN READ WRITE; | + | |
- | </ | + | |
- | + | ||
- | ==== Clone a remote PDB (12.1) ==== | + | |
- | For that feature, you need to be at least: 12.1.0.2, there is a big with 12.1.0.1. | + | |
- | Furthermore, | + | |
- | + | ||
- | * Clone from PDB within other CDB | + | |
- | * Clone a non-CDB | + | |
- | + | ||
- | For both, there are the following pre-requisites: | + | |
- | + | ||
- | ===Pre-requisites=== | + | |
- | * The user in the local database must have the CREATE PLUGGABLE DATABASE privilege in the root container. | + | |
- | * The remote database (PDB or non-CDB) must be open in read-only mode. | + | |
- | * The local database must have a database link to the remote database. If the remote database is a PDB, the database link can point to the remote CDB using a common user, or the PDB using a local or common user. | + | |
- | * The user in the remote database that the database link connects to must have the CREATE PLUGGABLE DATABASE privilege. | + | |
- | * The local and remote databases must have the same endianness, options installed and character sets. | + | |
- | * If the remote database uses Transparent Data Encryption (TDE) the local CDB must be configured appropriately before attempting the clone. If not you will be left with a new PDB that will only open in restricted mode. | + | |
- | * The default tablespaces for each common user in the remote PDB *must* exist in local CDB. If this is not true, create the missing tablespaces in the root container of the local PDB. If you don't do this your new PDB will only be able to open in restricted mode (Bug 19174942). | + | |
- | * When cloning from a non-CDB, both the the local and remote databases must using version 12.1.0.2 or higher. | + | |
- | + | ||
- | ===Clone from a PDB in another CDB === | + | |
- | As explained, we need to create a user and open the remote PDB in read only, and create Link in the local one: | + | |
- | + | ||
- | ==On remote== | + | |
- | < | + | |
- | export ORAENV_ASK=NO | + | |
- | export ORACLE_SID=cdb3 | + | |
- | . oraenv | + | |
- | export ORAENV_ASK=YES | + | |
- | + | ||
- | sqlplus / as sysdba | + | |
- | + | ||
- | ALTER SESSION SET CONTAINER=pdb5; | + | |
- | + | ||
- | CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user; | + | |
- | GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO remote_clone_user; | + | |
- | + | ||
- | CONN / AS SYSDBA | + | |
- | ALTER PLUGGABLE DATABASE pdb5 CLOSE; | + | |
- | ALTER PLUGGABLE DATABASE pdb5 OPEN READ ONLY; | + | |
- | EXIT; | + | |
- | </ | + | |
- | + | ||
- | Then we can move to the local machine and create the link: | + | |
- | + | ||
- | ==On local== | + | |
- | < | + | |
- | ###Edit local tnsnames.ora | + | |
- | PDB5 = | + | |
- | (DESCRIPTION = | + | |
- | (ADDRESS_LIST = | + | |
- | (ADDRESS = (PROTOCOL = TCP)(HOST = ol7-121.localdomain)(PORT = 1521)) | + | |
- | ) | + | |
- | (CONNECT_DATA = | + | |
- | (SERVICE_NAME = pdb5) | + | |
- | ) | + | |
- | ) | + | |
- | + | ||
- | export ORAENV_ASK=NO | + | |
- | export ORACLE_SID=cdb1 | + | |
- | . oraenv | + | |
- | export ORAENV_ASK=YES | + | |
- | + | ||
- | sqlplus / as sysdba | + | |
- | + | ||
- | CREATE DATABASE LINK clone_link | + | |
- | CONNECT TO remote_clone_user IDENTIFIED BY remote_clone_user USING ' | + | |
- | + | ||
- | -- Test link. | + | |
- | DESC user_tables@clone_link | + | |
- | + | ||
- | CREATE PLUGGABLE DATABASE pdb5new FROM pdb5@clone_link; | + | |
- | + | ||
- | Pluggable database created. | + | |
- | + | ||
- | SQL> | + | |
- | + | ||
- | SELECT name, open_mode FROM v$pdbs WHERE name = ' | + | |
- | + | ||
- | NAME | + | |
- | ------------------------------ ---------- | + | |
- | PDB5NEW | + | |
- | + | ||
- | SQL> | + | |
- | + | ||
- | ALTER PLUGGABLE DATABASE pdb5new OPEN; | + | |
- | + | ||
- | SELECT name, open_mode FROM v$pdbs WHERE name = ' | + | |
- | + | ||
- | NAME | + | |
- | ------------------------------ ---------- | + | |
- | PDB5NEW | + | |
- | + | ||
- | SQL> | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ==== Clone a non-CDB ==== | + | |
- | Non-CDB in this case, refers to normal database, pre 12c | + | |
- | So let's see how it will be done. As before we need to create a user and bring the whole database in read only mode: | + | |
- | + | ||
- | ==On remote== | + | |
- | < | + | |
- | export ORAENV_ASK=NO | + | |
- | export ORACLE_SID=db12c | + | |
- | . oraenv | + | |
- | export ORAENV_ASK=YES | + | |
- | + | ||
- | sqlplus / as sysdba | + | |
- | + | ||
- | CREATE USER remote_clone_user IDENTIFIED BY remote_clone_user; | + | |
- | GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE TO remote_clone_user; | + | |
SHUTDOWN IMMEDIATE; | SHUTDOWN IMMEDIATE; | ||
STARTUP MOUNT; | STARTUP MOUNT; | ||
- | ALTER DATABASE | + | ALTER DATABASE |
- | EXIT; | + | ALTER DATABASE OPEN; |
- | </ | + | |
- | Then on the local we have to do the same as before: | + | ALTER PLUGGABLE DATABASE pdb5 OPEN; |
- | + | ALTER PLUGGABLE | |
- | ==On local== | + | |
- | + | ||
- | < | + | |
- | DB12C = | + | |
- | (DESCRIPTION = | + | |
- | (ADDRESS_LIST = | + | |
- | (ADDRESS = (PROTOCOL = TCP)(HOST = ol7-121.localdomain)(PORT = 1521)) | + | |
- | ) | + | |
- | (CONNECT_DATA = | + | |
- | (SERVICE_NAME = db12c) | + | |
- | ) | + | |
- | ) | + | |
- | + | ||
- | export ORAENV_ASK=NO | + | |
- | export ORACLE_SID=cdb1 | + | |
- | . oraenv | + | |
- | export ORAENV_ASK=YES | + | |
- | + | ||
- | sqlplus / as sysdba | + | |
- | + | ||
- | CREATE | + | |
- | CONNECT TO remote_clone_user IDENTIFIED BY remote_clone_user USING ' | + | |
- | + | ||
- | -- Test link. | + | |
- | DESC user_tables@clone_link | + | |
+ | EXIT; | ||
+ | EOF | ||
</ | </ | ||
- | Then we can create the PDBs as follows: | ||
- | < | + | ===== Automation ===== |
- | CREATE PLUGGABLE DATABASE db12cpdb FROM NON$CDB@clone_link; | + | Using the awesome power, vested to me by Vagrant and Bash, I summon the automation of: |
- | Pluggable | + | * Virtual Machine |
+ | * Oracle 19c database | ||
+ | * 1 CDB | ||
+ | * 1 PDB | ||
- | SQL> | + | All that, twice: |
- | SELECT name, open_mode FROM v$pdbs WHERE name = ' | ||
- | NAME | + | < |
- | ------------------------------ ---------- | + | $allow_shell = << |
- | DB12CPDB | + | sed -i ' |
+ | systemctl restart sshd.service | ||
+ | SCRIPT | ||
- | SQL> | + | $edit_hosts_file = << |
- | ALTER SESSION SET CONTAINER=db12cpdb; | + | cat > /etc/hosts <<EOF |
+ | 127.0.0.1 localhost | ||
+ | 192.168.0.l03 lpar1.example.com | ||
+ | 192.168.0.l04 lpar2.example.com | ||
+ | EOF | ||
+ | SCRIPT | ||
- | @$ORACLE_HOME/rdbms/admin/noncdb_to_pdb.sql | + | $install_oracle_preinstall = << |
+ | curl -o oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm https://yum.oracle.com/repo/ | ||
+ | yum -y localinstall oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm | ||
+ | SCRIPT | ||
- | ALTER PLUGGABLE DATABASE db12cpdb OPEN; | + | $install_oracle_19c = << |
+ | cd /vagrant | ||
+ | yum -y localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm | ||
- | SELECT name, open_mode FROM v$pdbs WHERE name = ' | + | SCRIPT |
- | NAME | + | $install_19c_db = << |
- | ------------------------------ ---------- | + | runuser |
- | DB12CPDB | + | SCRIPT |
- | + | ||
- | SQL> | + | |
- | </Code> | + | |
- | + | ||
- | REMEMBER, as the cloned DB wasn't a PDB, we need to run the noncdb_to_pdb.sql. | + | |
- | + | ||
- | ===== Hot clone ===== | + | |
- | There is however one BIG flow in that procedure. The problem is that we need the database (non-cdb) or even PDB to be in read-only mode. That pretty much kills all the desire to perform the procedure as the downtime would be too much for production. | + | |
- | Because of that from 12.2 we can do a hot clone, which eliminates that prerequisites :) | + | |
- | So let's see how it is done: | + | $install_vnc_server = << |
+ | yum -y install vnc-server | ||
+ | yum -y install tigervnc-server | ||
+ | yum -y install xterm | ||
+ | yum -y install net-tools | ||
+ | yum -y install unzip | ||
+ | yum -y install curl | ||
+ | SCRIPT | ||
- | === Prerequisites === | ||
- | < | ||
- | * The user in the local database must have the CREATE PLUGGABLE DATABASE privilege in the root container. | ||
- | * The remote CDB must use local undo mode. Without this you must open the remote PDB or non-CDB in read-only mode. | ||
- | * The remote database should be in archivelog mode. Without this you must open the remote PDB or non-CDB in read-only mode. | ||
- | * The local database must have a database link to the remote database. If the remote database is a PDB, the database link can point to the remote CDB using a common user, the PDB or an application container using a local or common user. | ||
- | * The user in the remote database that the database link connects to must have the CREATE PLUGGABLE DATABASE privilege. | ||
- | * The local and remote databases must have the same endianness. | ||
- | * The local and remote databases must either have the same options installed, or the remote database must have a subset of those present on the local database. | ||
- | * If the character set of the local CDB is AL32UTF8, the remote database can be any character set. If the local CDB does not use AL32UTF8, the character sets of the remote and local databases much match. | ||
- | * If the remote database uses Transparent Data Encryption (TDE) the local CDB must be configured appropriately before attempting the clone. If not you will be left with a new PDB that will only open in restricted mode. | ||
- | * Bug 19174942 is marked as fixed in 12.2. I can't confirm this, so just in case I'll leave this here, but it should no longer be the case. The default tablespaces for each common user in the remote CDB *must* exist in local CDB. If this is not true, create the missing tablespaces in the root container of the local PDB. If you don't do this your new PDB will only be able to open in restricted mode (Bug 19174942). | ||
- | * When cloning from a non-CDB, both the the local and remote databases must using version 12.1.0.2 or higher. | ||
- | * In the examples below I have three databases running on the same virtual machine, but they could be running on separate physical or virtual servers. | ||
- | cdb1 : The local database that will eventually house the clones. | + | Vagrant.configure(" |
- | db12c : The remote non-CDB. | + | |
- | cdb3 : The remote CDB, used for cloning a remote PDB (pdb5). | + | config.vm.provision |
+ | config.vm.define " | ||
+ | | ||
+ | lpar.vm.hostname = " | ||
+ | lpar.vm.synced_folder " | ||
+ | lpar.vm.network " | ||
+ | lpar.vm.network " | ||
+ | lpar.vm.provision " | ||
+ | lpar.vm.provision " | ||
+ | lpar.vm.provision " | ||
+ | lpar.vm.provision " | ||
+ | lpar.vm.provision " | ||
+ | lpar.vm.provision " | ||
+ | lpar.vm.provider :virtualbox do |v| | ||
+ | v.customize [" | ||
+ | v.customize [" | ||
+ | v.customize [" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
</ | </ | ||
- | ===On remote=== | ||
- | On the remote machine, we have to however assure couple stuff: | ||
- | <Code:bash|Create user and verify archivelog> | + | Just make sure, you have the Oracle 19c RPM in folder called: " |
- | export ORAENV_ASK=NO | + | |
- | export ORACLE_SID=cdb3 | + | |
- | . oraenv | + | |
- | export ORAENV_ASK=YES | + | |
- | sqlplus | + | < |
- | + | responseFileVersion=/oracle/ | |
- | CONN / AS SYSDBA | + | gdbName=orcl.example.com |
- | + | sid=orcl | |
- | COLUMN property_name FORMAT A30 | + | databaseConfigType=SI |
- | COLUMN property_value FORMAT A30 | + | policyManaged=false |
- | + | createServerPool=false | |
- | SELECT property_name, | + | force=false |
- | FROM | + | createAsContainerDatabase=true |
- | WHERE property_name | + | numberOfPDBs=1 |
- | + | pdbName=pdb1 | |
- | PROPERTY_NAME | + | useLocalUndoForPDBs=true |
- | ------------------------------ ------------------------------ | + | pdbAdminPassword=Oracle123 |
- | LOCAL_UNDO_ENABLED | + | templateName=/ |
- | + | sysPassword=Oracle123 | |
- | SQL> | + | systemPassword= Oracle123 |
- | + | emExpressPort=0 | |
- | + | runCVUChecks=FALSE | |
- | SELECT log_mode | + | dvConfiguration=false |
- | FROM | + | olsConfiguration=false |
- | + | datafileJarLocation={ORACLE_HOME}/ | |
- | LOG_MODE | + | datafileDestination={ORACLE_BASE}/ |
- | ------------ | + | recoveryAreaDestination={ORACLE_BASE}/ |
- | ARCHIVELOG | + | storageType=FS |
- | + | characterSet=AL32UTF8 | |
- | SQL> | + | registerWithDirService=false |
+ | variables=ORACLE_BASE_HOME=/ | ||
+ | initParams=undo_tablespace=UNDOTBS1, | ||
+ | sampleSchema=false | ||
+ | memoryPercentage=40 | ||
+ | databaseType=MULTIPURPOSE | ||
+ | automaticMemoryManagement=true | ||
+ | totalMemory=0 | ||
</ | </ | ||
- | + | Of course feel free to add / remove or modify any parameter which you wish. Just bare in mind that some are mandatory | |
- | + | ||
- | ===On local=== | + | |
- | Now, we can create a DB link on the local machine and then we can create the PDB itself | + | |
- | + | ||
- | < | + | |
- | CDB3= | + | |
- | (DESCRIPTION = | + | |
- | (ADDRESS = (PROTOCOL = TCP)(HOST = my-server.my-domain)(PORT = 1521)) | + | |
- | (CONNECT_DATA = | + | |
- | (SERVER = DEDICATED) | + | |
- | (SERVICE_NAME = cdb3) | + | |
- | ) | + | |
- | ) | + | |
- | + | ||
- | export ORAENV_ASK=NO | + | |
- | export ORACLE_SID=cdb1 | + | |
- | . oraenv | + | |
- | export ORAENV_ASK=YES | + | |
- | + | ||
- | sqlplus / as sysdba | + | |
- | + | ||
- | CREATE DATABASE LINK clone_link | + | |
- | CONNECT TO c## | + | |
- | + | ||
- | -- Test link. | + | |
- | DESC user_tables@clone_link | + | |
- | + | ||
- | CREATE PLUGGABLE DATABASE pdb5new FROM pdb5@clone_link; | + | |
- | + | ||
- | Pluggable database created. | + | |
- | + | ||
- | SQL> | + | |
- | + | ||
- | COLUMN name FORMAT A30 | + | |
- | + | ||
- | SELECT name, open_mode FROM v$pdbs WHERE name = ' | + | |
- | + | ||
- | NAME | + | |
- | ------------------------------ ---------- | + | |
- | PDB5NEW | + | |
- | + | ||
- | SQL> | + | |
- | + | ||
- | ALTER PLUGGABLE DATABASE pdb5new OPEN; | + | |
- | + | ||
- | SELECT name, open_mode FROM v$pdbs WHERE name = ' | + | |
- | + | ||
- | NAME | + | |
- | ------------------------------ ---------- | + | |
- | PDB5NEW | + | |
- | + | ||
- | SQL> | + | |
- | </ | + | |
- | + | ||
- | + |