My Youtube Channel

Please Subscribe

Flag of Nepal

Built in OpenGL

Word Cloud in Python

With masked image

Tuesday, March 24, 2026

20 Linux Commands Every Database Administrator Should Know || Linux Commands Cheatsheet

Database Administration · Linux

20 Linux Commands Every Database Administrator Should Know

๐Ÿ“… 2025 ⏱ 18 min read ๐Ÿ”ง MySQL · PostgreSQL · Oracle

Master these essential Linux commands to diagnose performance bottlenecks, monitor database processes, track disk usage, analyze logs, and keep your databases running at peak health — with real-world examples you can copy and paste directly.

As a Database Administrator, your terminal is your most powerful diagnostic tool. When a database slows down at 2 AM, you need to diagnose it fast — is it CPU? Memory? Disk I/O? A runaway query? A network bottleneck? The commands in this guide are the ones senior DBAs reach for first, every time.

Each command includes its most useful flags, real DBA output examples, and practical troubleshooting scenarios for MySQL, PostgreSQL, and Oracle environments.

01
top
Real-time view of system CPU, memory, and running processes
Performance

What it does: top displays a continuously updated snapshot of your system's resource usage — CPU load, memory consumption, swap usage, and a ranked list of the most resource-hungry processes. For a DBA, it's the first command to run when a server feels sluggish.

Basic usage
top                          # launch interactive view
top -u mysql                 # show only mysql user processes
top -u postgres              # show only postgres user processes
top -b -n 1                   # batch mode: single snapshot (good for cron scripts)
top -d 2                      # refresh every 2 seconds
Sample output — MySQL server under load
top - 14:32:11 up 42 days, 6:14,  2 users,  load average: 4.21, 3.87, 3.54
Tasks: 312 total,   3 running, 309 sleeping
%Cpu(s): 62.4 us,  5.1 sy,  0.0 ni, 30.2 id,  2.1 wa,  0.0 hi
MiB Mem :  64432.0 total,   1248.3 free,  58731.2 used,   4452.5 buff/cache

  PID USER      PR  NI  VIRT    RES    SHR  S  %CPU  %MEM  TIME+     COMMAND
 4821 mysql     20   0  58.4g  49.2g   8.1g R  94.3  78.2  182:14.33 mysqld
 5103 mysql     20   0  58.4g  49.2g   8.1g S  12.1  78.2   18:02.11 mysqld
⚠️

DBA Red Flag: If %wa (I/O wait) is consistently above 10%, your database is waiting on disk — suspect missing indexes, full table scans, or underpowered storage. If us (user CPU) is above 80%, you likely have long-running or poorly optimized queries.

Interactive KeyAction
PSort by CPU usage (default)
MSort by memory usage
1Toggle per-CPU core breakdown
kKill a process by PID
qQuit
๐Ÿ’ก

DBA Trick: Run top -b -n 3 -u mysql > /tmp/top_snapshot.txt to capture 3 snapshots automatically — useful for attaching to incident tickets.

02
htop
Color-enhanced interactive process manager with tree view
Performance

What it does: htop is a more user-friendly alternative to top. It displays CPU bars for each core, scrollable process lists, and allows killing or renicing processes interactively with arrow keys.

Usage
htop                          # launch interactive view
htop -u mysql                 # filter to mysql user
htop -p 4821,4822,4823        # monitor specific PIDs only
htop --sort-key=PERCENT_MEM   # start sorted by memory
๐ŸŽฏ

DBA Use Case: Use htop -p $(pgrep -d',' mysqld) to monitor all mysqld threads simultaneously. Press F5 for tree view to see parent–child thread relationships — essential for understanding connection pools and background workers.

03
df
Report disk space usage across all mounted filesystems
Storage

What it does: df (disk free) shows how much disk space is available and used on each mounted filesystem. For DBAs, this is critical — a full /var or /data partition will crash your database or corrupt tables.

Common usage
df -h                          # human-readable sizes (GB, MB)
df -hT                         # include filesystem type (ext4, xfs, nfs)
df -h /var/lib/mysql           # check specific MySQL data directory
df -h /var/lib/postgresql      # check PostgreSQL data directory
df -i                           # check inode usage (important for many small files)
Sample output
Filesystem      Size   Used  Avail  Use%  Mounted on
/dev/sda1        50G    18G    32G   36%  /
/dev/sdb1       500G   481G    19G   97%  /var/lib/mysql
/dev/sdc1       200G    45G   155G   23%  /backups
tmpfs            32G   256M    32G    1%  /dev/shm
๐Ÿšจ

Critical Alert: The /var/lib/mysql partition at 97% above is a disaster waiting to happen. MySQL will refuse writes and InnoDB may crash. Set up disk usage alerts at 80% — never let a database partition reach 100%.

Alert script — disk usage monitor
#!/bin/bash
# Add to cron: */5 * * * * /usr/local/bin/check_disk.sh
THRESHOLD=80
df -h | awk 'NR>1 { gsub("%",""); if ($5 > THRESHOLD) print "ALERT: "$6" at "$5"%" }' \
  THRESHOLD=$THRESHOLD | mail -s "Disk Alert" dba@yourcompany.com
๐Ÿ’ก

Pro Tip: Don't forget to check inodes with df -i! A filesystem can run out of inodes even when disk space is available. MySQL's InnoDB with innodb_file_per_table generates one .ibd file per table — thousands of tables = thousands of inodes.

04
du
Estimate disk usage of files and directories
Storage

What it does: While df shows filesystem-level usage, du (disk usage) drills into directories to show exactly what's consuming space. DBAs use it to find which databases, tables, or log files are eating disk.

DBA-specific du commands
# Show total size of MySQL data directory
du -sh /var/lib/mysql/

# Show size of each MySQL database
du -h --max-depth=1 /var/lib/mysql/ | sort -rh

# Find the top 10 largest tables (InnoDB .ibd files)
du -h /var/lib/mysql/*/*.ibd | sort -rh | head -10

# Check binary log sizes (common cause of disk bloat)
du -sh /var/lib/mysql/mysql-bin.* 2>/dev/null | sort -rh

# PostgreSQL: find largest databases
du -h --max-depth=1 /var/lib/postgresql/*/main/base/ | sort -rh
Sample output — finding disk hogs
$ du -h --max-depth=1 /var/lib/mysql/ | sort -rh
245G    /var/lib/mysql/production_orders
 89G    /var/lib/mysql/analytics
 32G    /var/lib/mysql/user_events
 14G    /var/lib/mysql/mysql
389G    /var/lib/mysql/
๐Ÿ’ก

Pro Tip: Binary logs often grow silently. Ensure expire_logs_days (MySQL 5.x) or binlog_expire_logs_seconds (MySQL 8.x) is set to avoid runaway disk usage.

05
iostat
Monitor disk I/O throughput, latency, and utilization
I/O

What it does: iostat (from the sysstat package) reports CPU statistics and I/O statistics for devices and partitions. It's the go-to tool when diagnosing storage bottlenecks — slow queries that access disk heavily will show up here.

Usage
iostat -xh 2                  # extended stats, human-readable, every 2 seconds
iostat -xhd sdb 1             # watch specific device every 1 second
iostat -p sdb                  # per-partition stats for device sdb
Sample output — I/O saturation
Device   r/s    w/s  rMB/s  wMB/s  await  svctm  %util
sdb     842.3  1204.7   98.4  148.2   28.3    0.8   99.1
sdc      12.0    24.1    1.2    3.4    1.2    0.5    3.8
⚠️

Key Metrics: %util near 100% means the disk is saturated. await above 20ms for HDDs or 5ms for SSDs is a concern. svctm is actual service time; if await >> svctm, the device queue is backing up.

06
vmstat
Virtual memory, swap, CPU, and I/O statistics at a glance
Performance
Usage
vmstat 2 10                   # report every 2s, 10 times
vmstat -s                      # memory statistics summary
vmstat -d                      # disk statistics
Sample output
procs -------memory------ --swap-- ---io--- -system-- ----cpu-----
 r  b   swpd   free   buff  cache   si   so   bi   bo  in   cs us sy id wa
 4  8  171924  23456  4096 1048576  12   18  842 1204 4210 2890 62  6 22 10
⚠️

DBA Signals: b (blocked processes) > 0 signals I/O contention. si/so (swap in/out) > 0 means you're swapping — terrible for database performance. wa (I/O wait) > 10 indicates disk bottleneck.

07
ps
Snapshot of currently running processes and their state
Process

What it does: ps (process status) shows a point-in-time snapshot of running processes. Unlike top, it doesn't update continuously — making it ideal for scripting, piping to grep, or capturing process states for logs and tickets.

DBA-specific ps commands
# Show all MySQL processes with CPU, MEM, and start time
ps aux | grep mysqld

# Custom columns: PID, user, CPU, memory, elapsed time, command
ps -eo pid,user,%cpu,%mem,etime,cmd | grep mysqld

# Count number of MySQL connections (threads)
ps aux | grep mysqld | wc -l

# Find zombie/stuck processes (D = uninterruptible sleep = I/O wait)
ps aux | awk '$8 == "D" { print }'
Sample output
$ ps -eo pid,user,%cpu,%mem,etime,cmd | grep mysqld
  PID   USER    %CPU  %MEM     ELAPSED  CMD
 4821  mysql   94.3  78.2  42-06:14:22  /usr/sbin/mysqld --basedir=/usr
 4822  mysql    0.1   0.0  42-06:14:21  /usr/sbin/mysqld --basedir=/usr
๐Ÿ’ก

DBA Trick: Combine ps with watch for a pseudo-live view: watch -n 1 'ps aux | grep mysqld | grep -v grep'. Great for watching connections grow during a traffic spike.

08
netstat
Display network connections, listening ports, and routing tables
Network

What it does: netstat shows all active network connections, open ports, and socket states. For DBAs, it reveals who's connected to your database, how many connections are in use, and whether there's a connection leak.

DBA network investigation
# List all listening ports — confirm MySQL (3306) or PG (5432) is listening
netstat -tlnp

# Count connections by state (ESTABLISHED, TIME_WAIT, CLOSE_WAIT)
netstat -an | grep :3306 | awk '{print $6}' | sort | uniq -c | sort -rn

# Show which IPs are connecting to MySQL and how many connections each
netstat -an | grep 'ESTABLISHED' | grep :3306 | awk '{print $5}' \
  | cut -d: -f1 | sort | uniq -c | sort -rn

# PostgreSQL: connections to port 5432
netstat -an | grep :5432 | awk '{print $6}' | sort | uniq -c
Sample output — connection state analysis
$ netstat -an | grep :3306 | awk '{print $6}' | sort | uniq -c | sort -rn
    312 ESTABLISHED
     87 TIME_WAIT
     42 CLOSE_WAIT
      8 SYN_SENT
⚠️

Connection Leak Signals: A high count of CLOSE_WAIT connections usually means your application is not properly closing DB connections — a connection leak. Many TIME_WAIT connections are normal after spikes but can pile up with poor connection pooling.

๐ŸŽฏ

Note: On modern Linux systems, netstat is deprecated. Use ss (command #9) for better performance on servers with thousands of connections.

09
ss
Modern, faster socket statistics — the netstat replacement
Network
Usage
ss -tlnp                       # TCP listening ports with process names
ss -tnp sport = :3306          # all connections on MySQL port
ss -tnp state established 'dport = :5432'  # established PG connections
ss -s                          # summary count of connections by state

# Connection count to MySQL from each source IP
ss -tn state established 'dport = :3306' \
  | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn
10
grep
Search and filter text using patterns — the DBA's log knife
Search

What it does: grep searches for pattern matches in text. For DBAs, it's the primary tool for searching error logs, slow query logs, and configuration files. Master grep and you'll cut incident resolution time in half.

Essential grep patterns for DBAs
# Find all errors in MySQL error log
grep -i "error" /var/log/mysql/error.log

# Find crashes, deadlocks, or corruption
grep -iE "(crash|deadlock|corrupt|InnoDB: Error)" /var/log/mysql/error.log

# Show context: 3 lines before and after each match
grep -i -B3 -A3 "deadlock" /var/log/mysql/error.log

# Find slow queries over 5 seconds in slow query log
grep -A2 "Query_time: [5-9]\|Query_time: [0-9][0-9]" /var/log/mysql/slow.log

# Count occurrences of "Access denied" errors
grep -c "Access denied" /var/log/mysql/error.log

# Search PostgreSQL logs for connection failures
grep -i "FATAL\|connection refused\|too many connections" \
  /var/log/postgresql/postgresql-*.log

# Inverse match — show lines NOT matching a pattern
grep -v "Note\|Warning" /var/log/mysql/error.log | grep -i "error"

# Live monitoring with color highlight
tail -f /var/log/mysql/error.log | grep --color=always -i "error\|warn\|critical"
FlagDescription
-iCase-insensitive search
-r / -RRecursive directory search
-lPrint only filenames that match
-cCount of matching lines
-vInvert match (show non-matching lines)
-EExtended regex (use | for OR)
-oPrint only the matched part of the line
-B N / -A NN lines before / after each match
-nPrint line numbers
11
awk
Field-based text processing and log aggregation
Text
DBA log processing with awk
# Extract query times from slow query log and calculate average
awk '/Query_time/ { sum += $2; count++ } END { print "Avg:", sum/count "s" }' \
  /var/log/mysql/slow.log

# Print the top query patterns (the actual SQL) from slow log
awk '/^(SELECT|INSERT|UPDATE|DELETE)/ { print }' /var/log/mysql/slow.log \
  | sort | uniq -c | sort -rn | head -20

# Parse PostgreSQL CSV logs — extract duration and query
awk -F',' '$13 > 5000 { print $13"ms:", $15 }' /var/log/postgresql/pg.csv

# Count error types by hour from MySQL log
awk '/ERROR/ { match($0, /[0-9]{2}:[0-9]{2}/, t); errors[t[0]]++ }
  END { for (h in errors) print h, errors[h] }' /var/log/mysql/error.log | sort
12
tail
Follow logs in real-time as your database writes them
Text
Live log monitoring
# Follow MySQL error log live (Ctrl+C to stop)
tail -f /var/log/mysql/error.log

# Follow multiple logs simultaneously
tail -f /var/log/mysql/error.log /var/log/mysql/slow.log

# Show last 100 lines, then follow
tail -n 100 -f /var/log/mysql/error.log

# Follow with grep — live filtered view
tail -f /var/log/mysql/error.log | grep --line-buffered -i "error\|warn"

# PostgreSQL: follow all logs
tail -f /var/log/postgresql/postgresql-$(date +%Y-%m-%d).log
๐Ÿ’ก

Pro Tip: Use multitail (if installed) to follow multiple log files in split-screen terminal panels — invaluable during incidents when you need to watch the MySQL error log and system journal at the same time.

13
find
Locate database files, logs, and configs by any attribute
Search
File hunting for DBAs
# Find all MySQL config files on the system
find / -name "my.cnf" -o -name "my.ini" 2>/dev/null

# Find large .ibd files (tables over 1 GB)
find /var/lib/mysql -name "*.ibd" -size +1G -exec du -sh {} \; | sort -rh

# Find backup files older than 30 days to clean up
find /backups -name "*.sql.gz" -mtime +30 -delete

# Find files with wrong permissions in MySQL data dir
find /var/lib/mysql ! -user mysql -ls

# Find core dump files that MySQL may have created
find / -name "core.*" -user mysql -mtime -7 2>/dev/null
14
lsof
List open files — see what MySQL/Postgres has locked or opened
System Info
Usage
# List all files opened by MySQL process
lsof -u mysql

# Count open file descriptors (compare against ulimit)
lsof -u mysql | wc -l

# Check which process is using MySQL port 3306
lsof -i :3306

# Find deleted files still held open by MySQL
lsof -u mysql | grep "deleted"
⚠️

Deleted-but-open files: You delete a large binary log to free space, but df still shows the disk full — because MySQL still holds the file open. lsof | grep deleted reveals these ghost files. Restarting MySQL releases them.

15
strace
Trace system calls made by a database process
I/O
Usage — use with caution in production
# Attach to running MySQL process and trace I/O calls
strace -p $(pidof mysqld | awk '{print $1}') -e trace=read,write

# Trace with timestamps and output to file
strace -p 4821 -tt -e trace=open,read,write,close -o /tmp/strace_mysql.txt

# Count system call frequency (profile mode)
strace -p 4821 -c -f
๐Ÿšจ

Warning: strace can add significant overhead — use only on non-production systems or during controlled maintenance windows. For production diagnosis, prefer perf or MySQL's Performance Schema instead.

16
sar
System Activity Reporter — historical performance data
Performance

What it does: sar collects and saves system activity data. Unlike top (which only shows the current moment), sar lets you go back in time and see what happened at 3 AM when the DBA was asleep. Part of the sysstat package.

Historical investigation
# CPU usage for today, every 10 minutes
sar -u 10

# CPU usage for a specific past date (day 20 of current month)
sar -u -f /var/log/sysstat/sa20

# Memory usage history
sar -r -f /var/log/sysstat/sa20

# Disk I/O history
sar -b -f /var/log/sysstat/sa20
๐Ÿ’ก

DBA Use Case: A user complains "the database was slow at 3 AM." Use sar -u -r -b -f /var/log/sysstat/sa$(date +%d -d yesterday) to pull CPU, memory, and I/O stats for yesterday and pinpoint the exact degradation window.

17
free
Quick snapshot of total, used, and available memory
Performance
Usage
free -h                        # human-readable
free -h -s 2                   # update every 2 seconds
free -m                        # in megabytes
Sample output
               total        used        free      shared  buff/cache   available
Mem:            62Gi        57Gi       1.2Gi       256Mi       4.1Gi       4.8Gi
Swap:          8.0Gi       171Mi       7.8Gi
๐ŸŽฏ

Key Insight: Don't panic if "free" memory is low — Linux uses spare RAM as disk cache (buff/cache), which benefits databases. The "available" column is what matters. If "available" is near 0 and swap is being used, you have a real memory problem.

18
ulimit
View and set resource limits for database processes
Limits
Usage
ulimit -a                      # show all current limits
ulimit -n                      # show max open files (critical for MySQL)
ulimit -n 65536               # set open files limit (current shell)

# Check limits of a running MySQL process
cat /proc/$(pidof mysqld | awk '{print $1}')/limits | grep -i "open files"

# Set permanent limits (add to /etc/security/limits.conf)
echo "mysql   soft   nofile   65536" >> /etc/security/limits.conf
echo "mysql   hard   nofile   65536" >> /etc/security/limits.conf
⚠️

Critical for MySQL: MySQL uses one file descriptor per table when innodb_file_per_table=ON. If the open file limit is too low (default is often 1024), MySQL will log "Too many open files" errors. Set nofile to at least 65536 for production MySQL servers.

19
journalctl
Query the systemd journal — database service logs and OOM kills
System Info
Usage
# Follow MySQL service logs live
journalctl -u mysql -f

# Show MySQL logs since last boot
journalctl -u mysql -b

# Show logs for a specific time window
journalctl -u mysql --since "2025-03-20 02:00:00" --until "2025-03-20 04:00:00"

# MOST IMPORTANT: Find Out-of-Memory kills (OOM killer)
journalctl -k | grep -i "oom\|killed process"

# Check why MySQL service stopped/restarted
journalctl -u mysql --no-pager | grep -i "start\|stop\|fail\|error"
๐Ÿšจ

OOM Killer: The Linux OOM killer terminates processes to free memory — and mysqld is often a prime target due to its large memory footprint. If your MySQL keeps mysteriously dying, journalctl -k | grep -i oom will confirm it. Fix: tune innodb_buffer_pool_size down, or add more RAM.

20
sysctl
Read and tune kernel parameters for database optimization
Tuning

What it does: sysctl reads and modifies kernel parameters at runtime. For DBAs, it's used to tune OS-level settings that directly impact database performance — network buffers, memory behavior, I/O scheduling, and file descriptor limits.

Essential kernel tunables for DBAs
# KEY DBA TUNING: Reduce swappiness (0-10 for database servers)
sysctl -w vm.swappiness=10

# Increase max open files system-wide
sysctl -w fs.file-max=2097152

# Tune network buffers (good for high-throughput replication)
sysctl -w net.core.rmem_max=134217728
sysctl -w net.core.wmem_max=134217728

# View all DB-relevant parameters at once
sysctl -a 2>/dev/null | grep -E "swappiness|hugepages|file-max|overcommit|somaxconn"
Make changes permanent — /etc/sysctl.conf
# Add to /etc/sysctl.conf for persistence across reboots
cat >> /etc/sysctl.conf << 'EOF'
# MySQL/PostgreSQL performance tuning
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5
fs.file-max = 2097152
net.core.somaxconn = 65535
EOF

# Apply without reboot
sysctl -p
๐Ÿ’ก

vm.swappiness: On database servers, set this to 1–10 (not 0). A low non-zero value tells the kernel to strongly prefer physical RAM but still use swap as an absolute last resort — avoiding an OOM kill if memory is exhausted.

DBA Command Cheat Sheet

Copy-paste ready commands for the most common DBA scenarios

top -u mysql
MySQL CPU & memory live
df -h /var/lib/mysql
Check MySQL disk space
du -h --max-depth=1 /var/lib/mysql/
Size per database
iostat -xh 2
Live disk I/O stats
ps aux | grep mysqld
MySQL process snapshot
ss -tn state established 'dport = :3306'
Active DB connections
grep -i "error" /var/log/mysql/error.log
Find errors in log
tail -f /var/log/mysql/error.log
Follow live error log
journalctl -k | grep -i oom
Check OOM kills
sysctl vm.swappiness
Check swap aggressiveness
free -h
Quick memory overview
lsof -u mysql | grep deleted
Ghost files eating disk
vmstat 2 10
Memory & swap pressure
sar -u -f /var/log/sysstat/saNN
Historical CPU usage
find /var/lib/mysql -name "*.ibd" -size +1G
Largest table files
grep -iE "(deadlock|crash|corrupt)" /var/log/mysql/error.log
Critical log events

Oracle DBA Interview Questions and Answers (2026 Guide)

Oracle DBA Interview Questions and Answers (2026 Guide)

Preparing for an Oracle DBA interview? Whether you're a beginner or an experienced professional working with Oracle Database, this guide covers the most commonly asked questions across key areas:

  • Tablespaces

  • Indexes

  • Performance Tuning

  • Backups (RMAN)

  • RAC Basics


๐Ÿ“ฆ 1. Tablespaces

❓ What is a tablespace?

A tablespace is a logical storage unit in Oracle used to store database objects like tables and indexes.


❓ Types of tablespaces?

  • SYSTEM → stores data dictionary

  • SYSAUX → auxiliary metadata

  • USERS → default user data

  • UNDO → undo information

  • TEMP → temporary operations


❓ Difference between bigfile and smallfile tablespace?

FeatureBigfileSmallfile
DatafilesSingleMultiple
SizeVery largeModerate
ManagementSimplerFlexible

❓ How to check tablespace size?

SELECT tablespace_name, SUM(bytes)/1024/1024 MB
FROM dba_data_files
GROUP BY tablespace_name;

❓ What happens when tablespace is full?

  • Inserts/updates fail

  • Errors like ORA-01653

  • Application impact


๐Ÿ“Š 2. Indexes

❓ What is an index?

An index improves query performance by allowing faster data retrieval.


❓ Types of indexes?

  • B-Tree Index (default)

  • Bitmap Index

  • Unique Index

  • Composite Index

  • Function-based Index


❓ When should you not use an index?

  • Small tables

  • Columns with low selectivity

  • Frequent DML operations


❓ How to find unused indexes?

SELECT * FROM v$object_usage WHERE used = 'NO';

❓ Difference between B-Tree and Bitmap index?

FeatureB-TreeBitmap
Use CaseOLTPData warehouse
DMLFastSlow
CardinalityHighLow

๐Ÿš€ 3. Performance Tuning

❓ What is performance tuning?

Process of improving database efficiency by optimizing SQL, memory, and resources.


❓ How to identify slow SQL?

  • V$SQL

  • V$SQLAREA

  • AWR reports


❓ What is an execution plan?

It shows how Oracle executes a SQL query.

EXPLAIN PLAN FOR SELECT * FROM emp;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

❓ What causes slow queries?

  • Missing indexes

  • Full table scans

  • Poor joins

  • Outdated statistics


❓ What is bind variable?

A placeholder used in SQL to improve parsing efficiency.


๐Ÿ’พ 4. Backup and Recovery (RMAN)

❓ What is RMAN?

Recovery Manager is Oracle’s tool for backup and recovery.


❓ Types of backups?

  • Full backup

  • Incremental backup

  • Archive log backup


❓ Difference between Level 0 and Level 1?

  • Level 0 → full backup

  • Level 1 → incremental changes


❓ What is ARCHIVELOG mode?

It allows recovery up to the last committed transaction.


❓ How to take backup?

BACKUP DATABASE PLUS ARCHIVELOG;

❓ How to validate backup?

RESTORE DATABASE VALIDATE;

๐Ÿงฉ 5. RAC (Real Application Clusters) Basics

❓ What is RAC?

Oracle RAC allows multiple instances to access a single database.


❓ Benefits of RAC?

  • High availability

  • Load balancing

  • Scalability


❓ What is CRS?

Cluster Ready Services manages cluster resources.


❓ What is SCAN?

Single Client Access Name simplifies client connectivity.


❓ What is interconnect?

Private network used for communication between nodes.


๐Ÿง  6. Scenario-Based Questions

❓ Tablespace full issue?

Answer:

  • Add datafile

  • Resize existing file

  • Enable autoextend


❓ Database running slow suddenly?

Answer:

  • Check AWR report

  • Identify top SQL

  • Check CPU, I/O


❓ Recovery after accidental delete?

Answer:

  • Use RMAN restore

  • Flashback (if enabled)


❓ High CPU usage?

Answer:

  • Identify SQL from V$SQL

  • Tune query

  • Add indexes


๐ŸŽฏ 7. Tips to Crack Oracle DBA Interviews

✅ Be strong in basics

✅ Practice SQL queries

✅ Understand real scenarios

✅ Learn RMAN commands

✅ Know RAC architecture basics


๐Ÿ“Œ Conclusion

An Oracle DBA interview for roles involving Oracle Database typically focuses on:

  • Storage (tablespaces)

  • Performance (SQL tuning)

  • Recovery (RMAN)

  • High availability (RAC)

Mastering these areas with practical examples will give you a strong edge in 2026 interviews.


๐Ÿš€ Bonus: What Interviewers Expect

  • Clear understanding of concepts

  • Hands-on experience

  • Problem-solving approach

  • Confidence in troubleshooting

How to Identify Slow SQL Queries in Oracle (Practical Guide for Performance Tuning)

 

How to Identify Slow SQL Queries in Oracle (Practical Guide for Performance Tuning)

Performance tuning is one of the most valuable skills when working with Oracle Database. Slow SQL queries can degrade application performance, increase CPU usage, and frustrate users.

In this guide, we’ll cover how to identify slow SQL using:

  • V$SQL

  • V$SQLAREA

  • AWR Reports

  • Simple and effective tuning ideas


๐Ÿ” 1. Using V$SQL to Find Slow Queries

The V$SQL view contains detailed statistics about SQL statements currently in the shared pool.


✅ Find Top Slow Queries by Elapsed Time

SELECT 
    sql_id,
    executions,
    elapsed_time/1000000 AS elapsed_sec,
    cpu_time/1000000 AS cpu_sec,
    disk_reads,
    buffer_gets,
    sql_text
FROM 
    v$sql
ORDER BY 
    elapsed_time DESC
FETCH FIRST 10 ROWS ONLY;

๐Ÿ“Œ Key Columns Explained

  • elapsed_time → total execution time

  • cpu_time → CPU usage

  • disk_reads → physical I/O (slow operations)

  • buffer_gets → logical reads

  • executions → how many times query ran

๐Ÿ‘‰ Focus on:

  • High elapsed time

  • High disk reads

  • High buffer gets


๐ŸŽฏ Find Slow Queries Per Execution

SELECT 
    sql_id,
    executions,
    elapsed_time / DECODE(executions,0,1,executions) / 1000000 AS avg_time_sec,
    sql_text
FROM 
    v$sql
ORDER BY 
    avg_time_sec DESC;

๐Ÿ‘‰ This helps identify queries that are slow individually (not just frequent ones).


๐Ÿ“Š 2. Using V$SQLAREA (Aggregated View)

V$SQLAREA provides aggregated statistics for SQL statements.


✅ Top Queries by Resource Usage

SELECT 
    sql_id,
    executions,
    buffer_gets,
    disk_reads,
    elapsed_time/1000000 AS elapsed_sec,
    sql_text
FROM 
    v$sqlarea
ORDER BY 
    buffer_gets DESC
FETCH FIRST 10 ROWS ONLY;

๐Ÿ“Œ When to Use V$SQLAREA

  • To identify heavy queries overall

  • When multiple executions are involved

  • For workload-level analysis


๐Ÿ“ˆ 3. Using AWR Reports (Advanced Method)

๐Ÿ” What is AWR?

AWR (Automatic Workload Repository) stores historical performance data in Oracle Database.


๐Ÿ› ️ Generate AWR Report

@$ORACLE_HOME/rdbms/admin/awrrpt.sql

๐Ÿ“Š Key Sections in AWR Report

๐Ÿ”ฅ Top SQL by Elapsed Time

  • Shows queries consuming most time

๐Ÿ’ฝ Top SQL by Disk Reads

  • Identifies I/O-heavy queries

๐Ÿง  Top SQL by CPU Time

  • CPU-intensive SQL


๐Ÿ“Œ What to Look For

  • High elapsed time SQL

  • SQL with high executions

  • SQL with high I/O

๐Ÿ‘‰ AWR is best for:

  • Historical analysis

  • Production troubleshooting

  • Identifying trends


๐Ÿšจ 4. Common Signs of Slow SQL

  • High response time

  • High CPU usage

  • Excessive disk reads

  • Full table scans

  • Long-running sessions


๐Ÿ› ️ 5. Simple SQL Tuning Ideas


✅ 1. Use Proper Indexes

CREATE INDEX idx_emp_name ON emp(name);

๐Ÿ‘‰ Helps avoid full table scans


✅ 2. Avoid SELECT *

-- Bad
SELECT * FROM employees;

-- Good
SELECT id, name FROM employees;

๐Ÿ‘‰ Reduces unnecessary data retrieval


✅ 3. Use Bind Variables

SELECT * FROM emp WHERE emp_id = :id;

๐Ÿ‘‰ Improves parsing efficiency


✅ 4. Check Execution Plan

EXPLAIN PLAN FOR 
SELECT * FROM emp WHERE id = 100;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

๐Ÿ‘‰ Understand how Oracle executes query


✅ 5. Reduce Full Table Scans

  • Add indexes

  • Use selective conditions


✅ 6. Optimize Joins

  • Use proper join conditions

  • Avoid Cartesian joins


✅ 7. Gather Statistics

EXEC DBMS_STATS.GATHER_SCHEMA_STATS('HR');

๐Ÿ‘‰ Helps optimizer choose better plans


๐Ÿงช 6. Real-World Example

Problem Query

SELECT * FROM orders WHERE customer_id = 101;

Issue

  • No index on customer_id

  • Full table scan


Solution

CREATE INDEX idx_orders_cust ON orders(customer_id);

๐Ÿ‘‰ Result:

  • Query becomes significantly faster


⚖️ V$SQL vs V$SQLAREA vs AWR

FeatureV$SQLV$SQLAREAAWR
Data TypeReal-timeAggregatedHistorical
ScopeIndividual SQLCombined SQLSystem-wide
Use CaseImmediate tuningWorkload analysisDeep performance analysis

๐Ÿ“Œ Conclusion

Identifying slow SQL in Oracle Database involves a combination of:

  • Real-time views (V$SQL, V$SQLAREA)

  • Historical analysis (AWR Reports)

Once identified, applying simple tuning techniques like indexing, query optimization, and statistics gathering can dramatically improve performance.


๐Ÿš€ Next Topics You Can Cover

Since you're building performance-focused content, you can also write about:

  • SQL Execution Plans deep dive

  • Index types in Oracle

  • Wait events and session tuning

  • ASH vs AWR

Just tell me if you want those ready ๐Ÿ‘

How to Drop Tablespace Safely in Oracle (Complete Practical Guide)

 

How to Drop Tablespace Safely in Oracle (Complete Practical Guide)

Managing storage in Oracle Database often involves cleaning up unused tablespaces. However, dropping a tablespace is a critical and irreversible operation if not handled properly.

This guide explains:

  • DROP TABLESPACE syntax

  • Difference between INCLUDING CONTENTS and KEEP DATAFILES

  • Risks and safety precautions

  • Real-world practical steps


๐Ÿ“ฆ 1. What is a Tablespace?

A tablespace is a logical storage unit in Oracle that contains datafiles. It stores:

  • Tables

  • Indexes

  • LOBs

  • Other database objects

Dropping a tablespace removes all objects stored inside it.


⚠️ 2. Basic DROP TABLESPACE Syntax

DROP TABLESPACE tablespace_name;

๐Ÿ‘‰ This works only if the tablespace is empty


๐Ÿ”ฅ 3. Drop Tablespace with Contents

✅ Syntax

DROP TABLESPACE tablespace_name INCLUDING CONTENTS;

๐Ÿ“Œ What it does:

  • Deletes all objects inside the tablespace

  • Removes metadata from data dictionary

  • Does NOT delete physical datafiles

๐Ÿ‘‰ Use this when you want to remove logical structures but keep files on disk.


๐Ÿ’ฃ 4. Drop Tablespace Including Datafiles

✅ Syntax

DROP TABLESPACE tablespace_name INCLUDING CONTENTS AND DATAFILES;

๐Ÿ“Œ What it does:

  • Deletes all objects

  • Deletes datafiles from OS

  • Completely frees disk space

⚠️ This is irreversible


๐ŸงŠ 5. Keep Datafiles Option

✅ Syntax

DROP TABLESPACE tablespace_name INCLUDING CONTENTS KEEP DATAFILES;

๐Ÿ“Œ What it does:

  • Removes tablespace from database

  • Leaves datafiles untouched on disk

๐Ÿ‘‰ Useful when:

  • You want to reuse files

  • You need backup/forensic analysis


⚖️ Summary of Options

CommandObjects RemovedDatafiles Removed
DROP TABLESPACE
INCLUDING CONTENTS
INCLUDING CONTENTS AND DATAFILES
KEEP DATAFILES

๐Ÿšจ 6. Risks of Dropping Tablespace

Dropping a tablespace can cause serious issues if not planned properly:

❌ Data Loss

All tables and indexes inside will be permanently deleted.

❌ Application Failure

If application depends on that tablespace → system may break.

❌ Foreign Key Dependencies

Objects in other tablespaces may reference it.

❌ Backup Impact

If not backed up, recovery becomes impossible.


๐Ÿ›ก️ 7. Safety Checklist Before Dropping

✅ 1. Check Tablespace Contents

SELECT owner, segment_name, segment_type
FROM dba_segments
WHERE tablespace_name = 'USERS';

✅ 2. Check Datafiles

SELECT file_name
FROM dba_data_files
WHERE tablespace_name = 'USERS';

✅ 3. Check Default Tablespace Users

SELECT username
FROM dba_users
WHERE default_tablespace = 'USERS';

๐Ÿ‘‰ Change users before dropping:

ALTER USER username DEFAULT TABLESPACE new_tablespace;

✅ 4. Take Backup (VERY IMPORTANT)

Using RMAN:

BACKUP TABLESPACE users;

✅ 5. Ensure No Active Usage

SELECT * FROM v$sort_usage WHERE tablespace = 'USERS';

๐Ÿงช 8. Practical Example (Step-by-Step)

๐ŸŽฏ Scenario: Drop tablespace OLD_DATA


Step 1: Verify contents

SELECT COUNT(*) FROM dba_segments 
WHERE tablespace_name = 'OLD_DATA';

Step 2: Backup

BACKUP TABLESPACE old_data;

Step 3: Drop safely

DROP TABLESPACE old_data INCLUDING CONTENTS AND DATAFILES;

Step 4: Verify removal

SELECT * FROM dba_tablespaces 
WHERE tablespace_name = 'OLD_DATA';

๐Ÿง  9. Best Practices

✅ Always backup before dropping

✅ Never drop SYSTEM or SYSAUX tablespaces

✅ Avoid dropping USERS tablespace in production

✅ Check dependencies carefully

✅ Use KEEP DATAFILES if unsure

✅ Perform during maintenance window


๐Ÿ” 10. Common Mistakes to Avoid

❌ Dropping without checking users
❌ Forgetting backup
❌ Confusing KEEP DATAFILES vs AND DATAFILES
❌ Dropping active tablespace
❌ Ignoring application impact


๐Ÿ“Œ Conclusion

Dropping a tablespace in Oracle Database is a powerful but risky operation. Understanding the difference between:

  • INCLUDING CONTENTS

  • AND DATAFILES

  • KEEP DATAFILES

is essential for safe database administration.

Always follow a structured approach: Check → Backup → Drop → Verify to avoid irreversible data loss.


Oracle Backup Strategy for Beginners (Complete Guide with Examples)

 

Oracle Backup Strategy for Beginners (Complete Guide with Examples)

If you're starting your journey as a DBA working with Oracle Database, understanding backups is one of the most critical skills you must develop. A good backup strategy ensures your data is safe from failures, corruption, or human errors.

This guide explains RMAN basics, Full vs Incremental backups, and ARCHIVELOG mode in a clear, practical way.


๐Ÿ“ฆ 1. What is RMAN?

RMAN (Recovery Manager) is Oracle’s built-in backup and recovery tool.

๐Ÿ”‘ Key Features of RMAN:

  • Performs hot (online) backups while database is running

  • Supports incremental backups

  • Automatically tracks backups

  • Validates and detects corruption

  • Works with ARCHIVELOG mode


๐Ÿ› ️ Basic RMAN Commands

Connect to RMAN

rman target /

Take a Full Database Backup

BACKUP DATABASE;

Backup with Format

BACKUP DATABASE FORMAT '/backup/full_%U.bkp';

Backup Control File

BACKUP CURRENT CONTROLFILE;

๐Ÿ’พ 2. Full Backup vs Incremental Backup

Understanding backup types is essential for designing an efficient strategy.


๐Ÿ”ต Full Backup

A Full Backup copies the entire database.

✅ Example

BACKUP DATABASE PLUS ARCHIVELOG;

๐Ÿ“Œ Advantages:

  • Simple to restore

  • Complete snapshot of database

❌ Disadvantages:

  • Takes more time

  • Requires more storage


๐ŸŸก Incremental Backup

An Incremental Backup only backs up changed data blocks.


๐Ÿ”น Level 0 (Base Backup)

BACKUP INCREMENTAL LEVEL 0 DATABASE;

๐Ÿ‘‰ Works like a full backup


๐Ÿ”น Level 1 Incremental

BACKUP INCREMENTAL LEVEL 1 DATABASE;

๐Ÿ‘‰ Backs up only changes since last Level 0 or Level 1


๐Ÿ“Š Types of Incremental Backups:

TypeDescription
DifferentialChanges since last Level 1
CumulativeChanges since last Level 0

๐Ÿ“Œ Advantages:

  • Faster backups

  • Less storage usage

❌ Disadvantages:

  • Restore process is more complex

  • Requires all backup pieces


๐Ÿ”„ Example Strategy

-- Weekly full backup
BACKUP INCREMENTAL LEVEL 0 DATABASE;

-- Daily incremental backup
BACKUP INCREMENTAL LEVEL 1 DATABASE;

๐Ÿ” 3. ARCHIVELOG Mode Explained

๐Ÿ” What is ARCHIVELOG Mode?

In Oracle Database, ARCHIVELOG mode means:

  • All changes in redo logs are archived

  • Enables point-in-time recovery


๐Ÿ”ฅ Why ARCHIVELOG Mode is Important

Without ARCHIVELOG:

  • You can only restore to last backup

  • Data loss is unavoidable

With ARCHIVELOG:

  • You can recover up to the last committed transaction


๐Ÿ”Ž Check ARCHIVELOG Mode

SELECT log_mode FROM v$database;

๐Ÿ”„ Enable ARCHIVELOG Mode

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;

๐Ÿ“ฆ Backup Archive Logs

BACKUP ARCHIVELOG ALL;

Or combined:

BACKUP DATABASE PLUS ARCHIVELOG;

๐Ÿšจ Why Backups Matter (Real Scenarios)

1. ๐Ÿ’ฅ System Crash

Recover database after hardware failure

2. ๐Ÿง‘‍๐Ÿ’ป Accidental Data Deletion

Restore table or database to earlier time

3. ๐Ÿฆ  Data Corruption

Recover corrupted blocks using RMAN

4. ๐Ÿ” Disaster Recovery

Restore database on another server


๐Ÿง  Best Practices for Beginners

✅ Follow 3-2-1 Rule

  • 3 copies of data

  • 2 different storage types

  • 1 offsite backup

✅ Automate Backups

Use cron jobs or scheduler

✅ Validate Backups

RESTORE DATABASE VALIDATE;

✅ Monitor Backup Status

LIST BACKUP;

✅ Delete Old Backups

DELETE OBSOLETE;

๐Ÿงช Sample Beginner Backup Plan

FrequencyBackup Type
DailyLevel 1 Incremental
WeeklyLevel 0 (Full)
HourlyArchive Log Backup

๐Ÿ“Œ Conclusion

A strong backup strategy in Oracle Database revolves around:

  • Using RMAN effectively

  • Combining Full and Incremental backups

  • Enabling ARCHIVELOG mode for complete recovery

Mastering these basics ensures you are prepared for real-world database failures and recovery scenarios.


How to Find the Largest Tables in an Oracle Database ?

 

How to Find the Largest Tables in an Oracle Database

Managing database storage is a critical responsibility for DBAs, especially when working with enterprise systems powered by Oracle Database. Over time, tables can grow significantly, impacting performance, backup time, and maintenance operations.

In this guide, we’ll explore how to identify the largest tables using DBA_SEGMENTS and DBA_TABLES, along with understanding why large tables can affect performance.


๐Ÿ” 1. Using DBA_SEGMENTS to Find Largest Tables

The DBA_SEGMENTS view provides information about storage used by database segments (tables, indexes, etc.).

✅ Query to Find Largest Tables

SELECT 
    owner,
    segment_name AS table_name,
    ROUND(SUM(bytes) / 1024 / 1024, 2) AS size_mb
FROM 
    dba_segments
WHERE 
    segment_type = 'TABLE'
GROUP BY 
    owner, segment_name
ORDER BY 
    size_mb DESC;

๐Ÿ“Œ Explanation

  • segment_type = 'TABLE' → filters only table segments

  • bytes → actual storage used

  • SUM(bytes) → total size of each table

  • Converted into MB for readability

  • Sorted in descending order → largest tables on top

๐Ÿ‘‰ This is the most accurate method because it shows real disk usage.


๐Ÿ” 2. Using DBA_TABLES to Estimate Table Size

The DBA_TABLES view contains metadata about tables, including row counts and block usage.

✅ Query to Estimate Table Size

SELECT 
    owner,
    table_name,
    num_rows,
    blocks,
    ROUND((blocks * 8) / 1024, 2) AS size_mb
FROM 
    dba_tables
WHERE 
    blocks IS NOT NULL
ORDER BY 
    size_mb DESC;

๐Ÿ“Œ Explanation

  • num_rows → approximate number of rows

  • blocks → number of data blocks used

  • Block size assumed as 8KB (default, may vary)

  • Size is estimated, not exact

⚠️ Important:
This method depends on statistics. If stats are outdated, results may be inaccurate.

๐Ÿ‘‰ To refresh statistics:

EXEC DBMS_STATS.GATHER_SCHEMA_STATS('SCHEMA_NAME');

⚖️ DBA_SEGMENTS vs DBA_TABLES

FeatureDBA_SEGMENTSDBA_TABLES
Accuracy✅ Exact storage⚠️ เค…เคจुเคฎाเคจ (estimated)
Includes unused spaceYesNo
Depends on statsNoYes
Best forStorage analysisLogical table analysis

๐Ÿšจ Why Large Tables Impact Performance

Large tables don’t just consume space—they can significantly affect database performance in several ways:

1. ๐Ÿ”„ Slower Full Table Scans

Queries without proper indexes may scan millions of rows, increasing execution time.

2. ๐Ÿ“‰ Index Maintenance Overhead

Indexes on large tables:

  • Take longer to rebuild

  • Increase DML (INSERT/UPDATE/DELETE) cost

3. ๐Ÿ’พ Increased I/O Operations

More data = more disk reads → higher latency.

4. ๐Ÿ•’ Longer Backup and Recovery Time

Large tables:

  • Increase RMAN backup size

  • Slow down restore operations

5. ๐Ÿ” Locking and Concurrency Issues

Heavy operations on large tables can:

  • Cause locking contention

  • Impact multiple users simultaneously

6. ๐Ÿ“Š Statistics and Optimization Challenges

Optimizer may choose inefficient execution plans if:

  • Stats are stale

  • Data distribution is uneven


๐Ÿ› ️ Best Practices for Handling Large Tables

  • ✅ Use partitioning (range, list, hash)

  • ✅ Create proper indexes

  • ✅ Regularly gather statistics

  • ✅ Archive or purge old data

  • ✅ Use compression where applicable

  • ✅ Monitor growth trends


๐Ÿ“Œ Conclusion

Finding large tables is essential for proactive database management. While DBA_SEGMENTS gives you the most accurate storage usage, DBA_TABLES provides useful logical insights when statistics are up-to-date.

Understanding and managing large tables helps improve performance, reduce storage costs, and ensure smoother database operations.


Friday, March 20, 2026

How to Check Default Tablespace of a User in Oracle ?


## ๐Ÿ“˜ What Are Data Dictionary Tables?


In Oracle, **data dictionary tables** are system-owned tables that store metadata about the database.


They contain information such as:


* Users and roles

* Tables and indexes

* Tablespaces

* Privileges and permissions


These tables are owned by the `SYS` user and are accessed through **views** like:


* `DBA_USERS`

* `ALL_USERS`

* `USER_USERS`


๐Ÿ‘‰ Think of them as a **database about your database**.


---


## ๐Ÿ” Query to Check Default Tablespace of a User


The most common way to check a user’s default tablespace is using the `DBA_USERS` view.


### ✅ Basic Query


```sql

SELECT username, default_tablespace

FROM dba_users

WHERE username = 'YOUR_USERNAME';

```


๐Ÿ”น Replace `'YOUR_USERNAME'` with the actual username (in uppercase).


---


### ✅ Example


```sql

SELECT username, default_tablespace

FROM dba_users

WHERE username = 'HR';

```


**Output:**


```

USERNAME   DEFAULT_TABLESPACE

--------   ------------------

HR         USERS

```


---


### ⚠️ Note


* You need **DBA privileges** to query `DBA_USERS`.

* If you don’t have access, use:


```sql

SELECT username, default_tablespace

FROM user_users;

```


or


```sql

SELECT username, default_tablespace

FROM all_users;

```


---


## ๐ŸงŠ What Is Default Tablespace?


A **default tablespace** is the location where a user’s objects are stored if no tablespace is explicitly specified.


### ๐Ÿ“Œ Example:


```sql

CREATE TABLE employees (

  id NUMBER,

  name VARCHAR2(100)

);

```


๐Ÿ‘‰ This table will be created in the user’s **default tablespace**.


---


## ๐Ÿ”„ Temporary Tablespace Explained


A **temporary tablespace** is used for **temporary operations**, such as:


* Sorting data

* Hash joins

* Global temporary tables


---


### ๐Ÿ” Check Temporary Tablespace


```sql

SELECT username, temporary_tablespace

FROM dba_users

WHERE username = 'HR';

```


---


## ⚖️ Default vs Temporary Tablespace


| Feature          | Default Tablespace       | Temporary Tablespace              |

| ---------------- | ------------------------ | --------------------------------- |

| Purpose          | Stores permanent objects | Used for temporary operations     |

| Data Persistence | Permanent                | Temporary (cleared automatically) |

| Example Use      | Tables, indexes          | Sorting, joins                    |

| Storage Type     | Datafiles                | Tempfiles                         |


---


## ๐Ÿง  Key Differences Explained


* **Default Tablespace**


  * Stores actual database objects

  * Data remains until explicitly deleted


* **Temporary Tablespace**


  * Used only during query execution

  * Data disappears after operation completes


---


## ๐Ÿš€ Pro Tips


✔ Always assign a **dedicated default tablespace** for users instead of using `SYSTEM`


✔ Monitor tablespace usage regularly to avoid issues like space exhaustion


✔ Use separate temporary tablespaces for heavy workloads to improve performance


---


## ๐Ÿงพ Conclusion


Understanding default and temporary tablespaces is essential for efficient database management in Oracle. By using simple queries on data dictionary views like `DBA_USERS`, you can quickly identify where user data is stored and how temporary operations are handled.


---


If you want, I can also:


* Add **images/diagrams for your blog**

* Create **SEO title + tags**

* Suggest **related Oracle topics** to grow your blog traffic