Compare commits

...

3 Commits

Author SHA1 Message Date
Marius
5af33fc217 Oracle DR: Add SHUTDOWN ABORT before NOMOUNT to clean auto-started instance
Critical fix for service auto-start behavior:

Problem (identified by user):
- When Oracle service starts, it automatically tries to start instance
- Uses configured PFILE which references control files
- After cleanup, control files don't exist
- Instance ends up in partial/error state
- STARTUP NOMOUNT may fail or behave unexpectedly

Root Cause:
- Oracle service on Windows has auto-start behavior
- Service startup takes ~30s trying to start instance
- Without valid control files, instance is partially started
- This interferes with manual STARTUP NOMOUNT

Solution:
Before STARTUP NOMOUNT, explicitly clean any existing instance:
```sql
SHUTDOWN ABORT;  -- Clean any partial instance
STARTUP NOMOUNT PFILE='...';  -- Fresh clean start
```

Implementation:
- Use WHENEVER SQLERROR CONTINUE (SHUTDOWN may error if no instance)
- Explicit SHUTDOWN ABORT before NOMOUNT
- Ensures clean instance state for RMAN restore
- Service running + clean NOMOUNT instance = ready for restore

User requirement met: Instance in NOMOUNT state (not mounted/open)

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2025-10-11 15:18:45 +03:00
Marius
4b7bb29b9e Oracle DR: Fix service start with polling and timeout (not blocking)
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>
2025-10-11 15:14:24 +03:00
Marius
e4df4c11d8 Oracle DR: Fix service start hang - don't start stopped service
Critical fix for service preservation:

Problem:
- After cleanup, Oracle service is stopped
- Start-Service attempts to start the instance automatically
- Without database files, service startup hangs indefinitely
- PowerShell Start-Service blocks waiting for service to start

Root Cause:
- Oracle service on Windows tries to auto-start the instance
- With no controlfile/database files, it cannot start
- Start-Service waits forever (user reported 25+ warnings)

Solution:
- Do NOT attempt to start the stopped service
- SQL*Plus can connect '/ as sysdba' even if service is stopped
- STARTUP NOMOUNT will manually start the instance
- This is the correct Oracle workflow for restore from zero

Windows SQL*Plus requirements:
✓ ORACLE_SID set (we set this)
✓ Service exists in registry (preserved after cleanup)
✓ ORACLE_HOME set (we set this)
✗ Service running NOT required for NOMOUNT startup

The service will naturally transition to Running state when
STARTUP NOMOUNT successfully starts the instance.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2025-10-11 15:12:21 +03:00

View File

@@ -88,6 +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"
# 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..."
@@ -160,6 +205,19 @@ _allow_resetlogs_corruption=TRUE
# Step 2.2: Startup NOMOUNT
Write-Host "[2.2] Starting database in NOMOUNT mode..."
# First, ensure any partially started instance is shut down
# (Service auto-start may have started instance in error state without control files)
Write-Host " Ensuring clean state - shutting down any existing instance..."
$cleanupSQL = @"
WHENEVER SQLERROR CONTINUE
SHUTDOWN ABORT;
EXIT;
"@
$cleanupSQL | & sqlplus -S / as sysdba 2>&1 | Out-Null
# Now start cleanly in NOMOUNT
Write-Host " Starting fresh instance in NOMOUNT mode..."
$nomountSQL = @"
STARTUP NOMOUNT PFILE='C:\Users\oracle\admin\ROA\pfile\initROA.ora';
EXIT;