Monday, March 9, 2026

Oracle DBA Daily Health Check Script

 

1️⃣ Check Database Status

SELECT name, open_mode, database_role
FROM v$database;

Expected result:

  • Database should be OPEN

  • Role should be PRIMARY (unless standby database).


2️⃣ Check Instance Status

SELECT instance_name, status
FROM v$instance;

Status should be OPEN.


3️⃣ Check Tablespace Usage

SELECT
tablespace_name,
ROUND((used_space/tablespace_size)*100,2) used_percent
FROM dba_tablespace_usage_metrics
ORDER BY used_percent DESC;

⚠️ Alert if usage > 85%


4️⃣ Check Datafile Autoextend

SELECT
file_name,
autoextensible
FROM dba_data_files
WHERE autoextensible='NO';

Files without autoextend may cause tablespace full errors.


5️⃣ Check Archive Log Destination

SELECT
dest_name,
status,
error
FROM v$archive_dest;

Make sure archive destination is VALID.


6️⃣ Check Blocking Sessions

SELECT
blocking_session,
sid,
serial#
FROM v$session
WHERE blocking_session IS NOT NULL;

Blocking sessions may cause application hangs.


7️⃣ Check Long Running Queries

SELECT
sid,
serial#,
sql_id,
elapsed_time
FROM v$session_longops
WHERE sofar != totalwork;

Shows queries running for long time.


8️⃣ Check Invalid Objects

SELECT owner,
object_name,
object_type
FROM dba_objects
WHERE status='INVALID';

Invalid objects may cause application failures.


9️⃣ Check Database Size

SELECT
ROUND(SUM(bytes)/1024/1024/1024,2) "DB Size GB"
FROM dba_data_files;

Track database growth.


🔟 Check Alert Log Errors

Search alert log for critical errors:

  • ORA-00600

  • ORA-07445

  • ORA-04031

  • ORA-00257

Alert log location:

$ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log

1️⃣1️⃣ Check Memory Usage

Check SGA:

SHOW PARAMETER sga;

Check PGA:

SHOW PARAMETER pga;

1️⃣2️⃣ Check Top SQL by CPU

SELECT
sql_id,
cpu_time,
executions
FROM v$sql
ORDER BY cpu_time DESC
FETCH FIRST 10 ROWS ONLY;

Helps identify high CPU queries.


Example Daily Health Check Script (Combined)

You can combine multiple checks:

-- Database status
SELECT name, open_mode FROM v$database;

-- Tablespace usage
SELECT tablespace_name,
ROUND((used_space/tablespace_size)*100,2) used_percent
FROM dba_tablespace_usage_metrics;

-- Invalid objects
SELECT owner, object_name
FROM dba_objects
WHERE status='INVALID';

-- Blocking sessions
SELECT blocking_session, sid
FROM v$session
WHERE blocking_session IS NOT NULL;

Recommended Daily DBA Checklist

Every DBA should check:

✔ Database status
✔ Tablespace usage
✔ Archive log status
✔ Blocking sessions
✔ Invalid objects
✔ Backup status
✔ Alert log errors
✔ Database growth

20 Real Oracle DBA Production Issues (With Short Description)


1️⃣ Archive Log Destination Full

Problem: Database hangs because archive logs fill the disk.

Error example:

ORA-00257: archiver error. Connect as SYSDBA only.

Solution:

  • Delete old archive logs

  • Backup archive logs using RMAN

  • Increase archive destination space


2️⃣ Tablespace Full

Error:

ORA-01653: unable to extend table

Solution:

ALTER DATABASE DATAFILE '/data/users01.dbf'
RESIZE 5G;

Or add new datafile.


3️⃣ Listener Not Starting

Error:

TNS-12541: TNS:no listener

Check using Oracle Net Listener

Solution:

lsnrctl start

4️⃣ Database Not Starting

Error:

ORA-01034: ORACLE not available

Solution:

STARTUP;

Check alert log for root cause.


5️⃣ ORA-04031 Shared Pool Error

Error:

