mirror of
https://git.coastit.co.za/caitlin/CRM_ENVR.git
synced 2026-07-10 11:15:43 +02:00
26 lines
965 B
PowerShell
26 lines
965 B
PowerShell
$pgDir = "$env:TEMP\pg\pgsql"
|
|
$pgData = "$env:TEMP\pg\data"
|
|
$pgBin = "$pgDir\bin"
|
|
$logFile = "$env:TEMP\pg\logfile"
|
|
|
|
if (-not (Test-Path "$pgData\postgresql.conf")) {
|
|
Write-Error "PostgreSQL not initialized. Run initdb first."
|
|
exit 1
|
|
}
|
|
|
|
$running = $null -ne (Get-Process -Name "postgres" -ErrorAction SilentlyContinue)
|
|
$listening = $null -ne (netstat -ano -p TCP 2>$null | Select-String ":5432.*LISTENING")
|
|
|
|
if (-not $running -or -not $listening) {
|
|
$existing = Get-Process -Name "postgres" -ErrorAction SilentlyContinue
|
|
if ($existing) { $existing | Stop-Process -Force }
|
|
Start-Sleep -Seconds 1
|
|
Remove-Item "$pgData\postmaster.pid" -Force -ErrorAction SilentlyContinue
|
|
$env:PATH = "$pgBin;$env:PATH"
|
|
Start-Process -FilePath "$pgBin\postgres.exe" -ArgumentList "-D `"$pgData`"" -WindowStyle Hidden
|
|
Start-Sleep -Seconds 3
|
|
Write-Output "PostgreSQL started."
|
|
} else {
|
|
Write-Output "PostgreSQL already running on port 5432."
|
|
}
|