Showing posts with label #OracleDBA. Show all posts
Showing posts with label #OracleDBA. Show all posts

Saturday, June 20, 2026

Powershell for the Oracle Professional - A Primer

PowerShell for the Oracle Professional: A Primer



For years, the Oracle database community has relied heavily on Bash scripting to handle heavy lifting and automation. It’s tried, true, and deeply embedded in our daily workflows.

But there is another powerful tool worth adding to your toolkit: Microsoft PowerShell.

If you haven't looked into it lately, you might be surprised to learn just how well PowerShell integrates with Oracle environments. To kick things off, this post has two main goals:

  1. A quick, no-nonsense introduction to what PowerShell actually is.

  2. A practical sample script to get your feet wet and show you the basics in action.

This is the first installment of a new weekly series where we’ll explore how to leverage PowerShell to streamline and supercharge your Oracle database administration.

Let’s dive into part one.

Part 1: What is PowerShell anyway?

If you come from a Linux background, you can think of PowerShell as Bash on steroids. Introduced by Microsoft but now fully open-source and cross-platform (meaning it runs beautifully on Linux and macOS), PowerShell is much more than just a command-line shell.

The core difference lies in how data is handled:

  • Bash passes data as plain text or strings. You often have to rely on awk, sed, or grep to slice and dice your output to find exactly what you need.

  • PowerShell passes data as objects. When you run a command, the output retains its structure, properties, and data types. This means you can filter, sort, and manipulate your data without complex text parsing.

For an Oracle DBA, this object-oriented approach makes handling environment variables, managing files, and processing database outputs incredibly clean and predictable.


Part 2: Your First PowerShell Script

Let’s look at a quick, practical example. The script below does something every DBA has done a thousand times: it checks the status of a specific Windows service (like your Oracle system identifier, or SID) and drops a quick status update to the console.


================================================================= 

[Script]


# Define the Oracle Service name you want to check

$OracleService = "OracleServiceORCL"


# Retrieve the service object

$ServiceInfo = Get-Service -Name $OracleService -ErrorAction SilentlyContinue


# Verify if the service exists, then evaluate its status

if ($ServiceInfo) {

    Write-Host "`n[+] Service Status Check" -ForegroundColor Cyan

    Write-Host "--------------------------------------------------" -ForegroundColor Gray

    Write-Host "Service Name : $OracleService"

    

    if ($ServiceInfo.Status -eq "Running") {

        Write-Host "Status       : RUNNING" -ForegroundColor Green

    } else {

        Write-Host "Status       : $($ServiceInfo.Status.ToString().ToUpper())" -ForegroundColor Yellow

        Write-Host "`n[!] ALERT: The Oracle service is not currently running." -ForegroundColor Yellow

    }

    Write-Host "--------------------------------------------------`n" -ForegroundColor Gray

} else {

    # Beautifully formatted console error message

    Write-Host "`n==================================================" -ForegroundColor Red

    Write-Host "          DATABASE SERVICE EXCEPTION              " -ForegroundColor Red

    Write-Host "==================================================" -ForegroundColor Red

    Write-Host " Target Service : $OracleService" -ForegroundColor White

    Write-Host " Error Details  : The specified service could not be found." -ForegroundColor White

    Write-Host "                : Please verify the Oracle SID/ServiceName." -ForegroundColor White

    Write-Host "==================================================" -ForegroundColor Red

    Write-Host " Action Required: Check your Windows Services MMC.`n" -ForegroundColor Yellow

}


==================================================================

Here is an example of the output as I don't have an ORCL Service running on my machine.





Why this matters

Notice how we didn't have to grep for the word "Running"? We simply grabbed the $ServiceInfo object and asked for its .Status property directly.

This is just scratching the surface. In the coming weeks, we will dive deeper into connecting to your Oracle instances, executing SQL queries directly from the shell, and automating routine maintenance tasks.

Stay tuned for next week's post, where we will set up the .NET Managed Provider and make our very first database connection using PowerShell. 


#OracleDBA #PowerShell #DatabaseAutomation #OracleDatabase #DevOpsForDBAs #SysAdmin #Scripting

 

Wednesday, August 13, 2025

Oracle 21c Installation Guide on Windows

 


Oracle 21c Installation Guide on Windows




This guide walks you through installing Oracle Database 21c on Windows and configuring it for local use with SQL Developer.

🖥️ Pre-Installation Requirements

Ensure your system meets the following:

  • OS: Windows Server 2019 or later (64-bit) or Windows 10/11 (64-bit)
  • RAM: Minimum 8 GB (16 GB recommended)
  • Disk Space: At least 50 GB free
  • CPU: Intel or AMD x86-64 processor
  • User Account: Administrator privileges

🔧 System Configuration

  • Disable UAC:
    Control Panel → User Accounts → Change User Account Control Settings → Never Notify
  • Firewall:
    Allow inbound TCP traffic on port 1521
  • Install Prerequisites:
  • .NET Framework 4.8 or later
  • Latest Windows updates

📦 Step-by-Step Installation

Step 1: Download Oracle 21c

