diff --git a/proxmox/lxc108-oracle/roa-windows-setup/config.example.ps1 b/proxmox/lxc108-oracle/roa-windows-setup/config.example.ps1 index d567d49..0a9dfe0 100644 --- a/proxmox/lxc108-oracle/roa-windows-setup/config.example.ps1 +++ b/proxmox/lxc108-oracle/roa-windows-setup/config.example.ps1 @@ -37,5 +37,13 @@ $COMPANY_PASSWORD = "ROMFASTSOFT" # Directory for DMP files (Data Pump import/export) $DMPDIR = "C:\DMPDIR" +# Datafile directory for tablespace ROA +# Auto-detected from database if not set. Set this if auto-detection fails. +# Common paths: +# XE 21c: C:\app\\product\21c\oradata\XE\XEPDB1 +# SE 21c: C:\app\\oradata\ROA +# To find actual path: SELECT file_name FROM dba_data_files WHERE ROWNUM = 1; +$DATAFILE_DIR = $null # e.g., "C:\app\romfast\product\21c\oradata\XE\XEPDB1" + # ROAUPDATE base path (for automatic updates module) $ROAUPDATE_BASE_PATH = "D:\ROAUPDATE" diff --git a/proxmox/lxc108-oracle/roa-windows-setup/scripts/lib/oracle-functions.ps1 b/proxmox/lxc108-oracle/roa-windows-setup/scripts/lib/oracle-functions.ps1 index 41d25f6..c9cae59 100644 --- a/proxmox/lxc108-oracle/roa-windows-setup/scripts/lib/oracle-functions.ps1 +++ b/proxmox/lxc108-oracle/roa-windows-setup/scripts/lib/oracle-functions.ps1 @@ -697,57 +697,61 @@ function New-OracleDirectory { Write-Log "Created directory: $DirectoryPath" } - # Check if directory already exists with different path - if so, drop it first + # Always drop and recreate directory to ensure correct path # This fixes Oracle XE issue where DMPDIR may point to wrong default location - $checkSql = @" -SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF LINESIZE 500 -SELECT directory_path FROM dba_directories WHERE directory_name = '$DirectoryName'; -EXIT; -"@ - - $existingPath = Invoke-SqlPlus -OracleHome $OracleHome -ServiceName $ServiceName ` - -Username "SYS" -Password $Password -SqlCommand $checkSql -AsSysdba -Silent - - $existingPath = ($existingPath -split "`n" | Where-Object { $_.Trim() -ne "" } | Select-Object -First 1) - if ($existingPath) { - $existingPath = $existingPath.Trim() - } - - # Normalize paths for comparison (case-insensitive, handle trailing slashes) - $normalizedExisting = if ($existingPath) { $existingPath.TrimEnd('\').ToUpper() } else { "" } - $normalizedTarget = $DirectoryPath.TrimEnd('\').ToUpper() - - if ($existingPath -and $normalizedExisting -ne $normalizedTarget) { - Write-Log "Directory $DirectoryName exists with different path: $existingPath" - Write-Log "Dropping and recreating with correct path: $DirectoryPath" - - $dropSql = @" -SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF -DROP DIRECTORY $DirectoryName; -EXIT; -"@ - Invoke-SqlPlus -OracleHome $OracleHome -ServiceName $ServiceName ` - -Username "SYS" -Password $Password -SqlCommand $dropSql -AsSysdba -Silent | Out-Null - } - + # Using DROP + CREATE instead of CREATE OR REPLACE for reliability $sql = @" -SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF +SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF LINESIZE 500 +-- Check current directory path +VARIABLE v_path VARCHAR2(500); +VARIABLE v_exists NUMBER; +BEGIN + SELECT COUNT(*), MAX(directory_path) INTO :v_exists, :v_path + FROM dba_directories WHERE directory_name = '$DirectoryName'; +END; +/ +PRINT v_path + +-- Drop if exists with different path +BEGIN + IF :v_exists > 0 AND UPPER(TRIM(:v_path)) != UPPER('$DirectoryPath') THEN + EXECUTE IMMEDIATE 'DROP DIRECTORY $DirectoryName'; + DBMS_OUTPUT.PUT_LINE('DROPPED_DIFFERENT_PATH'); + ELSIF :v_exists > 0 THEN + DBMS_OUTPUT.PUT_LINE('PATH_ALREADY_CORRECT'); + END IF; +EXCEPTION + WHEN OTHERS THEN NULL; +END; +/ + +-- Create or replace directory CREATE OR REPLACE DIRECTORY $DirectoryName AS '$DirectoryPath'; GRANT READ, WRITE ON DIRECTORY $DirectoryName TO PUBLIC; -COMMIT; -SELECT 'DIRECTORY_CREATED' FROM dual; + +-- Verify +SELECT 'VERIFIED:' || directory_path FROM dba_directories WHERE directory_name = '$DirectoryName'; EXIT; "@ $result = Invoke-SqlPlus -OracleHome $OracleHome -ServiceName $ServiceName ` -Username "SYS" -Password $Password -SqlCommand $sql -AsSysdba -Silent - if ($result -match "DIRECTORY_CREATED") { - Write-Log "Oracle directory $DirectoryName created pointing to $DirectoryPath" - return $true + # Check verification result + if ($result -match "VERIFIED:(.+)") { + $verifiedPath = $Matches[1].Trim() + if ($verifiedPath.ToUpper() -eq $DirectoryPath.ToUpper()) { + Write-Log "Oracle directory $DirectoryName created pointing to $DirectoryPath" + return $true + } + else { + Write-LogWarning "Directory path mismatch! Expected: $DirectoryPath, Got: $verifiedPath" + return $false + } } else { Write-LogWarning "Could not verify directory creation" + Write-LogWarning "SQL output: $result" return $false } } @@ -810,19 +814,44 @@ EXIT; } } - # Fallback to common paths based on Oracle Home + # Fallback: derive path from ORACLE_HOME + # Example: C:\app\romfast\product\21c\dbhomeXE -> C:\app\romfast\product\21c\oradata\XE\XEPDB1 + Write-LogWarning "Could not query datafile path from database, using fallback based on ORACLE_HOME" + $version = Get-OracleVersion -OracleHome $oraHome -ServiceName $ServiceName -Password $Password - if ($version.IsXE) { - if ($version.Version -match "^21") { - return "C:\app\oracle\oradata\XE\XEPDB1" - } - elseif ($version.Version -match "^18") { - return "C:\app\oracle\oradata\XE" + # Try to derive oradata path from ORACLE_HOME + # Pattern: \product\\dbhomeXE -> \product\\oradata\XE\ + if ($oraHome -match "^(.+\\product\\[^\\]+)\\dbhome") { + $baseOradata = "$($Matches[1])\oradata" + if ($version.IsXE) { + if ($version.Version -match "^21") { + return "$baseOradata\XE\XEPDB1" + } + elseif ($version.Version -match "^18") { + return "$baseOradata\XE" + } } + return $baseOradata } - # Default fallback + # Legacy fallback for non-standard installations + # Extract base from ORACLE_HOME (e.g., C:\app\romfast from C:\app\romfast\product\21c\dbhomeXE) + if ($oraHome -match "^([A-Z]:\\[^\\]+\\[^\\]+)\\") { + $appBase = $Matches[1] + if ($version.IsXE) { + if ($version.Version -match "^21") { + return "$appBase\oradata\XE\XEPDB1" + } + elseif ($version.Version -match "^18") { + return "$appBase\oradata\XE" + } + } + return "$appBase\oradata" + } + + # Ultimate fallback - this should rarely be reached + Write-LogWarning "Could not derive datafile path from ORACLE_HOME, using hardcoded default" return "C:\app\oracle\oradata" } diff --git a/proxmox/lxc108-oracle/roa-windows-setup/sql/grants-public.sql b/proxmox/lxc108-oracle/roa-windows-setup/sql/grants-public.sql index 8578714..44c19d5 100644 --- a/proxmox/lxc108-oracle/roa-windows-setup/sql/grants-public.sql +++ b/proxmox/lxc108-oracle/roa-windows-setup/sql/grants-public.sql @@ -274,12 +274,22 @@ GRANT SELECT ON CONTAFIN_ORACLE.VDEF_PROGRAME_SERII TO CONTAFIN_ORACLE; PROMPT [8/9] Granting directory and system permissions... --- Create DMPDIR directory if it doesn't exist (adjust path as needed) +-- DMPDIR directory should already exist (created by 01-setup-database.ps1) +-- Only grant permissions here - don't override the path +-- If DMPDIR doesn't exist, create with standard path C:\DMPDIR +DECLARE + v_count NUMBER; BEGIN - EXECUTE IMMEDIATE 'CREATE OR REPLACE DIRECTORY DMPDIR AS ''D:\Oracle\admin\ORCL\dpdump'''; + SELECT COUNT(*) INTO v_count FROM dba_directories WHERE directory_name = 'DMPDIR'; + IF v_count = 0 THEN + EXECUTE IMMEDIATE 'CREATE DIRECTORY DMPDIR AS ''C:\DMPDIR'''; + DBMS_OUTPUT.PUT_LINE(' Created DMPDIR directory (C:\DMPDIR)'); + ELSE + DBMS_OUTPUT.PUT_LINE(' DMPDIR directory already exists - preserving existing path'); + END IF; EXCEPTION WHEN OTHERS THEN - DBMS_OUTPUT.PUT_LINE('Note: DMPDIR directory may already exist or path needs adjustment'); + DBMS_OUTPUT.PUT_LINE('Note: DMPDIR ' || SQLERRM); END; /