Common Issues and Solutions
Common Issues and Solutions
Section titled “Common Issues and Solutions”This guide provides solutions to frequently encountered Oracle database issues, along with diagnostic steps and preventive measures.
Connection Issues
Section titled “Connection Issues”ORA-12541: TNS no listener
Section titled “ORA-12541: TNS no listener”Problem: The database listener is not running or not reachable.
Solution:
# Check listener statuslsnrctl status
# Start the listenerlsnrctl start
# Check listener configurationcat $ORACLE_HOME/network/admin/listener.ora
# Verify TNS configurationtnsping <database_name>
Prevention:
- Configure listener to start automatically
- Monitor listener status with alerting
- Keep backup of network configuration files
ORA-12154: TNS could not resolve the connect identifier
Section titled “ORA-12154: TNS could not resolve the connect identifier”Problem: The connection string cannot be resolved.
Solution:
# Check tnsnames.ora filecat $ORACLE_HOME/network/admin/tnsnames.ora
# Verify ORACLE_HOME and TNS_ADMINecho $ORACLE_HOMEecho $TNS_ADMIN
# Test connectionsqlplus username/password@tns_alias
# Use Easy Connect if tnsnames.ora is problematicsqlplus username/password@//hostname:port/service_name
ORA-01017: Invalid username/password
Section titled “ORA-01017: Invalid username/password”Problem: Authentication failure.
Solution:
-- Check if account is lockedSELECT username, account_status, lock_dateFROM dba_usersWHERE username = 'YOUR_USER';
-- Unlock accountALTER USER your_user ACCOUNT UNLOCK;
-- Reset passwordALTER USER your_user IDENTIFIED BY new_password;
-- Check password case sensitivitySHOW PARAMETER sec_case_sensitive_logon;
Performance Issues
Section titled “Performance Issues”Slow Query Performance
Section titled “Slow Query Performance”Problem: Queries running slower than expected.
Diagnostic Steps:
-- Get execution planEXPLAIN PLAN FORSELECT * FROM your_table WHERE conditions;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
-- Check for missing indexesSELECT 'CREATE INDEX idx_' || table_name || '_' || column_name || ' ON ' || table_name || '(' || column_name || ');' as index_ddlFROM ( SELECT DISTINCT s.sql_id, p.object_owner as table_owner, p.object_name as table_name, p.filter_predicates FROM v$sql s JOIN v$sql_plan p ON s.sql_id = p.sql_id WHERE p.operation = 'TABLE ACCESS' AND p.options = 'FULL' AND s.executions > 100);
-- Analyze table statisticsBEGIN DBMS_STATS.GATHER_TABLE_STATS( ownname => 'SCHEMA_NAME', tabname => 'TABLE_NAME', cascade => TRUE );END;/
Solutions:
- Add appropriate indexes
- Update table and index statistics
- Rewrite query to use existing indexes
- Consider partitioning for large tables
- Use hints if necessary
High CPU Usage
Section titled “High CPU Usage”Problem: Database consuming excessive CPU resources.
Diagnostic Query:
-- Find top CPU consuming sessionsSELECT s.sid, s.serial#, s.username, s.program, ss.value/100 as cpu_seconds, s.sql_id, sq.sql_textFROM v$session sJOIN v$sesstat ss ON s.sid = ss.sidJOIN v$statname sn ON ss.statistic# = sn.statistic#LEFT JOIN v$sql sq ON s.sql_id = sq.sql_idWHERE sn.name = 'CPU used by this session' AND s.status = 'ACTIVE' AND s.username IS NOT NULLORDER BY ss.value DESCFETCH FIRST 10 ROWS ONLY;
Solutions:
- Optimize high CPU queries
- Add resource manager rules
- Consider parallel query settings
- Review and tune PGA/SGA settings
Space Issues
Section titled “Space Issues”ORA-01653: Unable to extend table
Section titled “ORA-01653: Unable to extend table”Problem: Tablespace is full.
Solution:
-- Check tablespace usageSELECT tablespace_name, ROUND(used_space * 8192 / 1024 / 1024, 2) AS used_mb, ROUND(tablespace_size * 8192 / 1024 / 1024, 2) AS total_mb, ROUND(used_percent, 2) AS used_percentFROM dba_tablespace_usage_metricsORDER BY used_percent DESC;
-- Add datafileALTER TABLESPACE usersADD DATAFILE '/path/to/users02.dbf'SIZE 1G AUTOEXTEND ON NEXT 100M MAXSIZE 10G;
-- Resize existing datafileALTER DATABASE DATAFILE '/path/to/users01.dbf'RESIZE 5G;
-- Enable autoextendALTER DATABASE DATAFILE '/path/to/users01.dbf'AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;
Archive Log Space Full
Section titled “Archive Log Space Full”Problem: Archive destination is full.
Solution:
-- Check archive usageARCHIVE LOG LIST;
-- Check flash recovery area usageSELECT * FROM v$recovery_file_dest;SELECT * FROM v$flash_recovery_area_usage;
-- Delete old archives (after backup!)RMAN> DELETE ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
-- Increase recovery area sizeALTER SYSTEM SET db_recovery_file_dest_size = 50G SCOPE=BOTH;
Lock and Blocking Issues
Section titled “Lock and Blocking Issues”Session Blocking
Section titled “Session Blocking”Problem: Sessions waiting on locks.
Diagnostic Query:
-- Find blocking sessionsSELECT s1.sid || ',' || s1.serial# AS blocker, s1.username AS blocker_user, s2.sid || ',' || s2.serial# AS blocked, s2.username AS blocked_user, s2.seconds_in_wait, s2.event, sq1.sql_text AS blocker_sql, sq2.sql_text AS blocked_sqlFROM v$session s1JOIN v$session s2 ON s1.sid = s2.blocking_sessionLEFT JOIN v$sql sq1 ON s1.sql_id = sq1.sql_idLEFT JOIN v$sql sq2 ON s2.sql_id = sq2.sql_idWHERE s2.blocking_session IS NOT NULL;
-- Kill blocking session (use carefully!)ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
Deadlock Detection
Section titled “Deadlock Detection”Problem: ORA-00060: Deadlock detected.
Solution:
-- Check alert log for deadlock trace fileSELECT value FROM v$diag_info WHERE name = 'Diag Trace';
-- Review trace file for deadlock graph-- Look for "Deadlock graph" section
-- Prevent deadlocks:-- 1. Always access tables in the same order-- 2. Keep transactions short-- 3. Use SELECT FOR UPDATE NOWAITSELECT * FROM table_nameWHERE conditionFOR UPDATE NOWAIT;
Memory Issues
Section titled “Memory Issues”ORA-04031: Unable to allocate shared memory
Section titled “ORA-04031: Unable to allocate shared memory”Problem: Shared pool fragmentation or sizing issue.
Solution:
-- Check shared pool usageSELECT pool, name, ROUND(bytes/1024/1024, 2) as size_mbFROM v$sgastatWHERE pool = 'shared pool'ORDER BY bytes DESCFETCH FIRST 20 ROWS ONLY;
-- Flush shared pool (temporary fix)ALTER SYSTEM FLUSH SHARED_POOL;
-- Increase shared pool sizeALTER SYSTEM SET shared_pool_size = 500M SCOPE=BOTH;
-- Pin frequently used objectsBEGIN DBMS_SHARED_POOL.KEEP('SCHEMA.PACKAGE_NAME', 'P');END;/
PGA Memory Issues
Section titled “PGA Memory Issues”Problem: ORA-04030: Out of process memory.
Solution:
-- Check PGA usageSELECT name, ROUND(value/1024/1024, 2) as value_mbFROM v$pgastatWHERE name IN ( 'aggregate PGA target parameter', 'total PGA allocated', 'total PGA used');
-- Increase PGA targetALTER SYSTEM SET pga_aggregate_target = 2G SCOPE=BOTH;
-- Monitor PGA usage by sessionSELECT sid, username, program, ROUND(pga_used_mem/1024/1024, 2) as pga_used_mb, ROUND(pga_alloc_mem/1024/1024, 2) as pga_alloc_mbFROM v$session sJOIN v$process p ON s.paddr = p.addrWHERE s.username IS NOT NULLORDER BY pga_alloc_mem DESC;
Corruption Issues
Section titled “Corruption Issues”ORA-01578: Oracle data block corrupted
Section titled “ORA-01578: Oracle data block corrupted”Problem: Data block corruption detected.
Solution:
-- Identify corrupted blocksSELECT * FROM v$database_block_corruption;
-- Run RMAN validationRMAN> VALIDATE DATABASE;RMAN> VALIDATE DATAFILE 5;
-- Use RMAN to recover blocksRMAN> RECOVER CORRUPTION LIST;
-- Alternative: Use DBMS_REPAIRBEGIN DBMS_REPAIR.CHECK_OBJECT( schema_name => 'SCHEMA', object_name => 'TABLE_NAME', corrupt_count => :cc );END;/
Startup/Shutdown Issues
Section titled “Startup/Shutdown Issues”Database Won’t Start
Section titled “Database Won’t Start”Common Issues and Solutions:
-- Check alert logtail -f $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace/alert_$ORACLE_SID.log
-- Common startup issues:
-- 1. Control file issuesSTARTUP NOMOUNT;-- Recreate control file from trace
-- 2. Missing datafileSTARTUP MOUNT;ALTER DATABASE DATAFILE '/path/to/file.dbf' OFFLINE DROP;ALTER DATABASE OPEN;
-- 3. Redo log issuesSTARTUP MOUNT;ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 1;
-- 4. Parameter file issuesCREATE PFILE='/tmp/init.ora' FROM SPFILE;-- Edit the pfile to fix issuesSTARTUP PFILE='/tmp/init.ora';CREATE SPFILE FROM PFILE='/tmp/init.ora';
Best Practices for Issue Prevention
Section titled “Best Practices for Issue Prevention”Proactive Monitoring
Section titled “Proactive Monitoring”-- Create monitoring jobBEGIN DBMS_SCHEDULER.CREATE_JOB( job_name => 'DAILY_HEALTH_CHECK', job_type => 'PLSQL_BLOCK', job_action => 'BEGIN check_database_health; END;', start_date => SYSTIMESTAMP, repeat_interval => 'FREQ=DAILY; BYHOUR=6', enabled => TRUE );END;/
Regular Maintenance Tasks
Section titled “Regular Maintenance Tasks”-
Statistics Gathering
EXEC DBMS_STATS.GATHER_DATABASE_STATS(estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE); -
Index Maintenance
-- Rebuild fragmented indexesALTER INDEX index_name REBUILD ONLINE; -
Backup Validation
RMAN> VALIDATE BACKUPSET ALL; -
Space Monitoring
-- Set up tablespace alertsEXEC DBMS_SERVER_ALERT.SET_THRESHOLD(DBMS_SERVER_ALERT.TABLESPACE_PCT_FULL,DBMS_SERVER_ALERT.OPERATOR_GE, 85, 95, 1, 1, NULL,DBMS_SERVER_ALERT.OBJECT_TYPE_TABLESPACE, 'USERS');
Emergency Response Procedures
Section titled “Emergency Response Procedures”Critical Issue Checklist
Section titled “Critical Issue Checklist”-
Assess Impact
- Number of users affected
- Business processes impacted
- Data integrity concerns
-
Gather Information
- Alert log entries
- Recent changes
- Error messages
- System resource usage
-
Immediate Actions
- Notify stakeholders
- Document findings
- Implement temporary workarounds
-
Resolution Steps
- Apply fix in test environment first
- Get approval for production changes
- Implement with rollback plan
- Verify resolution
-
Post-Incident
- Root cause analysis
- Update documentation
- Implement preventive measures
- Share lessons learned