Step 2: Extract the Installer

  • Extract the ZIP to a directory like C:\Oracle21c
  • Open Command Prompt as Administrator
  • Navigate to the extracted folder

Step 3: Run Oracle Universal Installer

  • Run setup.exe
  • Follow the wizard:
    • Installation Type: Enterprise Edition (recommended)
    • Database Configuration: Create a database
    • Destination Folder: C:\app\oracle\product\21c\
    • Oracle Base: C:\app\oracle\product\21c\
    • Oracle Home: C:\app\oracle\product\21c\oradata
    • Admin Password: Choose a strong password
  • Verify prerequisites and click Install

🔌 Step 4: Configure Listener

  • Launch Net Configuration Assistant (NETCA)
  • Choose Listener Configuration → Add
  • Set:
  • Listener Name: LISTENER
  • Protocol: TCP
  • Port: 1521

To start listener manually:

lsnrctl status lsnrctl start

Or update listener.ora:

ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ORCL) ) )

🗃️ Step 5: Create the Database

  • Launch Database Configuration Assistant (DBCA)
  • Choose Create a database
  • Select Advanced Configuration → General Purpose or Transaction Processing
  • Set:
  • Global Database Name: ORCL
  • SID: ORCL
  • Enable Automatic Memory Management
  • Enable Archiving (optional)

Click Finish to create the database.

🧑‍💻 Step 6: Connect with SQL Developer

  • Username: system
  • Password: your admin password
  • Hostname: localhost
  • Port: 1521
  • SID: ORCL

🛠️ Troubleshooting Tips

  • If listener fails to start, check firewall and port settings
  • Use tnsping ORCL to verify connectivity
  • Ensure environment variables like ORACLE_HOME and PATH are correctly set

Monday, July 14, 2025

Oracle DBA Commands Notebook: A Mini Survival Guide

 



Whether you’re spinning up a RAC lab, auditing system usage, or simply trying to stay sharp as an Oracle DBA, this notebook packs a punch with essential SQL snippets for every skill level. Copy, paste, and conquer! ⚡

🟢 Beginner Commands — The Essentials

🔍 Check Oracle Database Version

SELECT * FROM v$version;

Great for confirming your environment—especially useful before patching or feature testing.

👤 List All Users

SELECT username FROM dba_users ORDER BY username;

Quick way to verify access or hunt for unused accounts.

🗃️ Show Tablespaces

SELECT tablespace_name, status FROM dba_tablespaces;

Verify availability and health of your storage allocations.

🟡 Intermediate Commands — Digging Deeper

📁 Datafiles by Tablespace

SELECT tablespace_name, file_name, bytes/1024/1024 AS MB FROM dba_data_files ORDER BY tablespace_name;

See how your datafiles are distributed and consuming space.

📊 Tablespace Usage Overview

SELECT df.tablespace_name, df.total_mb, fs.free_mb, (df.total_mb - fs.free_mb) AS used_mb, ROUND((df.total_mb - fs.free_mb)/df.total_mb*100, 2) AS pct_used FROM (SELECT tablespace_name, SUM(bytes)/1024/1024 AS total_mb FROM dba_data_files GROUP BY tablespace_name) df JOIN (SELECT tablespace_name, SUM(bytes)/1024/1024 AS free_mb FROM dba_free_space GROUP BY tablespace_name) fs ON df.tablespace_name = fs.tablespace_name;



Your go-to for capacity planning and alert thresholds.

🧑‍💻 List Running Sessions

SELECT sid, serial#, username, status, osuser, machine, program FROM v$session WHERE username IS NOT NULL;

Useful for monitoring active connections, especially in multi-user setups.

🔴 Advanced Commands — When You Need Firepower

⛓️ Blocking Sessions Detector

SELECT s1.sid || ',' || s1.serial# AS blocker, s2.sid || ',' || s2.serial# AS blocked, s1.username AS blocker_user, s2.username AS blocked_user FROM v$lock l1 JOIN v$session s1 ON l1.sid = s1.sid JOIN v$lock l2 ON l2.block = 1 AND l2.id1 = l1.id1 AND l2.id2 = l1.id2 JOIN v$session s2 ON l2.sid = s2.sid;

Debug locks and performance bottlenecks in real time.

🔥 Top SQL by CPU Usage

SELECT * FROM ( SELECT sql_id, parsing_schema_name, cpu_time/1000000 AS cpu_seconds, executions, sql_text FROM v$sql ORDER BY cpu_time DESC ) WHERE ROWNUM <= 10;

Spot expensive queries before they throttle the system.

📦 Archive Log Status

ARCHIVE LOG LIST;

A fast way to verify if your DB is in archive log mode—critical for RMAN and PITR operations.

⏱️ Wait Event Breakdown

SELECT event, total_waits, time_waited/100 AS seconds_waited FROM v$system_event ORDER BY time_waited DESC FETCH FIRST 10 ROWS ONLY;

Helps diagnose performance issues by identifying system-level wait events.

Shift Left: Why Performance Engineering is a Development Metric, Not a Production Post-Mortem

Introduction:   We’ve all lived through some version of this nightmare: The features are locked. The UI looks stunning. The code has passed ...