Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Scripts to build PostgreSQL and its dependencies on Windows automatically
Perl PowerShell Shell
Tree: 649f9f82f0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


These scripts create a PostgreSQL build environment for Windows, and build

They're for NMake, the Microsoft version of make that uses cmd.exe. It comes
with Visual Studio. Yes, that's horrid, but it's better than trying to disentangle
the environment of mingw from that of Visual Studio.

You will require installs of ActiveState Perl, ActiveState TCL,
Python 2, MinGW, git (from, and the Microsoft SDK 7.1 to use these
scripts. Instructions on unattended installs for these tools are coming shortly;
just need to copy them from another machine.

Download Windows SDK 7.1

You can download the SDK from: (web installer)
or (offline installers ISOs).

If using the offline installer, get GRMSDKX_EN_DVD.iso for x64 or 
GRMSDK_EN_DVD.iso for x86. You don't need to burn a CD to install it, 
see below for instructions.

Download required tools

Some of this will be automated later, but for now you must download the following
required tools. Don't install them; see below for that.
* ActiveState TCL x64 and x86 from
* ActiveState Perl x86 and x64 from
* python 2.7 and 3.3, both in x86 and x64 versions from
* mingw-get-inst from
* git from
* 7-zip from

You need MinGW even for MSVC builds because you need the "flex" executable
from it to build on x64; the version provided on the PostgreSQL site doesn't
run on win64. These scripts also use bison, wget and touch from mingw. All 
these tools come with msysgit too, so a future version may support using
msysgit instead of MinGW.

I also recommend:
* notepad++ from http://

Install the tools

Open a command prompt and cd to the location you downloaded all the above tools to.

Now use the following commands to install the tools. On Windows the command prompt
doesn't wait until a spawned command completes; you can use "start /WAIT" to launch
them and wait, but it won't work with all installers.

You will need to adjust the file names to reflect the exact files you downloaded.

	start /wait mingw-get-inst-20120426.exe /silent
	c:\MinGW\bin\mingw-get.exe install msys-flex msys-bison g++ gdb mingw32-make msys-base
	start /wait msiexec /i 7z920-x64.msi /qb /passive /norestart
	start /wait Git-1.8.0-preview20121022.exe /silent
	start /wait msiexec /i ActivePerl- /qb /passive PERL_PATH=Yes PERL_EXT=Yes
	start /wait msiexec /i ActivePerl- /qb /passive PERL_PATH=No PERL_EXT=No
	start /wait ActiveTcl8. --directory %SystemDrive%\TCL_85_x86
	start /wait ActiveTcl8. --directory %SystemDrive%\TCL_85_x64
	start /wait msiexec /i python-2.7.3.amd64.msi /qb /passive TARGETDIR=c:\Python27_x64 ALLUSERS=1
	start /wait msiexec /i python-2.7.3.msi /qb /passive TARGETDIR=c:\Python27_x86 ALLUSERS=1
	start /wait msiexec /i python-3.3.0.amd64.msi /qb /passive TARGETDIR=c:\Python33_x64 ALLUSERS=1
If you downloaded the offline install ISO for the Windows SDK, you can install it with:

	"c:\Program Files\7-Zip\7z.exe" x -owinsdk GRMSDKX_EN_DVD.iso
	start /wait winsdk\setup.exe -q -params:ADDLOCAL=ALL
	rd /s /q winsdk
(Change GRMSDKX_EN_DVD.iso to GRMSDK_EN_DVD.iso if you're on x64) 

Optionally also install notepad++:

	start /wait npp.6.2.2.Installer.exe /S

Configure the build

Copy settings-template.mak to settings.mak and edit it to reflect your
environment. You can pass the settings on the command line instead, but
currently an empty settings.mak is still required. See settings-defaults.mak
for what you can override. You will want to set at least:

	PG_GIT_URL=valid Git url for PostgreSQL
	PG_BRANCH=which pg branch to build, eg REL9_2_STABLE or master

It's preferable to use absolute paths for LIBDIR and PGDIR.

Anything inside LIBDIR and PGDIR will be deleted by "nmake reallyclean".

As cloning Pg from scratch takes time, I recommend cloning a bare copy of the Pg repo *outside* LIBDIR and PGDIR:

	git clone --bare --mirror git:// d:\postgresql-git

and specifying the path to it as PG_GIT_URL:

Set up your Visual Studio or Windows SDK environment for the build target you want.
Either use the Start menu option to launch a suitable prompt if you want the default
settings, or preferably open a new ordinary Command Prompt and use SetEnv.cmd
(SDK) or vcvars.bat (Studio) to set the environment up.

For windows SDK 7.1 32-bit release builds you'd use:

    "c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.Cmd" /x86 /release /xp
For options:

    "c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.Cmd" /?

The main options are "/x86" vs "/x64" and "/Debug" vs "/Release".
You probably want to pass "/xp" for 32-bit builds and "/2008" for 64-bit builds.


In a command prompt that's had its environment set up as per "SET UP
VISUAL STUDIO ENVIRONMENT", do a full build with:

    nmake /f pg_build_win\Makefile postgresql

Supported targets are:

* postgresql: Build PostgreSQL and its dependencies
* postgresql-check: Run the test suite
* postgresql-clean: Clean postgresql working tree, leave libraries alone


If you want to build individual libraries, each library Makefile
has "libname" and "libname-clean" targets, eg:

* zlib
* zlib-clean


* clean - remove built libraries and clean PostgreSQL working tree
* really-clean: Remove built libraries and downloaded files, delete PostgreSQL checkout and working tree
Something went wrong with that request. Please try again.