programatically install postgres on windows

Of course if you are running a PostgreSQL server it should be on a robust *NIX server, as that is what PostgreSQL is natively written for.

However some of our teams need Windows servers, and on these they need the psql client to communicate with remote databases.

To install PostgreSQL (client) on Windows with a GUI installer is easy. Download installer, click "Next" a few times, and it's installed.

However to install programatically through a DSC system requires a little more work.

Luckily, PostgreSQL provides the binaries for psql and related tools.

However for a fresh install of Windows, these won't work out of the box.

First, you will then need to install Microsoft Visual C++ 2013 Redistributable. This will install all the required DLLs.

If using Chocolatey (if not, start!) - choco install -y msvisualcplusplus2013-dist.

Then, download the zipped PostgreSQL directory and then move the pgsql directory into a common location, such as C:\Program Files.

Finally, add the binaries to your PATH with your desired DSC framework.

Chef Example
windows_path 'C:\Program Files\pgsql\bin' do
  action: add
done


You will now be able to use the PostgreSQL binaries from your PowerShell and CMD prompts.

last updated 2024-10-03