Database File Information by File ID (dfileid.sql)
What This Script Does
Section titled “What This Script Does”The dfileid.sql script retrieves information about Oracle data files using either file ID numbers or filename patterns. It provides essential file properties including tablespace assignment, size, status, and autoextend settings. This script is simpler than dfilef.sql as it focuses only on data files (not temp files) and doesn’t include increment calculations.
The Script
Section titled “The Script”set lines 132
col tablespace_name format a15 heading 'TABLESPACE'col file_id format 9999 heading 'ID'col relative_fno format 9999 heading 'REL|FILE NO'col bytes format 9,999,999,999,999 heading 'BYTES'col blocks format 9,999,999 heading 'BLOCKS'col status format a9 heading 'STATUS'col file_name format a45 heading 'FILE NAME'col autoextensible form a4 heading 'AUTO'
select tablespace_name, file_id, relative_fno, bytes, blocks, status, decode(autoextensible, 'NO', null, autoextensible) autoextensible, file_name from sys.dba_data_files where file_id like nvl('&id','%') and file_name like nvl('&file_name','%') order by tablespace_name, file_id/
Run the script and provide input when prompted:
SQL> @dfileid.sqlEnter value for id: 4Enter value for file_name:
-- Or search by filename patternEnter value for id:Enter value for file_name: %users%
-- Or leave both empty to see all data filesEnter value for id:Enter value for file_name:
Parameters:
id
: File ID number (exact match or % for all)file_name
: Filename pattern (supports SQL wildcards % and _)
Required Privileges
Section titled “Required Privileges”SELECT
privilege onDBA_DATA_FILES
(usually requires DBA role)
Sample Output
Section titled “Sample Output”TABLESPACE ID REL FILE NO BYTES BLOCKS STATUS AUTO FILE NAME--------------- ---- ----------- ----------- -------- --------- ---- ---------------------------------------------SYSTEM 1 1 800,000,000 97,656 AVAILABLE YES /u01/oradata/PROD/system01.dbfSYSAUX 2 2 550,000,000 67,139 AVAILABLE YES /u01/oradata/PROD/sysaux01.dbfUNDOTBS1 3 3 200,000,000 24,414 AVAILABLE YES /u01/oradata/PROD/undotbs01.dbfUSERS 4 4 100,000,000 12,207 AVAILABLE YES /u01/oradata/PROD/users01.dbfUSERS 5 5 50,000,000 6,103 AVAILABLE /u01/oradata/PROD/users02.dbf
Key Output Columns
Section titled “Key Output Columns”- TABLESPACE: Name of the tablespace containing the file
- ID: File ID number (unique across the database)
- REL FILE NO: Relative file number (unique within the tablespace)
- BYTES: Current file size in bytes
- BLOCKS: Number of Oracle blocks in the file
- STATUS: File status (AVAILABLE, OFFLINE, INVALID, etc.)
- AUTO: Autoextend setting (YES or blank for fixed size)
- FILE NAME: Full path and filename
Common Use Cases
Section titled “Common Use Cases”-
File ID Lookup
- Find specific file details by file ID from error messages
- Verify file properties for backup and recovery operations
-
Tablespace File Analysis
- List all files belonging to a specific tablespace
- Analyze file distribution across tablespaces
-
File Status Verification
- Check if files are online and available
- Identify offline or problematic files
-
Size and Growth Analysis
- Review current file sizes
- Identify files with or without autoextend enabled
Understanding File Properties
Section titled “Understanding File Properties”File ID vs Relative File Number
Section titled “File ID vs Relative File Number”- File ID: Unique across entire database
- Relative File Number: Unique within each tablespace
- Both Required: For certain RMAN operations and recovery scenarios
File Status Interpretation
Section titled “File Status Interpretation”- AVAILABLE: File is online and accessible for read/write
- OFFLINE: File is offline (manual intervention required)
- INVALID: File header corruption or inconsistency
- RECOVER: File requires media recovery
Autoextend Behavior
Section titled “Autoextend Behavior”- AUTO = YES: File grows automatically when space needed
- AUTO = blank: Fixed size file (manual resize required)
Query Patterns
Section titled “Query Patterns”Find Specific File
Section titled “Find Specific File”-- By file ID (from error messages)Enter value for id: 4Enter value for file_name:
-- By exact filenameEnter value for id:Enter value for file_name: /u01/oradata/PROD/users01.dbf
Find Files by Pattern
Section titled “Find Files by Pattern”-- All files in a directoryEnter value for id:Enter value for file_name: /u01/oradata/PROD/%
-- All files for a tablespace (by naming convention)Enter value for id:Enter value for file_name: %users%
Administrative Queries
Section titled “Administrative Queries”-- All files (comprehensive view)Enter value for id: %Enter value for file_name: %
-- Range of file IDsEnter value for id: [1-9]Enter value for file_name:
Performance Analysis
Section titled “Performance Analysis”File Size Considerations
Section titled “File Size Considerations”- Large Files (>10GB): May impact backup/recovery times
- Many Small Files: Could indicate fragmentation issues
- Uneven Sizes: May suggest manual intervention needed
File Distribution
Section titled “File Distribution”- Single Tablespace/Multiple Files: Good for I/O parallelism
- One File/Tablespace: May limit performance scalability
- File System Spread: Important for I/O distribution
Troubleshooting Guide
Section titled “Troubleshooting Guide”File-Related Errors
Section titled “File-Related Errors”Oracle error messages often include file IDs:
ORA-01110: data file 4: '/u01/oradata/PROD/users01.dbf'
Use this script to get complete file details for the specified file ID.
File Status Issues
Section titled “File Status Issues”- OFFLINE: Use
ALTER DATABASE DATAFILE n ONLINE;
- INVALID: May require media recovery
- Missing Files: Check file system and restore if necessary
Autoextend Problems
Section titled “Autoextend Problems”- No AUTO setting: File may fill up causing errors
- AUTO without maxsize: File could consume all disk space
- Filesystem full: Autoextend fails silently
Related Scripts
Section titled “Related Scripts”- dfilef.sql - File information with filename search and temp files
- dtspace.sql - Tablespace usage with file details
- vdbfile.sql - Database file overview
Script Features
Section titled “Script Features”- Dual Parameter Support: Search by file ID or filename pattern
- Clean Output: Focused on essential file properties
- Data Files Only: Simplified view excluding temp files
- Wildcard Support: Flexible pattern matching for both parameters
Best Practices
Section titled “Best Practices”- File ID Documentation: Maintain mapping of file IDs to business functions
- Regular Monitoring: Check file status and growth regularly
- Standardized Naming: Use consistent file naming conventions
- Autoextend Settings: Configure appropriate autoextend parameters
Comparison with Related Scripts
Section titled “Comparison with Related Scripts”vs. dfilef.sql
Section titled “vs. dfilef.sql”- dfileid.sql: Simpler, data files only, file ID search capability
- dfilef.sql: More comprehensive, includes temp files, increment calculations
vs. dtspace.sql
Section titled “vs. dtspace.sql”- dfileid.sql: File-focused view with detailed file properties
- dtspace.sql: Tablespace-focused view with space utilization
Common Error Scenarios
Section titled “Common Error Scenarios”File Not Found in Output
Section titled “File Not Found in Output”- Check file ID range: Ensure file ID exists in database
- Verify filename pattern: Check spelling and wildcards
- Temp files: This script only shows data files, not temp files
Permission Issues
Section titled “Permission Issues”- Ensure user has SELECT privilege on DBA_DATA_FILES
- Consider using ALL_DATA_FILES for limited access environments
- May need specific grants for data file views
Limitations
Section titled “Limitations”- Data files only (use dfilef.sql for temp files)
- No historical information (current status only)
- No file system validation (shows data dictionary information only)
- No redo log files (use V$LOGFILE for redo log information)