Basic tasks using Oracle Fleet Patching and Provisioning
Tags: upgrade, oracle, tutorial, oraclefpp
Published: 2021-01-23 14:27:56

Like I mentioned on my [previous post about Oracle Fleet Patching and Provisioning](https://project42.site/oracle-fleet-patching-and-provisioning-using-brokedba-vagrant-fork/) I got to install [BrokeDBA FPP Vagrant Fork](https://brokedba.blogspot.com/2020/12/my-vagrant-fork-of-oracle-fleet.html) as a test for this new (for me at least) Oracle management system.
A good place to start checking about the benefits of Oracle FPP: [Oracle Fleet Patching and Provisioning - Introduction and Technical Overview](https://www.oracle.com/a/tech/docs/fpp-technical-brief-19c.pdf)

On this post, I wanted to mention some of the commands I have tried so far, nothing fancy or too complicated, but just a way to force me to use it and find new questions :)

Everything done is executed directly from our FPP Server and even though in this case I'm using only one client, you should be able to replicate the same to your entire feet

## Actions List
  * [Import Oracle DB Images](#Import-Oracle-DB-Images)
  * [Deploy New DB Oracle Home to the Fleet](#Deploy-New-DB-Oracle-Home-to-the-Fleet)
  * [Create Database](#Create-Database)
  * [Create PDB](#Create-PDB)
  * [Upgrade Database](#Upgrade-Database)
  * [Remove Database](#Remove-Database)
  * [Remove Oracle Home ](#Remove-Oracle-Home)
  * [Operations Auditing](#Operations-Auditing)

## Import Oracle DB Images <a name="Import-Oracle-DB-Images"></a>

Let's import the DB 19c image in the server so we can deploy it later to our clients (we only have one client so far)
```bash
[grid@fpp-Server ~]$ rhpctl import image -image db_19300 -imagetype ORACLEDBSOFTWARE -zip /vagrant/ORCL_software/LINUX.X64_193000_db_home.zip
fpp-Server.evilcorp.com: Audit ID: 3
fpp-Server.evilcorp.com: Creating a new ACFS file system for image "db_19300" ...
fpp-Server.evilcorp.com: Extracting files to directory /rhp_storage/images/idb_19300815168/swhome...
fpp-Server.evilcorp.com: Files successfully extracted
fpp-Server.evilcorp.com: Changing the home ownership to user grid...
fpp-Server.evilcorp.com: Starting clone operation...
========================================
fpp-Server.evilcorp.com:
[INFO] [INS-32183] Use of clone.pl is deprecated in this release. Clone operation is equivalent to performing a Software Only installation from the image.
[....]
You can find the log of this install session at:
 /u01/app/oraInventory/logs/DetachHome2021-01-19_01-59-14PM.log
'DetachHome' was successful.
fpp-Server.evilcorp.com: Successfully executed detach home operation.
[grid@fpp-Server ~]$

[grid@fpp-Server ~]$ rhpctl import image -image db_12102 -imagetype ORACLEDBSOFTWARE -path /u01/app/oracle/product/12.1.0.2/dbhome_1 -targetnode fpp-Client -root
Enter user "root" password:
fpp-Server.evilcorp.com: Adding storage for image ...
fpp-Server.evilcorp.com: Creating a new ACFS file system for image "db_12102" ...
fpp-Server.evilcorp.com: Creating export file system ...
fpp-Server.evilcorp.com: Starting export file system...
fpp-Server.evilcorp.com: Mounting file system...
fpp-Server.evilcorp.com: Copying files...
fpp-Server.evilcorp.com: Removing export file system ...
[grid@fpp-Server ~]$
```

## Deploy New DB Oracle Home to the Fleet <a name="Deploy-New-DB-Oracle-Home-to-the-Fleet"></a> 

Now we can add a new 19c Oracle home to our client VM:
```bash
[grid@fpp-Server ~]$ rhpctl add workingcopy -workingcopy wc_db_19300 -image db_19300 -user oracle -groups OSBACKUP=dba,OSDG=dba,OSKM=dba,OSRAC=dba -oraclebase /u01/app/oracle -path /u01/app/oracle/product/19.0.0/dbhome_1 -targetnode fpp-Client -root
Enter user "root" password:
fpp-Server.evilcorp.com: Audit ID: 7
fpp-Server.evilcorp.com: Option storagetype is set to the following default value: LOCAL.
fpp-Server.evilcorp.com: Storing metadata in repository for working copy "wc_db_19300" ...
fpp-Server.evilcorp.com: Connecting to node fpp-client ...
fpp-Server.evilcorp.com: Starting transfer for remote copy ...
[...]
fpp-client: ..................................................   100% Done.
fpp-Server.evilcorp.com: Successfully executed clone operation.
fpp-Server.evilcorp.com: Executing root script on nodes fpp-client.
fpp-client: Check /u01/app/oracle/product/19.0.0/dbhome_1/install/root_fpp-Client_2021-01-19_14-18-52-702784822.log for the output of root script
fpp-Server.evilcorp.com: Successfully executed root script on nodes fpp-client.
fpp-Server.evilcorp.com: Working copy creation completed.
[grid@fpp-Server ~]$
```
We can do the same for any other Database Oracle Home we have in our FPP Server
```bash
[grid@fpp-Server ~]$ rhpctl add workingcopy -workingcopy wc_db_12102 -image db_12102 -user oracle  -oraclebase /u01/app/oracle -path /u01/app/oracle/product/12.1.0.2/dbhome_1 -targetnode fpp-Client -root
Enter user "root" password:
fpp-Server.evilcorp.com: Audit ID: 21
fpp-Server.evilcorp.com: Option storagetype is set to the following default value: LOCAL.
fpp-Server.evilcorp.com: Storing metadata in repository for working copy "wc_db_12102" ...
[....]
fpp-Server.evilcorp.com: Executing root script on nodes fpp-client.
fpp-client: Check /u01/app/oracle/product/12.1.0.2/dbhome_1/install/root_fpp-Client_2021-01-20_13-34-01.log for the output of root script
fpp-Server.evilcorp.com: Successfully executed root script on nodes fpp-client.
fpp-Server.evilcorp.com: Working copy creation completed.
[grid@fpp-Server ~]$
```

## Create Database <a name="Create-Database"></a> 

What about creating a DB in our fpp-client? as simple as a remote command from our FPP Server
By the way, is not a "good idea" to cancel a Sever operation using *"Ctrl+c"* since it will actually continue in the background:
```bash
[grid@fpp-Server ~]$ rhpctl add database -workingcopy wc_db_19300 -dbname CDB19 -dbtype SINGLE -cdb -pdbName PDB -numberOfPDBs 1 -root
Enter user "root" password:
fpp-Server.evilcorp.com: Audit ID: 8
fpp-Server.evilcorp.com: Option datafileDestination is set to the following default value: /u01/app/oracle/oradata.
fpp-Server.evilcorp.com: Starting database creation on node fpp-client ...
^C^C
PRCG-1104 : User terminated the command. The command operation is not cancelled by this interruption, and may continue to be processed on the server.
[grid@fpp-Server ~]$

# Client VM

[root@fpp-Client logs]# ps -ef |grep pmon
oracle    1161     1  0 13:19 ?        00:00:00 ora_pmon_cdb1
oracle   31149     1  0 14:34 ?        00:00:00 ora_pmon_CDB19
root     32083 24582  0 14:41 pts/0    00:00:00 grep --color=auto pmon
[root@fpp-Client logs]#
```

Just to confirm, we can see our new 19c Database running in fpp-Client
```bash
[oracle@fpp-Client ~]$ . oraenv
ORACLE_SID = [cdb1] ? CDB19
The Oracle base remains unchanged with value /u01/app/oracle
[oracle@fpp-Client ~]$ sqlplus / as sysdba

DB_NAME   CDB HOST_NAME   STARTUP              DATABASE_ROLE 
--------- --- ----------- -------------------- ------------- 
CDB19     YES fpp-Client  19-JAN-2021 14:51:12 PRIMARY       



   INST_ID     CON_ID NAME                 OPEN_MODE  OPEN_TIME                                STATUS
---------- ---------- -------------------- ---------- ---------------------------------------- ----------
         1          2 PDB$SEED             READ ONLY  19-JAN-21 02.51.22.283 PM +00:00         NORMAL
         1          3 PDB                  READ WRITE 19-JAN-21 02.51.38.524 PM +00:00         NORMAL

SQL>
```

You can also specify the datafile creation destination, like we are doing for this 12.1 Database
```bash
[grid@fpp-Server ~]$ rhpctl add database -workingcopy wc_db_12102 -dbname cdb12 -dbtype SINGLE -cdb -pdbName PDB12 -numberOfPDBs 1 -datafileDestination /u02/oradata -root
Enter user "root" password:
fpp-Server.evilcorp.com: Audit ID: 22
fpp-Server.evilcorp.com: Starting database creation on node fpp-client ...
fpp-client: SYS_PASSWORD_PROMPT
SYSTEM_PASSWORD_PROMPT
fpp-client:PDB_ADMIN_PASSWORD_PROMPT
fpp-client:Copying database files
fpp-client: 1% complete
[....]
fpp-client:   For the following PDBs: CDB$ROOT PDB$SEED PDB12
fpp-client:     Nothing to roll back
fpp-client:     Nothing to apply
fpp-client:
fpp-client: SQL Patching tool complete on Wed Jan 20 13:42:35 2021
[grid@fpp-Server ~]$


#DB alert confirming datfiles location
alter database rename global_name to "cdb12"
Completed: alter database rename global_name to "cdb12"
ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/oradata/cdb12/temp01.dbf' SIZE 61440K REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
Completed: ALTER TABLESPACE TEMP ADD TEMPFILE '/u02/oradata/cdb12/temp01.dbf' SIZE 61440K REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED

```

## Create PDB <a name="Create-PDB"></a> 

We can also create PDBs on any CDB already running
(by the way, I'm sure will be corrected soon, but the [documentation](https://docs.oracle.com/en/database/oracle/oracle-database/19/cwadd/rapid-home-provisioning-and-server-control-command-reference.html#GUID-323C6FCD-0D98-4F82-BFF3-4DDD96EF2CA1) shows some typo, like *-cdbName* and *-pdbName* instead of *-cdbname* and *-pdbname*)
```bash
[grid@fpp-Server ~]$ rhpctl addpdb database -workingcopy wc_db_12102 -cdbname cdb12 -pdbname PDB122 -root
Enter user "root" password:
fpp-Server.evilcorp.com: Audit ID: 26
fpp-Server.evilcorp.com: Option dbtype is set to the following default value: SINGLE.
fpp-Server.evilcorp.com: Option datafileDestination is set to the following default value: /u01/app/oracle/oradata.
fpp-Server.evilcorp.com: Starting pluggable database addition on node fpp-client ...
fpp-client: Enter PDBADMIN User Password:
Creating Pluggable Database
fpp-client: 4% complete
fpp-client: 12% complete
fpp-client: 21% complete
fpp-client: 38% complete
fpp-client: 85% complete
fpp-client: Completing Pluggable Database Creation
fpp-client: 100% complete
fpp-client: Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/cdb12/PDB122/cdb12.log" for further details.
[grid@fpp-Server ~]$

## fpp-client

CON_ID NAME     OPEN_MODE  OPEN_TIME                          STATUS
------ -------- ---------- ---------------------------------- ---------
     2 PDB$SEED READ ONLY  20-JAN-21 01.42.01.262 PM +00:00   NORMAL
     3 PDB12    READ WRITE 20-JAN-21 01.42.20.847 PM +00:00   NORMAL
     4 PDB122   READ WRITE 20-JAN-21 02.19.24.252 PM +00:00   NORMAL
```

## Upgrade Database <a name="Upgrade-Database"></a> 

This Scenario is the same upgrade exercise [BrokeDBA](https://twitter.com/BrokeDba) shows in his post [My Vagrant fork of Oracle Fleet Patching and provisioning (FPP)](https://brokedba.blogspot.com/2020/12/my-vagrant-fork-of-oracle-fleet.html)
```bash
[grid@fpp-Server ~]$ rhpctl upgrade database -dbname cdb12 -sourcehome /u01/app/oracle/product/12.1.0.2/dbhome_1  -destwc wc_db_19300 -root
Enter user "root" password:
fpp-Server.evilcorp.com: Audit ID: 28
fpp-Server.evilcorp.com: verifying versions of Oracle homes ...
fpp-Server.evilcorp.com: verifying owners of Oracle homes ...
fpp-Server.evilcorp.com: verifying groups of Oracle homes ...
fpp-Server.evilcorp.com: Processing arguments file /u01/app/grid/crsdata/fpp-server/rhp/conf/rhp.pref
fpp-Server.evilcorp.com: Connecting to node fpp-client ...
fpp-Server.evilcorp.com: Starting to upgrade database from path "/u01/app/oracle/product/12.1.0.2/dbhome_1" to path "/u01/app/oracle/product/19.0.0/dbhome_1" on node "fpp-client"
fpp-client: Logs directory:  /u01/app/oracle/cfgtoollogs/dbua/upgrade2021-01-20_02-28-20PM
fpp-client: Performing Pre-Upgrade Checks...
fpp-client: ============================
fpp-client: PRE- and POST- FIXUP ACTIONS
fpp-client: =============================
fpp-client: /u01/app/oracle/cfgtoollogs/dbua/upgrade2021-01-20_02-28-20PM/cdb12/upgrade.xml
fpp-client: /u01/app/oracle/cfgtoollogs/dbua/upgrade2021-01-20_02-28-20PM/cdb12/preupgrade_fixups.sql
fpp-client: /u01/app/oracle/cfgtoollogs/dbua/upgrade2021-01-20_02-28-20PM/cdb12/postupgrade_fixups.sql
[....]
69% complete
70% complete
80% complete
90% complete
Database upgrade has been completed successfully, and the database is ready to use.
[grid@fpp-Server ~]$

#fpp-client

DB_NAME   CDB HOST_NAME       STARTUP               DATABASE_ROLE
--------- --- --------------- --------------------- -------------
CDB12     YES fpp-Client      20-JAN-2021 15:41:56  PRIMARY      

SQL> SQL> SQL>   2    3    4
 CON_ID NAME                 OPEN_MODE  OPEN_TIME                                STATUS
------- -------------------- ---------- ---------------------------------------- ----------
      2 PDB$SEED             READ ONLY  20-JAN-21 05.47.39.793 PM +00:00         NORMAL
      3 PDB12                READ WRITE 20-JAN-21 06.11.24.190 PM +00:00         NORMAL
      4 PDB122               READ WRITE 20-JAN-21 06.11.24.376 PM +00:00         NORMAL

SQL>  select banner from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
```

## Remove Database <a name="Remove-Database"></a> 

Let's delete the DB we just upgraded.
As you can see, we need to remember that the "workingcopy" has changed after the upgrade
```bash
[grid@fpp-Server ~]$ rhpctl delete database -workingcopy wc_db_19300 -dbname cdb12 -targetnode fpp-Client -root
Enter user "root" password:
fpp-Server.evilcorp.com: Starting database deletion...
fpp-client: [WARNING] [DBT-11503] The instance (cdb12) is not running on the local node. This may result in partial delete of Oracle database.
fpp-client:    CAUSE: A locally running instance is required for complete deletion of Oracle database instance and database files.
fpp-client:    ACTION: Specify a locally running database, or execute DBCA on a node where the database instance is running.
fpp-client: [WARNING] [DBT-19202] The Database Configuration Assistant will delete the Oracle instances and datafiles for your database. All information in the database will be destroyed.
fpp-client: Prepare for db operation
fpp-client: 32% complete
fpp-client: Connecting to database
[....]
fpp-client: 100% complete
fpp-client: Database deletion completed.
fpp-client: Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/cdb12/cdb120.log" for further details.
[grid@fpp-Server ~]$
```

## Remove Oracle Home <a name="Remove-Oracle-Home"></a> 

We can now delete the old 12.1 DB Oracle Home from the client
```bash
[grid@fpp-Server ~]$ rhpctl delete workingcopy -workingcopy wc_db_12102 -root
Enter user "root" password:
fpp-Server.evilcorp.com: Audit ID: 29
fpp-Server.evilcorp.com: Removing working copy home ...
fpp-client: Checking for required files and bootstrapping ...
fpp-client: Please wait ...
fpp-client: Location of logs /u01/app/oracle/oraInventory/logs/
[....]
fpp-client: ####################### DEINSTALL CLEAN OPERATION SUMMARY #######################
fpp-client: Successfully detached Oracle home '/u01/app/oracle/product/12.1.0.2/dbhome_1' from the central inventory on the local node.
fpp-client: Successfully deleted directory '/u01/app/oracle/product/12.1.0.2/dbhome_1' on the local node.
fpp-client: Oracle Universal Installer cleanup was successful.
fpp-client:
fpp-client: Oracle deinstall tool successfully cleaned up temporary directories.
fpp-client: #######################################################################
fpp-client:
fpp-client:
fpp-client: ############# ORACLE DEINSTALL TOOL END #############
fpp-client:
[grid@fpp-Server ~]$
```

## Operations Auditing <a name="Operations-Auditing"></a> 

If your system is slow (like mine) and want to check an operation executed or running, you can use audit option to see the status and if completed, will show you how long it took, which is nice addition since this can give you some idea and expectations for new deployments ETA
```bash
[grid@fpp-Server ~]$ rhpctl query audit -record 8
fpp-Server.evilcorp.com: Audit ID: 9
Audit ID: 8
Start time: 2021-01-19T14:31:48.429
Command executed: rhpctl add database -workingcopy wc_db_19300 -dbname CDB19 -dbtype SINGLE -cdb -pdbName PDB -numberOfPDBs 1 -root
End time:
Command result: RUNNING
User name: grid
Node name: fpp-server@london-fleet-c
Target cluster: london-fleet-c

[grid@fpp-Server ~]$


[grid@fpp-Server ~]$ rhpctl query audit -record 8
fpp-Server.evilcorp.com: Audit ID: 11
Audit ID: 8
Start time: 2021-01-19T14:31:48.429
Command executed: rhpctl add database -workingcopy wc_db_19300 -dbname CDB19 -dbtype SINGLE -cdb -pdbName PDB -numberOfPDBs 1 -root
End time: 2021-01-19T14:51:44.000
Command result: SUCCESS
User name: grid
Node name: fpp-server@london-fleet-c
Target cluster: london-fleet-c

[grid@fpp-Server ~]$
```

You can find more commands in [Fleet Patching and Provisioning Control (RHPCTL) Command Reference](https://docs.oracle.com/en/database/oracle/oracle-database/19/cwadd/rapid-home-provisioning-and-server-control-command-reference.html#GUID-66345667-F035-4ADB-A25F-5530299E04B7)
Also, you can find more examples in the [Oficial Oracle FPP GitHub](https://github.com/oracle/vagrant-projects/tree/master/OracleFPP#fpp-commands-you-could-test-postdeploy-based-on-the-configuration-file-above)

This is first time I use Oracle FPP, so there is a lot to learn, but now that is up and running and [BrokeDBA](https://draft.blogger.com/profile/03256293966951383441) already promised to make more content about, I'm really looking forward to learn about it