From 4b7bb29b9e1c60be23c787d26623bf9bbc991adc Mon Sep 17 00:00:00 2001 From: Marius Date: Sat, 11 Oct 2025 15:14:24 +0300 Subject: [PATCH] Oracle DR: Fix service start with polling and timeout (not blocking) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Critical fix - service MUST be running for SQL*Plus connection: Problem (confirmed by user): - After cleanup, service is stopped - sqlplus / as sysdba → ORA-12560: TNS:protocol adapter error - Start-Service blocks indefinitely (user saw 25+ warnings) - Service takes ~30 seconds to start Previous attempt (WRONG): - Assumed SQL*Plus works with stopped service ✗ - User proved ORA-12560 occurs when service stopped ✓ Correct Solution: - Start service in background job (non-blocking) - Poll service status every 3 seconds - Timeout after 60 seconds (2x expected startup time) - Progress logging every 15 seconds - Cleanup background job when done Implementation: ```powershell Start-Job { Start-Service OracleServiceROA } while (elapsed < 60s) { if (service.Status == Running) → break sleep 3s } ``` Result: - Service starts in ~30s (user confirmed) - Script doesn't block - SQL*Plus can connect successfully - Graceful fallback if timeout exceeded Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- .../rman_restore_from_zero.ps1 | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 index f89808f..19b379e 100644 --- a/oracle/standby-server-scripts/rman_restore_from_zero.ps1 +++ b/oracle/standby-server-scripts/rman_restore_from_zero.ps1 @@ -88,7 +88,51 @@ $service = Get-Service -Name "OracleServiceROA" -ErrorAction SilentlyContinue if ($service) { Write-Host "[OK] Oracle service already exists, skipping creation (15s saved!)" -ForegroundColor Green Write-Host " Service will be reused for this restore" - Write-Host " Note: Service status is $($service.Status) (OK - will be started by NOMOUNT)" + + # Ensure service is running (required for SQL*Plus connection) + if ($service.Status -ne "Running") { + Write-Host " Service is stopped, starting it (may take 30-60 seconds)..." + + # Start service in background job to avoid blocking + $startJob = Start-Job -ScriptBlock { + Start-Service -Name "OracleServiceROA" -ErrorAction SilentlyContinue + } + + # Poll for service status with timeout + $maxWait = 60 + $elapsed = 0 + $pollInterval = 3 + $serviceStarted = $false + + while ($elapsed -lt $maxWait) { + Start-Sleep -Seconds $pollInterval + $elapsed += $pollInterval + + # Refresh service status + $currentService = Get-Service -Name "OracleServiceROA" -ErrorAction SilentlyContinue + if ($currentService -and $currentService.Status -eq "Running") { + $serviceStarted = $true + Write-Host " [OK] Service started successfully after $elapsed seconds" + break + } + + if ($elapsed % 15 -eq 0) { + Write-Host " Still waiting for service to start... ($elapsed/$maxWait seconds)" + } + } + + # Cleanup background job + Stop-Job -Job $startJob -ErrorAction SilentlyContinue + Remove-Job -Job $startJob -ErrorAction SilentlyContinue + + if (-not $serviceStarted) { + Write-Host " WARNING: Service did not start within $maxWait seconds" -ForegroundColor Yellow + Write-Host " This may cause SQL*Plus connection issues (ORA-12560)" + Write-Host " Attempting to continue anyway..." + } + } else { + Write-Host " Service is already running" + } } else { Write-Host " Oracle service not found, creating from PFILE..."