public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ben Caspi <[email protected]>
To: [email protected]
Cc: Avi Uziel <[email protected]>
Cc: Liran Amrani <[email protected]>
Cc: Shahar Amram <[email protected]>
Subject: PostgreSQL MSI ignores --datadir flag during minor upgrade on Windows
Date: Wed, 18 Feb 2026 15:17:50 +0200
Message-ID: <CABv1Mx7basCao7xTOjNs0imLwm98YUgRcOupbMwNGaPVLKSjaw@mail.gmail.com> (raw)

Hello,

Recently we tried to upgrade a client machine's PostgreSQL version from
15.13 to 15.16.
We often upgrade our client machines from versions 9/13 to 15 without
encountering any issues.
However, during this upgrade (15.13 --> 15.16) we've noticed that
post-upgrade the PostgreSQL service assigned data directory changed to the
default value "C:\Program Files\PostgreSQL\15\data".

Our client's data directory prior to the upgrade was
"F:\AidocData\PostgreSQL\15\data". This change caused data to be written to
the wrong location until we found the issue.

This is the command we use for the upgrade:

> Start-Process $installer_exe -ArgumentList "--unattendedmodeui minimal
> --mode unattended --superaccount $POSTGRES_ROOT_USER --superpassword
> $POSTGRES_ROOT_USER_PWD --serverport $port --datadir `"$data_dir`" --locale
> `"$locale_name`"" -Wait


I looked into your codebase and found that during an upgrade the installer
defaults to the Registry value for data directory and ignores the --datadir
flag I provided in my command.

In server/pgserver.xml.in, in the server component’s
preInstallationActionList:

*pgserver.xml.in <http://pgserver.xml.in>*
Lines 1142-1153

        <!-- Set datadir if an existing installation is found -->
>         <setInstallerVariable>
>             <name>datadir</name>
>             <value>${iDataDirectory}</value>
>             <ruleList>
>                 <stringTest>
>                     <text>${iDataDirectory}</text>
>                     <type>not_empty</type>
>                 </stringTest>
>                 <isFalse value="${extract_mode}"/>
>             </ruleList>
>         </setInstallerVariable>



*iDataDirectory is read from the registry here:*
*pgserver.xml.in <http://pgserver.xml.in>*
Lines 1003-1008

                <!-- Get the existing data directory. -->
>                 <registryGet>
>                     <name>Data Directory</name>
>
>                     <key>HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql${service_suffix}-${product_version}</key>
>                     <variable>iDataDirectory</variable>
>                 </registryGet>


*What goes wrong:*
When passing --datadir "F:\AidocData\PostgreSQL\15\data" on the command
line, the wizard sets datadir = "F:\AidocData\PostgreSQL\15\data".

Later, in preInstallationActionList, the installer reads iDataDirectory
from the registry.
If iDataDirectory is not empty, it overwrites datadir with that value.

   1. There is no check that the user explicitly provided --datadir, so the
   CLI value is ignored.

If the registry still has the old default path (e.g. C:\Program
Files\PostgreSQL\15\data), the service ends up re-registered with that path
instead of F:\AidocData\PostgreSQL\15\data.
When the registry can be wrong

   - Initial install used the default data directory, then data was moved
   to F:\AidocData\PostgreSQL\15\data and the service was updated manually,
   but the PostgreSQL registry key was not.
   - A previous install or reinstall wrote the default path to the registry.
   - Any other case where the registry value does not match the actual data
   location.


*Fix*
Only use the registry value when the user has not provided --datadir on the
command line. For example, add a condition so that datadir is set from
iDataDirectory only when datadir is empty:

<!-- Set datadir if an existing installation is found (only when user
> didn't provide --datadir) -->
> <setInstallerVariable>
>     <name>datadir</name>
>     <value>${iDataDirectory}</value>
>     <ruleList>
>         <stringTest>
>             <text>${iDataDirectory}</text>
>             <type>not_empty</type>
>         </stringTest>
>         <stringTest>
>             <text>${datadir}</text>
>             <type>empty</type>
>         </stringTest>
>         <isFalse value="${extract_mode}"/>
>     </ruleList>
> </setInstallerVariable>


This keeps the current behavior when --datadir is not passed, but ensures
that an explicit --datadir is not overridden by the registry.

Please consider investigating this issue and its solution.
If I misunderstood anything please let me know. Thanks!
-- 

[image: photo]

Ben Caspi
DevOps Engineer

www.aidoc.com  |  [email protected]

[image: linkedin] <https://www.linkedin.com/company/aidoc/;

[image: twitter] <https://twitter.com/aidocmed;

[image: App Banner Image] <https://www.aidoc.com/book-a-demo/;


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: PostgreSQL MSI ignores --datadir flag during minor upgrade on Windows
  In-Reply-To: <CABv1Mx7basCao7xTOjNs0imLwm98YUgRcOupbMwNGaPVLKSjaw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox