BIT352 Database Administration

Database AdministrationUnit 1111 min read

Oracle Initialization Parameters, Profiles & Database Tuning

Unit 11 of Database Administration explores Oracle’s initialization parameters (PFILE/SPFILE), resource profiles, and database tuning—how to configure memory, processes, and performance limits via init.ora/spfile, manage user resource quotas, and optimize system behavior for real-world workloads like Ncell’s billing sy

TAKEAWAYS:

  • Oracle uses two parameter files (PFILE for static, SPFILE for dynamic) to store startup settings like memory allocation, process limits, and undo retention.
  • Resource profiles enforce CPU, session, and parallel query limits per user—critical for multi-tenant databases like Khalti’s payment processing.
  • Key parameters (MEMORY_TARGET, PROCESSES, UNDO_RETENTION) directly impact performance; misconfigurations cause timeouts or crashes.
  • Profiles let admins restrict users (e.g., Daraz’s order-entry clerks) to prevent runaway queries or DDoS-like resource exhaustion.
  • Worked example: Tuning DB_BLOCK_SIZE for NTC’s call-center database to reduce I/O bottlenecks during peak hours.
  • Exam focus: Compare PFILE vs. SPFILE, explain ALTER SYSTEM SET syntax, and trace how a profile limits a user’s concurrent sessions.

1. Oracle Initialization Parameters: The Control Panel of Your Database

Oracle’s initialization parameters are configuration settings stored in files that define how the database starts, allocates resources, and behaves. Think of them as the operating system settings for your Oracle instance—just like how Windows uses registry or Linux uses /etc/sysctl.conf.

08162431db_block_size16 bitsmemory_target16 bitsprocesses16 bitsundo_retention16 bits
Key Oracle initialization parameters and their typical values for a high-concurrency system like NEPSE’s trading database.

1.1 Two Types of Parameter Files

Oracle supports two formats for storing these parameters:

classDiagram
    class ParameterFile {
        +Static (PFILE) init.ora
        +Dynamic (SPFILE) spfile.ora
        +Stored in $ORACLE_HOME/dbs/
    }
    class PFILE {
        +Text-based
        +Requires restart to change
        +Example: initORCL.ora
    }
    class SPFILE {
        +Binary format
        +Dynamic changes via ALTER SYSTEM
        +Example: spfileORCL.ora
    }
    ParameterFile <|-- PFILE
    ParameterFile <|-- SPFILE

Key Differences:

Feature PFILE (init.ora) SPFILE (spfile.ora)
Format Plain text Binary
Modification Requires restart Dynamic via ALTER SYSTEM
Use Case Legacy systems, testing Production (recommended)
Example memory_target=4G Same, but edited via SQL*Plus

1.2 How Parameters Work: The init.ora File

A typical init.ora (or spfile) contains lines like:

# Memory settings
db_block_size=8192
memory_target=4G
sga_target=3G

# Process limits
processes=300
sessions=500

# Undo/Redo
undo_retention=900
undo_tablespace=UNDOTBS1
  • db_block_size: Defines the size of data blocks (e.g., 8KB). Larger blocks reduce I/O but increase memory usage.
  • memory_target: Automatically allocates SGA (Shared Global Area) and PGA (Program Global Area) memory.
  • processes: Maximum OS processes Oracle can spawn (critical for high-concurrency apps like Pathao’s ride-matching).

Worked Example: Tuning for NEPSE’s Stock Database NEPSE’s trading system processes 10,000 transactions/sec during peak hours. To prevent timeouts:

  1. Set processes=1000 (default is 150, which is insufficient).
  2. Increase undo_retention=1800 (seconds) to support long-running rollbacks.
  3. Use ALTER SYSTEM SET memory_target=16G SCOPE=SPFILE to allocate more SGA for query caching.

2. Profiles: Enforcing Resource Limits

Profiles are resource quotas applied to database users or roles. They prevent:

  • A single user from consuming all CPU (e.g., a rogue Daraz admin running SELECT * FROM orders without a WHERE clause).
  • Unlimited sessions (e.g., a hacker spawning 1000 connections to crash the system).
sequenceDiagram
    participant User as Order Clerk
    participant Oracle as Oracle Database
    participant Profile as Daraz Clerk Profile
    User->>Oracle: CONNECT (user_id=order_clerk)
    Oracle->>Profile: Check sessions_per_user (5)
    Profile-->>Oracle: Allow (3/5 sessions used)
    Oracle->>User: Session granted
    loop During peak hours
        User->>Oracle: SELECT * FROM orders
        Oracle->>Profile: Check CPU_PER_SESSION (300s)
        Profile-->>Oracle: Reject (CPU limit exceeded)
        Oracle->>User: ORA-02391: Exceeded resource limit
    end
How Daraz’s order clerks are restricted by CPU and session limits in their profile.

2.1 Profile Components

A profile defines limits for:

  • CPU_PER_SESSION: Max CPU time per session (in hundredths of a second).
  • SESSIONS_PER_USER: Max concurrent sessions.
  • LOGICAL_READS_PER_SESSION: Max disk reads per session.
  • CONNECT_TIME: Max session duration.

Example Profile for Daraz’s Order Clerks:

CREATE PROFILE daraz_clerk_profile
  LIMIT
    sessions_per_user 5
    cpu_per_session 30000  -- 300 seconds (5 minutes)
    connect_time 1800;      -- 30 minutes

Mermaid Diagram: Profile Enforcement Flow