ORA-04031: unable to allocate shared memory

Cause:

  • Shared pool too small

  • Too many SQL statements

Solution:
Increase shared pool size.


6️⃣ ORA-04036 PGA Limit Exceeded

Error:

ORA-04036: PGA memory exceeds PGA_AGGREGATE_LIMIT

Solution:

  • Increase PGA limit

  • Tune heavy SQL queries.


7️⃣ High CPU Usage

Symptoms:

  • Server CPU 100%

  • Slow database response

Check SQL:

SELECT * FROM v$sql ORDER BY cpu_time DESC;

Tune problematic queries.


8️⃣ Blocking Sessions

Users complain application is stuck.

Check blocking session:

SELECT blocking_session, sid
FROM v$session
WHERE blocking_session IS NOT NULL;

Kill blocking session if necessary.


9️⃣ Deadlocks

Error:

ORA-00060: deadlock detected

Cause:
Two sessions locking each other.

Check trace file and optimize application transactions.


🔟 Datafile Autoextend Disabled

Tablespace cannot grow.

Check:

SELECT autoextensible
FROM dba_data_files;

Enable autoextend.


1️⃣1️⃣ Too Many Database Connections

Error:

ORA-00020: maximum number of processes exceeded

Solution:

ALTER SYSTEM SET processes=500 SCOPE=SPFILE;

Restart database.


1️⃣2️⃣ Temporary Tablespace Full

Error:

ORA-01652: unable to extend temp segment

Solution:

Add temp file.

ALTER TABLESPACE temp ADD TEMPFILE '/data/temp02.dbf' SIZE 2G;

1️⃣3️⃣ Undo Tablespace Full

Error:

ORA-30036: unable to extend segment in undo tablespace

Solution:

Increase undo tablespace.


1️⃣4️⃣ Database Performance Slow

Possible causes:

  • Bad SQL

  • Missing indexes

  • Memory issues

Analyze using AWR reports.


1️⃣5️⃣ Corrupted Datafile

Error:

ORA-01110: data file corrupted

Solution:
Restore using RMAN.


1️⃣6️⃣ RMAN Backup Failure

Possible issues:

  • Disk space full

  • Archive logs missing

  • Channel configuration problem

Check RMAN logs.


1️⃣7️⃣ Invalid Database Objects

After patching or upgrades.

Check:

SELECT object_name
FROM dba_objects
WHERE status='INVALID';

Recompile objects.


1️⃣8️⃣ Flash Recovery Area Full

Error:

ORA-19809: limit exceeded for recovery files

Solution:

Delete old backups.


1️⃣9️⃣ Database Lock Contention

Sessions waiting for locks.

Check:

SELECT * FROM v$lock;

Tune application transactions.


2️⃣0️⃣ Slow SQL Queries

Common in production systems.

Find top SQL:

SELECT sql_id, elapsed_time
FROM v$sql
ORDER BY elapsed_time DESC;

Tune SQL or create indexes.



Oracle Memory Tuning Guide (Complete DBA Guide)


1️⃣ Oracle Memory Architecture

Oracle memory is mainly divided into two parts:

🔹 SGA (System Global Area)

Shared memory used by all sessions.

Main components:

  • Database Buffer Cache – stores data blocks

  • Shared Pool – stores SQL execution plans

  • Large Pool – used for RMAN and parallel queries

  • Java Pool

  • Redo Log Buffer

Check SGA size:

SHOW PARAMETER sga;

🔹 PGA (Program Global Area)

Private memory allocated to each server process.

Used for:

  • Sorting

  • Hash joins

  • Session variables

  • Bitmap operations

Check PGA parameters:

SHOW PARAMETER pga;

2️⃣ Memory Management Methods

Automatic Memory Management (AMM)

Oracle automatically manages SGA + PGA.

Parameters:

memory_target
memory_max_target

Example:

ALTER SYSTEM SET memory_target=8G SCOPE=SPFILE;
ALTER SYSTEM SET memory_max_target=8G SCOPE=SPFILE;

