[Windows] Move PGDATA out of Program Files (#13107)

This commit is contained in:
Erik Bershel
2025-10-02 15:37:42 +02:00
committed by GitHub
parent 8b17fc0f05
commit d62283e7d1

View File

@@ -5,7 +5,10 @@
# Define user and password for PostgreSQL database
$pgUser = "postgres"
$pgPwd = "root"
$pgPwd = "root"
# Save current value of ErrorActionPreference and set it to Stop
$errorActionOldValue = $ErrorActionPreference
# Prepare environment variable for validation
[Environment]::SetEnvironmentVariable("PGUSER", $pgUser, "Machine")
@@ -35,7 +38,6 @@ if ($null -ne ($toolsetVersion | Select-String -Pattern '\d+\.\d+\.\d+')) {
$targetMinorVersions = ($minorVersions | Sort-Object)[-1]
# In order to get rid of error messages (we know we will have them), force ErrorAction to SilentlyContinue
$errorActionOldValue = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
# Install latest PostgreSQL
@@ -58,10 +60,27 @@ if ($null -ne ($toolsetVersion | Select-String -Pattern '\d+\.\d+\.\d+')) {
} while (!$response)
}
# Return the previous value of ErrorAction and invoke Install-Binary function
$ErrorActionPreference = $errorActionOldValue
$installerArgs = @("--install_runtimes 0", "--superpassword root", "--enable_acledit 1", "--unattendedmodeui none", "--mode unattended")
# Define new data directory for PostgreSQL and create it
if ($installerUrl -match 'postgresql-(\d+)') {
$pgMajorVersion = $matches[1]
}
$pgData = "C:\PostgreSQL\$pgMajorVersion\data"
if (-Not (Test-Path -Path $pgData)) {
New-Item -ItemType Directory -Path $pgData | Out-Null
}
# Define silent install arguments for PostgreSQL
$installerArgs = @(
"--install_runtimes 0",
"--superpassword root",
"--enable_acledit 1",
"--unattendedmodeui none",
"--mode unattended",
"--datadir `"$pgData`""
)
Install-Binary `
-Url $installerUrl `
@@ -74,8 +93,7 @@ $pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").Pat
# Parse output of command above to obtain pure path
$pgBin = Split-Path -Path $pgPath.split('"')[1]
$pgRoot = Split-Path -Path $pgPath.split('"')[5]
$pgData = Join-Path $pgRoot "data"
$pgRoot = Split-Path $pgBin -Parent
# Validate PostgreSQL installation
$pgReadyPath = Join-Path $pgBin "pg_isready.exe"