Display current DB patch set info for Oracle DB using Python scripting

In my previous posts, I discussed about tablespace/FRA/RMAN backup monitoring using python. Here comes my new python code to display current DB patch set level for a Oracle DB.

Note: This code is ready to use & only works on Oracle DB with versions 18+


  • python binaries with version 3
  • cx_Oracle module

What this program does:

This program needs following inputs from user side:

  • SYSTEM password
  • TNS entry to connect to DB.

At the end of execution, it displays current DB patch set level for a Oracle DB.

  • Patch Application Date
  • Patch Action
  • Status
  • Patch Description
  • Patch Number
  • Patch Type

Actual code:

# Script Name: patch_info.py
# Description: Patchset details for an Oracle DB
# Usage: python patch_info.py
# Author: Adityanath Dewoolkar
# Version: 1

# importing required modules
import cx_Oracle
import getpass
import os

# For conditional coloring
class style():
    RED = '\033[31m'
    GREEN = '\033[32m'
    YELLOW = '\033[33m'
    RESET = '\033[0m'

# Prompt the user for a password without echoing
password = getpass.getpass(prompt = 'Enter SYSTEM password: ',  stream=None)
# Enter TNS string to connect
db_name = input("Enter DB name: ")

# Code for getting Tablespace usage details in an Oracle DB
    con = cx_Oracle.connect("SYSTEM",password,db_name)
    head = ("DateTime","Action","Status","Description","PatchNumber","PatchType")
    for result in cursor.execute("SELECT TO_char(action_time, 'DD-MON-YYYY HH24:MI:SS') AS action_time,action,status, description, PATCH_ID,PATCH_TYPE FROM   sys.dba_registry_sqlpatch order by 1 "):
        print(style.YELLOW + result.format(head) + style.RESET)

except cx_Oracle.DatabaseError as err:
    print("Script execution failed: ", err)

Here comes the result:

You can download sample files from below location:


For Databases below version 18 you will need to use script below:


Hope u will find this post very useful.



2 replies

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s