Automatic Shared Memory Management (ASMM)

Oracle manages SGA automatically.

Parameters:

sga_target
pga_aggregate_target

Example:

ALTER SYSTEM SET sga_target=6G SCOPE=BOTH;
ALTER SYSTEM SET pga_aggregate_target=2G SCOPE=BOTH;

3️⃣ Check Current Memory Usage

Check SGA components:

SELECT component,
current_size/1024/1024 MB
FROM v$sga_dynamic_components;

Check PGA usage:

SELECT name,value
FROM v$pgastat;

Check total SGA:

SELECT * FROM v$sga;

4️⃣ Shared Pool Tuning

Shared pool stores:

  • SQL execution plans

  • PL/SQL code

  • Data dictionary

Check shared pool memory:

SELECT pool,name,bytes/1024/1024 MB
FROM v$sgastat
WHERE pool='shared pool';

Common issue:

ORA-04031: unable to allocate shared memory

Solution:

ALTER SYSTEM SET shared_pool_size=1G SCOPE=BOTH;

5️⃣ Buffer Cache Tuning

Buffer cache stores frequently accessed data blocks.

Check buffer cache hit ratio:

SELECT
(1 - (physical reads /
(db block gets + consistent gets))) * 100
AS buffer_cache_hit_ratio
FROM v$sysstat;

Recommended:

Hit Ratio > 90%

Increase buffer cache:

ALTER SYSTEM SET db_cache_size=4G SCOPE=BOTH;

6️⃣ PGA Memory Tuning

PGA handles:

  • Sort operations

  • Hash joins

  • Session memory

Check PGA statistics:

SELECT * FROM v$pgastat;

Important columns:

  • total PGA allocated

  • cache hit percentage

Recommended configuration:

PGA_AGGREGATE_LIMIT ≈ 2 × PGA_AGGREGATE_TARGET

Example:

ALTER SYSTEM SET pga_aggregate_target=4G SCOPE=BOTH;
ALTER SYSTEM SET pga_aggregate_limit=8G SCOPE=BOTH;

7️⃣ Monitor SQL Work Areas

Large queries may consume excessive PGA.

Check active work areas:

SELECT
sql_id,
operation_type,
actual_mem_used
FROM v$sql_workarea_active;

Look for:

  • Large sort operations

  • Hash joins


8️⃣ Use Oracle Advisory Views

Oracle provides recommendations for memory tuning.

Check SGA advisory:

SELECT
sga_size,
estd_db_time
FROM v$sga_target_advice;

Check PGA advisory:

SELECT
pga_target_for_estimate,
estd_pga_cache_hit_percentage
FROM v$pga_target_advice;

These views help determine optimal memory sizes.


9️⃣ Monitor with AWR Reports

Generate AWR report:

@$ORACLE_HOME/rdbms/admin/awrrpt.sql

Important sections:

  • Memory statistics

  • PGA usage

  • SGA recommendations

  • Top wait events


🔟 OS Level Memory Monitoring

Always check server memory.

Linux commands:

free -g
top
vmstat

Ensure Oracle does not consume all physical RAM.


1️⃣1️⃣ Common Oracle Memory Errors

ErrorCause
ORA-04031Shared pool memory shortage
ORA-04036PGA memory limit exceeded
ORA-04030Process memory exhausted

1️⃣2️⃣ Recommended Memory Allocation

Typical OLTP database:

SGA = 60–70% of RAM
PGA = 20–30% of RAM
OS = remaining memory

Example (Server RAM 32GB):

SGA = 20GB
PGA = 8GB
OS = 4GB

⭐ Best Practices for Oracle Memory Tuning

✔ Use automatic memory management when possible
✔ Monitor memory usage regularly
✔ Use bind variables to reduce shared pool usage
✔ Avoid excessive parallel queries
✔ Analyze AWR reports periodically
✔ Tune SQL before increasing memory

Oracle Memory Tuning Best Practices

 

1️⃣ Use Automatic Memory Management (AMM) or ASMM

