[olug] compiling PostgreSQL for Windows

Lou Duchez lou at paprikash.com
Tue Mar 10 17:07:37 CDT 2015


I work in a mixed environment of Linux and Windows servers, with lots of 
PostgreSQL databases on both types of machines.  Ever since about day 
one, I have been updating PostgreSQL on the Linux boxes by downloading 
the new source code from postgresql.org and doing the old "configure / 
make / make install" that we've come to expect. Windows compiling was 
always more complicated, though, so I would just download the pre-built 
binaries.

Only problem is, with the latest major revision of PostgreSQL, they've 
withdrawn support for some of the older versions of Windows I have to 
work with, so no new binaries.  So I spent some time the past couple 
days figuring out the compilation process, and now I can roll my own.

So just in case anyone needs to compile their own Windows PostgreSQL, 
here are my notes.  I do not guarantee their inerrancy; this is what 
worked for me, and assuming I didn't forget to record any steps, 
hopefully it should work for you too.

---

Compiling PostgreSQL under Windows

General instructions can be found here:

http://www.postgresql.org/docs/9.4/static/install-windows-full.html

These instructions assume you have a copy of Visual Studio, and that you 
will get the Microsoft Windows SDK, ActiveState Perl, Diff, Gettext, and 
openssl per the Web page above.

1)    Unzip the PostgreSQL source (postgresql-x.x.x.tar.gz) to 
c:\postgresql-x.x.x.

2)    Create or edit the file 
C:\postgresql-x.x.x\src\tools\msvc\config.pl so that it contains this line:

     $config->{openssl} = 'C:\OpenSSL-Win32';

     This is the directory where OpenSSL was installed; if it was 
installed elsewhere, change as appropriate.  Note the use of apostrophes 
rather than double-quotes.

3)    Click on Programs / Microsoft Visual Studio / Visual Tools / 
Visual Studio Command Prompt.  This opens a command prompt with the 
Visual Studio environment.

4)    Run "clean" to make sure the directories are cleaned out for a new 
build.

5)    Run "build" to do the build.  After several minutes it should be 
done, and hopefully will return zero errors (though some number of 
warnings are normal).

6)    Run "path %PATH%;C:\Program Files\GnuWin32\bin"so that the 
regression check will have access to the Gnu utilities it needs. (Again, 
change the path as appropriate.)

7)    Run "vcregress check" to do the regression check.

8)    Run "install C:\PostgreSQL\x.x" to install in C:\PostgreSQL\x.x.



PostgreSQL does not require any registry work or moving files into 
"shared" folders.  The remaining steps are just creating the cluster and 
creating a service for starting / stopping PostgreSQL.

To create the cluster:

1)    Create a user "postgres" for PostgreSQL to run under.

2)    At a command prompt, run "runas /user:postgres".  After you enter 
the password, a new command prompt will open that is running as postgres.

3)    Run "C:\postgresql\x.x\bin\initdb -E UTF-8 -D c:\postgresql\x.x\data".

To create the service:

c:\postgresql\x.x\bin\pg_ctl register -N [service name] -U postgres -P 
[password] -D C:\postgresql\x.x\data -w




More information about the OLUG mailing list