Skip to content

Commit d62283e

Browse files
authored
[Windows] Move PGDATA out of Program Files (#13107)
1 parent 8b17fc0 commit d62283e

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

images/windows/scripts/build/Install-PostgreSQL.ps1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
# Define user and password for PostgreSQL database
77
$pgUser = "postgres"
8-
$pgPwd = "root"
8+
$pgPwd = "root"
9+
10+
# Save current value of ErrorActionPreference and set it to Stop
11+
$errorActionOldValue = $ErrorActionPreference
912

1013
# Prepare environment variable for validation
1114
[Environment]::SetEnvironmentVariable("PGUSER", $pgUser, "Machine")
@@ -35,7 +38,6 @@ if ($null -ne ($toolsetVersion | Select-String -Pattern '\d+\.\d+\.\d+')) {
3538
$targetMinorVersions = ($minorVersions | Sort-Object)[-1]
3639

3740
# In order to get rid of error messages (we know we will have them), force ErrorAction to SilentlyContinue
38-
$errorActionOldValue = $ErrorActionPreference
3941
$ErrorActionPreference = 'SilentlyContinue'
4042

4143
# Install latest PostgreSQL
@@ -58,10 +60,27 @@ if ($null -ne ($toolsetVersion | Select-String -Pattern '\d+\.\d+\.\d+')) {
5860
} while (!$response)
5961
}
6062

61-
6263
# Return the previous value of ErrorAction and invoke Install-Binary function
6364
$ErrorActionPreference = $errorActionOldValue
64-
$installerArgs = @("--install_runtimes 0", "--superpassword root", "--enable_acledit 1", "--unattendedmodeui none", "--mode unattended")
65+
66+
# Define new data directory for PostgreSQL and create it
67+
if ($installerUrl -match 'postgresql-(\d+)') {
68+
$pgMajorVersion = $matches[1]
69+
}
70+
$pgData = "C:\PostgreSQL\$pgMajorVersion\data"
71+
if (-Not (Test-Path -Path $pgData)) {
72+
New-Item -ItemType Directory -Path $pgData | Out-Null
73+
}
74+
75+
# Define silent install arguments for PostgreSQL
76+
$installerArgs = @(
77+
"--install_runtimes 0",
78+
"--superpassword root",
79+
"--enable_acledit 1",
80+
"--unattendedmodeui none",
81+
"--mode unattended",
82+
"--datadir `"$pgData`""
83+
)
6584

6685
Install-Binary `
6786
-Url $installerUrl `
@@ -74,8 +93,7 @@ $pgPath = (Get-CimInstance Win32_Service -Filter "Name LIKE 'postgresql-%'").Pat
7493

7594
# Parse output of command above to obtain pure path
7695
$pgBin = Split-Path -Path $pgPath.split('"')[1]
77-
$pgRoot = Split-Path -Path $pgPath.split('"')[5]
78-
$pgData = Join-Path $pgRoot "data"
96+
$pgRoot = Split-Path $pgBin -Parent
7997

8098
# Validate PostgreSQL installation
8199
$pgReadyPath = Join-Path $pgBin "pg_isready.exe"

0 commit comments

Comments
 (0)