Oracle provides automatic memory management to simplify tuning.

Automatic Memory Management (AMM)

MEMORY_TARGET
MEMORY_MAX_TARGET

Example:

ALTER SYSTEM SET memory_target=8G SCOPE=SPFILE;
ALTER SYSTEM SET memory_max_target=8G SCOPE=SPFILE;

Oracle automatically manages SGA + PGA.


Automatic Shared Memory Management (ASMM)

If AMM is not used, configure:

SGA_TARGET
PGA_AGGREGATE_TARGET

Example:

ALTER SYSTEM SET sga_target=6G SCOPE=BOTH;
ALTER SYSTEM SET pga_aggregate_target=2G SCOPE=BOTH;

2️⃣ Monitor SGA Components Regularly

Key SGA areas:

  • Shared Pool

  • Buffer Cache

  • Large Pool

  • Java Pool

  • Redo Log Buffer

Check SGA usage:

SELECT component, current_size/1024/1024 MB
FROM v$sga_dynamic_components;

3️⃣ Properly Size the Shared Pool

Shared pool stores:

  • SQL execution plans

  • PL/SQL

  • Data dictionary

Too small → errors like:

ORA-04031: unable to allocate shared memory

Check usage:

SELECT pool, name, bytes
FROM v$sgastat
WHERE pool='shared pool';

4️⃣ Optimize Buffer Cache

Buffer cache stores data blocks.

If too small → excessive disk I/O.

Check hit ratio:

SELECT
(1 - (physical reads / (db block gets + consistent gets))) * 100
AS buffer_cache_hit_ratio
FROM v$sysstat;

Recommended:

Buffer Cache Hit Ratio > 90%

5️⃣ Tune PGA Memory

PGA handles:

  • Sorting

  • Hash joins

  • Session memory

Check PGA statistics:

SELECT * FROM v$pgastat;

Best practice:

PGA_AGGREGATE_LIMIT ≈ 2 × PGA_AGGREGATE_TARGET

Example:

PGA_AGGREGATE_TARGET = 4G
PGA_AGGREGATE_LIMIT = 8G

6️⃣ Monitor SQL Work Areas

Large queries may consume huge PGA memory.

Check active work areas:

SELECT *
FROM v$sql_workarea_active;

Look for:

  • Large sorts

  • Hash joins


7️⃣ Avoid Excessive Hard Parsing

Hard parsing fills shared pool memory.

Check parsing:

SELECT sql_text, parse_calls
FROM v$sqlarea
ORDER BY parse_calls DESC;

Best practice:

Use bind variables.

Example:

SELECT * FROM employees WHERE employee_id = :emp_id;

8️⃣ Monitor Memory Usage with AWR Reports

Use AWR reports to analyze memory performance.

Steps:

@$ORACLE_HOME/rdbms/admin/awrrpt.sql

Look for:

  • Memory advisory

  • PGA usage

  • SGA tuning suggestions


9️⃣ Use Memory Advisory Views

Oracle provides advisory views for tuning.

Example:

SELECT *
FROM v$sga_target_advice;

For PGA:

SELECT *
FROM v$pga_target_advice;

These show recommended memory sizes.


🔟 Monitor OS Memory

Always check server memory.

Example (Linux):

free -g
top
vmstat

Ensure Oracle does not consume all physical RAM.


📊 Recommended Memory Allocation (General Guideline)

Typical OLTP database:

SGA = 60–70% of RAM
PGA = 20–30% of RAM
OS = Remaining memory

Example (Server RAM 32GB):

SGA = 20GB
PGA = 8GB
OS = 4GB

⚠️ Common Memory Errors DBAs Face

ErrorCause
ORA-04031Shared pool exhausted
ORA-04036PGA limit exceeded
ORA-4030Process memory exhausted

📘 Key Learning for Oracle DBAs

Always monitor these views:

v$sga
v$sgastat
v$pgastat
v$sql_workarea
v$sga_target_advice
v$pga_target_advice

Memory tuning should be data-driven, not guesswork.