sequenceDiagram
    participant User
    participant Oracle
    participant Profile
    User->>Oracle: CONNECT (user_id=123)
    Oracle->>Profile: Check limits
    Profile-->>Oracle: Allow (sessions=3/5)
    Oracle->>User: Session granted
    loop Every 5 minutes
        User->>Oracle: Query orders
        Oracle->>Profile: Check CPU usage
        Profile-->>Oracle: Reject (CPU limit exceeded)
        Oracle->>User: ORA-02391: exceeded resource limit
    end

2.2 Assigning Profiles to Users

ALTER USER order_clerk
  PROFILE daraz_clerk_profile;

Verification:

SELECT username, profile, resource_name, limit
FROM dba_profiles
WHERE username = 'ORDER_CLERK';

3. Key Initialization Parameters for Exams

Focus on these high-impact parameters (likely to appear in exams):

Parameter Purpose Example Value
db_block_size Size of data blocks (affects I/O and memory). 8192 (8KB)
memory_target Total SGA + PGA memory (auto-tuned). 4G
processes Max OS processes Oracle can use. 300
undo_retention How long undo data is kept for rollback. 900 (15 minutes)
open_cursors Max open cursors per session (prevents "too many open cursors" errors). 300
remote_login_passwordfile Enables password file for remote DB links. EXCLUSIVE

Exam Tip: Memorize the default values for these parameters (e.g., processes=150, open_cursors=50).


In the Real World

  1. Ncell’s Billing System

    • Parameter Used: undo_retention=3600 (1 hour)
    • Why? Ncell’s billing database processes millions of call records/day. A high undo_retention ensures rollbacks (e.g., for fraud detection) don’t fail due to expired undo segments.
  2. Khalti’s Payment Gateway

    • Parameter Used: processes=2000, sessions=5000
    • Why? During Diwali sales, Khalti handles 10,000 transactions/minute. The high processes limit prevents "too many sessions" errors, while memory_target=32G caches frequent payment queries.
  3. NTC’s Call Center Database

    • Profile Used: CPU_PER_SESSION=10000 (2 minutes), LOGICAL_READS_PER_SESSION=100000
    • Why? Agents run reports like SELECT * FROM customer_calls WHERE date='2023-10-01'. The profile prevents any single agent from locking the database with a full-table scan.

4. Dynamic vs. Static Parameters

Not all parameters can be changed without a restart. Oracle classifies them as:

Type Description Example Parameters
Static Require database restart to take effect. db_block_size, db_name
Dynamic Can be changed via ALTER SYSTEM SET without restart. memory_target, undo_retention

Example: Changing undo_retention Dynamically

-- Check current value
SHOW PARAMETER undo_retention;

-- Change dynamically
ALTER SYSTEM SET undo_retention=1800 SCOPE=SPFILE;

5. Common Pitfalls and Fixes

Issue Cause Solution
ORA-00020: maximum number of processes exceeded processes limit too low Increase processes or kill idle sessions.
ORA-01555: snapshot too old undo_retention too low Increase undo_retention or optimize queries.
ORA-02391: exceeded resource limit Profile limits hit Check USER_RESOURCE_LIMITS and adjust profile.
Database hangs during peak hours memory_target too low Increase SGA/PGA via ALTER SYSTEM.
10,000 TPS300 (default processes limit)4G (memory_target)NEPSE DBOracle InstanceOS ProcessesMemory Pool
Bottleneck in NEPSE’s stock database: Default `processes=150` vs. required `processes=1000` for 10,000 transactions/sec.

Exam Tip

  1. Parameter File Questions:

    • Always compare PFILE vs. SPFILE in tables (as above).
    • Know the command to create a SPFILE from PFILE:
      CREATE SPFILE FROM PFILE='/u01/app/oracle/product/19c/dbs/initORCL.ora';
      
  2. Profiles:

    • Expect questions on creating profiles, assigning them to users, and querying limits (USER_RESOURCE_LIMITS).
    • Worked Example: If a user hits ORA-02391, trace it to a profile limit and suggest:
      ALTER PROFILE clerk_profile LIMIT sessions_per_user 10;
      
  3. Tuning Scenarios:

    • For high-concurrency apps (e.g., Pathao), focus on processes, sessions, and undo_retention.
    • For CPU-heavy workloads (e.g., NEPSE’s analytics), adjust CPU_PER_SESSION in profiles.
  4. Syntax Must-Knows:

    • ALTER SYSTEM SET parameter=value SCOPE=SPFILE/SID;
    • CREATE PROFILE profile_name LIMIT resource_name=limit;
    • ALTER USER user_name PROFILE profile_name;

In the real world

  • Ncell’s Billing System: Uses undo_retention=3600 (1 hour) to ensure rollbacks for fraud detection don’t fail when processing millions of call records/day. Without this, expired undo segments would cause ORA-01555 errors during high-volume audits.
  • Khalti’s Payment Gateway: Dynamically adjusts processes=2000 and memory_target=32G during Diwali sales to handle 10,000 transactions/minute, preventing "too many sessions" errors (ORA-00020).
  • NTC’s Call Center Database: Applies a profile with CPU_PER_SESSION=10000 (2 minutes) to agents to prevent runaway queries (e.g., SELECT * FROM calls) from crashing the system during peak hours (10 AM–6 PM).

Based on the TU BIT syllabus for Database Administration (BIT352), unit 11.

Discussion

Loading…