From eade344f283d5752e16f4249f384555188afc4c6 Mon Sep 17 00:00:00 2001 From: Marius Date: Sat, 11 Oct 2025 11:05:17 +0300 Subject: [PATCH] Oracle DR: Auto-create PFILE if missing using tested configuration Enhancement to rman_restore_from_zero.ps1: - Auto-generate initROA.ora if not found at service creation - Uses exact tested configuration from initROA.ora: - memory_target=1024M (tested DR VM allocation) - _allow_resetlogs_corruption=TRUE (critical for DR restore!) - control_files in oradata + recovery_area - Standard Oracle 19c parameters for DR environment Benefits: - Script is now fully self-sufficient - No manual PFILE setup required - DR VM can be restored from completely clean state - Uses battle-tested configuration Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- .../rman_restore_from_zero.ps1 | 62 +++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 index 6d68b19..45686f8 100644 --- a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 +++ b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 @@ -91,13 +91,65 @@ if ($service) { } else { Write-Host " Oracle service not found, creating from PFILE..." - if (-not (Test-Path "C:\Users\oracle\admin\ROA\pfile\initROA.ora")) { - Write-Host "ERROR: PFILE not found at C:\Users\oracle\admin\ROA\pfile\initROA.ora" -ForegroundColor Red - Write-Host "Cannot create Oracle service without PFILE!" - exit 1 + # Check if PFILE exists, create if missing + $pfilePath = "C:\Users\oracle\admin\ROA\pfile\initROA.ora" + if (-not (Test-Path $pfilePath)) { + Write-Host " PFILE not found, creating default initROA.ora..." -ForegroundColor Yellow + + # Create directory if needed + $pfileDir = Split-Path $pfilePath -Parent + if (-not (Test-Path $pfileDir)) { + New-Item -ItemType Directory -Path $pfileDir -Force | Out-Null + } + + # Create PFILE with tested configuration + $pfileContent = @" +# Initialization Parameters for ROA Database - DR VM +# Auto-generated by rman_restore_from_zero.ps1 - $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') + +# Database Identification +db_name=ROA +db_unique_name=ROA + +# Memory Configuration +memory_target=1024M +memory_max_target=1024M + +# File Locations +control_files=('C:\Users\oracle\oradata\ROA\control01.ctl', 'C:\Users\oracle\recovery_area\ROA\control02.ctl') +db_recovery_file_dest='C:\Users\oracle\recovery_area' +db_recovery_file_dest_size=20G +audit_file_dest='C:\Users\oracle\admin\ROA\adump' + +# Redo and Archive Log +log_archive_format=%t_%s_%r.dbf + +# Compatibility +compatible=19.0.0 + +# Character Set +nls_language=AMERICAN +nls_territory=AMERICA + +# Processes and Sessions +processes=300 +sessions=472 + +# Miscellaneous +diagnostic_dest='C:\Users\oracle' +_allow_resetlogs_corruption=TRUE +"@ + + try { + $pfileContent | Out-File -FilePath $pfilePath -Encoding ASCII -ErrorAction Stop + Write-Host " [OK] Created PFILE: $pfilePath" -ForegroundColor Green + } catch { + Write-Host "ERROR: Failed to create PFILE: $_" -ForegroundColor Red + exit 1 + } } - & oradim -new -sid ROA -startmode auto -pfile "C:\Users\oracle\admin\ROA\pfile\initROA.ora" 2>&1 | Out-Null + & oradim -new -sid ROA -startmode auto -pfile $pfilePath 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: Failed to create Oracle service" -ForegroundColor Red exit 1