Sunday, July 12, 2009

Compiling PostgreSQL on Windows

The following compilation procedure has been tested on MS Windows XP Professional using PostgreSQL 8.4.0, MinGW 5.1.4 and MSYS 1.0.11.rc-1.

Steps

1. Download MinGW and MSYS from http://www.mingw.org
2. Download PostgreSQL source code from http://www.postgresql.org
3. Download the zlib compression library from http://www.zlib.org
4. Install MinGW under the directory c:\mingw
5. Install MSYS under the directory c:\msys. Indicate where mingw is located when prompted by MSYS.

6. Add the path to Windows for the following directories:

c:\msys\1.0\bin
c:\msys\1.0\mingw\bin
c:\msys\1.0\mingw\sbin
c:\mingw\bin



This is done by going to "Start->Settings->Control Panel->System icon->Advanced tab->Environment Variables button". Then under the "System Variables" grouping, Select the "Path" and choose "Edit" button. Add the above directories at the end by delimiting it with a semi-colon (;).

7. Install the zlib library:

a) Unpack the zlib in MSYS (c:\msys\home\{username}\zlib)
b) Run MSYS by typing the msys.bat file in c:\msys\1.0
c) At the MSYS terminal, type the following:

$ cd /home/{username}/zlib
$ make -f win32/Makefile.gcc


d) Copy the zlib1.dll to c:\mingw\bin
e) Copy the libzdll.a and libz.a to c:\mingw\lib
f) Copy the zlib.h and zconf.h to c:\mingw\include


8. Unpack the PostgreSQL source code and copy it to the directory c:\msys\1.0\home\{username}\postgresql.

The source code is in tar.gz format. You can use the 7zip software from http://www.7-zip.org to unpack the source code.

9. At the MSYS terminal, go to the PostgreSQL source code directory and run the compile commands as follows:

$ cd /home/{username}/postgresql
$ ./configure
$ make
$ make install


This will create the PostgreSQL binaries in the following directory c:\msys\1.0\local\pgsql

10. Create the default data directory for PostgreSQL as "c:\msys\1.0\local\pgsql\data"

11. You can now copy the folder of PostgreSQL binaries to your desired location like "c:\pgsql" or create an installer package for your other machines.

The MinGW and MSYS software are not needed by PostgreSQL once you are able to create its binaries under Windows.

No comments: