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+

Prerequisites:

  • 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
os.system("")
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
try:
    con = cx_Oracle.connect("SYSTEM",password,db_name)
    cursor=con.cursor()
    head = ("DateTime","Action","Status","Description","PatchNumber","PatchType")
    print(head)
    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 "):
        result=str(result)
        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:

patch_info

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

patch_info12

Hope u will find this post very useful.

Cheers

Regards,
Adityanath

Advertisements

2 responses to “Display current DB patch set info for Oracle DB using Python scripting”

  1. ปั้มไลค์ Avatar
    ปั้มไลค์

    Like!! Great article post.Really thank you! Really Cool.

  2. zortilo nrel Avatar
    zortilo nrel

    But wanna admit that this is handy, Thanks for taking your time to write this.

Leave a comment

Advertisements
Blog Stats

562,677 hits

Advertisements
Advertisements