Skip to Content

PROBLEM IDENTIFIED: Installer Reused Old PostgreSQL Data

PROBLEM IDENTIFIED: Installer Reused Old PostgreSQL Data

Root Cause

The new installer DID include all our fixes in post_install.ps1 (confirmed by grep showing "CRITICAL FIX 2025-11-25").

BUT - the installer logic at line 106:

if (-not (Test-Path $pgData)) {
    # Initialize Database Cluster with --lc-collate=C --lc-ctype=C
}

Only runs initdb if data directory doesn't exist. Since your old PostgreSQL data from August 30 still existed, it:
- ❌ Skipped initdb (no new cluster initialization)
- ❌ Reused old cluster with lc_ctype = English_Australia.1252
- ❌ Database inherited wrong locale from old cluster

Evidence

PostgreSQL configuration files:
- postgresql.conf: Aug 30 07:31 (OLD!)
- pg_hba.conf: Aug 30 07:31 (OLD!)
- PG_VERSION: Aug 30 07:31 (OLD!)

Current cluster locale:

lc_ctype = English_Australia.1252  ❌

The Fix

  1. Stop SAM AI service:
    powershell Stop-Service "SAMAI-Odoo" -Force

  2. Stop PostgreSQL:
    powershell & "C:\Program Files\SAM AI\postgresql\bin\pg_ctl.exe" stop -D "C:\Program Files\SAM AI\postgresql\data"

  3. Delete old data directory:
    powershell Remove-Item "C:\Program Files\SAM AI\postgresql\data" -Recurse -Force

  4. Re-run post_install.ps1:
    powershell cd "C:\Program Files\SAM AI\scripts" .\post_install.ps1 -InstallDir "C:\Program Files\SAM AI" -DatabaseName "sam_ai" -OdooPort 8069 -PostgreSQLPort 5432 -UseExistingPostgreSQL "false" -UseExistingDatabase "false"

  5. Validate locale (should now be C/C):
    powershell powershell -ExecutionPolicy Bypass -File "C:\Users\total\check_locale.ps1"

Option 2: Complete Uninstall/Reinstall

  1. Uninstall SAM AI via Windows Settings
  2. Delete PostgreSQL data before reinstalling:
    powershell Remove-Item "C:\Program Files\SAM AI\postgresql\data" -Recurse -Force
  3. Run new installer
  4. Validate locale

Why This Happened

Your development workflow:
1. You've been testing installations repeatedly
2. Uninstaller doesn't delete PostgreSQL data (by design, to preserve databases)
3. Each new install reuses existing data directory
4. New initdb flags never executed because data directory already exists

Permanent Fix for Installer

Update post_install.ps1 to force reinitialize if locale is wrong:

# Check if data directory exists
if (Test-Path $pgData) {
    # Validate existing cluster locale
    $env:PGPASSWORD = "postgres"
    $lcCtype = & "$pgPath\bin\psql.exe" -U postgres -d postgres -t -c "SHOW lc_ctype;" 2>&1
    Remove-Item Env:\PGPASSWORD -ErrorAction SilentlyContinue

    if ($lcCtype -notmatch "^\s*C\s*$") {
        Log-Warning "4.2" "Existing PostgreSQL cluster has wrong locale: $($lcCtype.Trim())"
        Log-Warning "4.2" "Deleting and reinitializing with correct locale..."

        # Stop PostgreSQL if running
        & "$pgPath\bin\pg_ctl.exe" stop -D "$pgData" -m fast 2>&1 | Out-Null

        # Delete old data
        Remove-Item $pgData -Recurse -Force
    }
}

# Now initialize if needed
if (-not (Test-Path $pgData)) {
    # Run initdb with --lc-collate=C --lc-ctype=C
    ...
}

This would:
- ✅ Check existing cluster locale
- ✅ Delete and reinitialize if wrong locale detected
- ✅ Guarantee correct locale on every installation


Quick Test Now

Run this to fix your current installation:

# Stop services
Stop-Service "SAMAI-Odoo" -Force
& "C:\Program Files\SAM AI\postgresql\bin\pg_ctl.exe" stop -D "C:\Program Files\SAM AI\postgresql\data" -m fast

# Delete old data
Remove-Item "C:\Program Files\SAM AI\postgresql\data" -Recurse -Force

# Re-run installer script
cd "C:\Program Files\SAM AI\scripts"
.\post_install.ps1 -InstallDir "C:\Program Files\SAM AI" -DatabaseName "sam_ai" -OdooPort 8069 -PostgreSQLPort 5432 -UseExistingPostgreSQL "false" -UseExistingDatabase "false"

# Validate
powershell -ExecutionPolicy Bypass -File "C:\Users\total\check_locale.ps1"

Expected result:

datname | datcollate | datctype
--------+------------+----------
sam_ai  | C          | C         ✅
Was this helpful?