1 <!-- doc/src/sgml/install-windows.sgml -->
3 <chapter id="install-windows">
4 <title>Installation from Source Code on <productname>Windows</productname></title>
7 <primary>installation</primary>
8 <secondary>on Windows</secondary>
12 It is recommended that most users download the binary distribution for
13 Windows, available as a graphical installer package
14 from the <productname>PostgreSQL</productname> website. Building from source
15 is only intended for people developing <productname>PostgreSQL</productname>
20 There are several different ways of building PostgreSQL on
21 <productname>Windows</productname>. The simplest way to build with
22 Microsoft tools is to install <productname>Visual Studio Express 2015
23 for Windows Desktop</productname> and use the included
24 compiler. It is also possible to build with the full
25 <productname>Microsoft Visual C++ 2005 to 2015</productname>.
26 In some cases that requires the installation of the
27 <productname>Windows SDK</productname> in addition to the compiler.
31 It is also possible to build PostgreSQL using the GNU compiler tools
32 provided by <productname>MinGW</productname>, or using
33 <productname>Cygwin</productname> for older versions of
34 <productname>Windows</productname>.
38 Building using <productname>MinGW</productname> or
39 <productname>Cygwin</productname> uses the normal build system, see
40 <xref linkend="installation"> and the specific notes in
41 <xref linkend="installation-notes-mingw"> and <xref linkend="installation-notes-cygwin">.
42 To produce native 64 bit binaries in these environments, use the tools from
43 <productname>MinGW-w64</productname>. These tools can also be used to
44 cross-compile for 32 bit and 64 bit <productname>Windows</productname>
45 targets on other hosts, such as <productname>Linux</productname> and
46 <productname>macOS</productname>.
47 <productname>Cygwin</productname> is not recommended for running a
48 production server, and it should only be used for running on
49 older versions of <productname>Windows</productname> where
50 the native build does not work, such as
51 <productname>Windows 98</productname>. The official
52 binaries are built using <productname>Visual Studio</productname>.
56 Native builds of <application>psql</application> don't support command
57 line editing. The <productname>Cygwin</productname> build does support
58 command line editing, so it should be used where psql is needed for
59 interactive use on <productname>Windows</productname>.
62 <sect1 id="install-windows-full">
63 <title>Building with <productname>Visual C++</productname> or the
64 <productname>Microsoft Windows SDK</productname></title>
67 PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
68 These compilers can be either from <productname>Visual Studio</productname>,
69 <productname>Visual Studio Express</productname> or some versions of the
70 <productname>Microsoft Windows SDK</productname>. If you do not already have a
71 <productname>Visual Studio</productname> environment set up, the easiest
72 ways are to use the compilers from <productname>Visual Studio Express 2015
73 for Windows Desktop</productname> or those in the <productname>Windows SDK
74 7.1</productname>, which are both free downloads from Microsoft.
78 Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
79 32-bit PostgreSQL builds are possible with
80 <productname>Visual Studio 2005</productname> to
81 <productname>Visual Studio 2015</productname> (including Express editions),
82 as well as standalone Windows SDK releases 6.0 to 7.1.
83 64-bit PostgreSQL builds are supported with
84 <productname>Microsoft Windows SDK</productname> version 6.0a to 7.1 or
85 <productname>Visual Studio 2008</productname> and above. Compilation
86 is supported down to <productname>Windows XP</productname> and
87 <productname>Windows Server 2003</> when building with
88 <productname>Visual Studio 2005</> to
89 <productname>Visual Studio 2013</productname>. Building with
90 <productname>Visual Studio 2015</productname> is supported down to
91 <productname>Windows Vista</> and <productname>Windows Server 2008</>.
95 The tools for building using <productname>Visual C++</productname> or
96 <productname>Platform SDK</productname> are in the
97 <filename>src/tools/msvc</filename> directory. When building, make sure
98 there are no tools from <productname>MinGW</productname> or
99 <productname>Cygwin</productname> present in your system PATH. Also, make
100 sure you have all the required Visual C++ tools available in the PATH. In
101 <productname>Visual Studio</productname>, start the
102 <application>Visual Studio Command Prompt</application>.
103 If you wish to build a 64-bit version, you must use the 64-bit version of
104 the command, and vice versa.
105 In the <productname>Microsoft Windows SDK</productname>, start the
106 <application>CMD shell</application> listed under the SDK on the Start Menu.
107 In recent SDK versions you can change the targeted CPU architecture, build
108 type, and target OS by using the <command>setenv</command> command, e.g.
109 <command>setenv /x86 /release /xp</command> to target Windows XP or later
110 with a 32-bit release build. See <command>/?</command> for other options to
111 <command>setenv</command>. All commands should be run from the
112 <filename>src\tools\msvc</filename> directory.
116 Before you build, you may need to edit the file <filename>config.pl</filename>
117 to reflect any configuration options you want to change, or the paths to
118 any third party libraries to use. The complete configuration is determined
119 by first reading and parsing the file <filename>config_default.pl</filename>,
120 and then apply any changes from <filename>config.pl</filename>. For example,
121 to specify the location of your <productname>Python</productname> installation,
122 put the following in <filename>config.pl</filename>:
124 $config->{python} = 'c:\python26';
126 You only need to specify those parameters that are different from what's in
127 <filename>config_default.pl</filename>.
131 If you need to set any other environment variables, create a file called
132 <filename>buildenv.pl</filename> and put the required commands there. For
133 example, to add the path for bison when it's not in the PATH, create a file
136 $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
141 To pass additional command line arguments to the Visual Studio build
142 command (msbuild or vcbuild):
149 <title>Requirements</title>
151 The following additional products are required to build
152 <productname>PostgreSQL</productname>. Use the
153 <filename>config.pl</filename> file to specify which directories the libraries
158 <term><productname>Microsoft Windows SDK</productname></term>
160 If your build environment doesn't ship with a supported version of the
161 <productname>Microsoft Windows SDK</productname> it
162 is recommended that you upgrade to the latest version (currently
163 version 7.1), available for download from
164 <ulink url="https://www.microsoft.com/download"></>.
167 You must always include the
168 <application>Windows Headers and Libraries</application> part of the SDK.
169 If you install a <productname>Windows SDK</productname>
170 including the <application>Visual C++ Compilers</application>,
171 you don't need <productname>Visual Studio</productname> to build.
172 Note that as of Version 8.0a the Windows SDK no longer ships with a
173 complete command-line build environment.
178 <term><productname>ActiveState Perl</productname></term>
180 ActiveState Perl is required to run the build generation scripts. MinGW
181 or Cygwin Perl will not work. It must also be present in the PATH.
182 Binaries can be downloaded from
183 <ulink url="http://www.activestate.com"></> (Note: version 5.8 or later is required,
184 the free Standard Distribution is sufficient).
191 The following additional products are not required to get started,
192 but are required to build the complete package. Use the
193 <filename>config.pl</filename> file to specify which directories the libraries
198 <term><productname>ActiveState TCL</productname></term>
200 Required for building <application>PL/Tcl</application> (Note: version
201 8.4 is required, the free Standard Distribution is sufficient).
206 <term><productname>Bison</productname> and
207 <productname>Flex</productname></term>
210 <productname>Bison</productname> and <productname>Flex</productname> are
211 required to build from Git, but not required when building from a release
212 file. Only <productname>Bison</productname> 1.875 or versions 2.2 and later
213 will work. <productname>Flex</productname> must be version 2.5.31 or later.
217 Both <productname>Bison</productname> and <productname>Flex</productname>
218 are included in the <productname>msys</productname> tool suite, available
219 from <ulink url="http://www.mingw.org/wiki/MSYS"></> as part of the
220 <productname>MinGW</productname> compiler suite.
224 You will need to add the directory containing
225 <filename>flex.exe</filename> and <filename>bison.exe</filename> to the
226 PATH environment variable in <filename>buildenv.pl</filename> unless
227 they are already in PATH. In the case of MinGW, the directory is the
228 <filename>\msys\1.0\bin</filename> subdirectory of your MinGW
229 installation directory.
234 The Bison distribution from GnuWin32 appears to have a bug that
235 causes Bison to malfunction when installed in a directory with
236 spaces in the name, such as the default location on English
237 installations <filename>C:\Program Files\GnuWin32</filename>.
238 Consider installing into <filename>C:\GnuWin32</filename> or use the
239 NTFS short name path to GnuWin32 in your PATH environment setting
240 (e.g. <filename>C:\PROGRA~1\GnuWin32</filename>).
246 The obsolete <literal>winflex</literal> binaries distributed on the PostgreSQL FTP site
247 and referenced in older documentation will fail with <quote>flex: fatal
248 internal error, exec failed</quote> on 64-bit Windows hosts. Use Flex from
256 <term><productname>Diff</productname></term>
258 Diff is required to run the regression tests, and can be downloaded
259 from <ulink url="http://gnuwin32.sourceforge.net"></>.
264 <term><productname>Gettext</productname></term>
266 Gettext is required to build with NLS support, and can be downloaded
267 from <ulink url="http://gnuwin32.sourceforge.net"></>. Note that binaries,
268 dependencies and developer files are all needed.
273 <term><productname>MIT Kerberos</productname></term>
275 Required for GSSAPI authentication support. MIT Kerberos can be
277 <ulink url="http://web.mit.edu/Kerberos/dist/index.html"></>.
282 <term><productname>libxml2</productname> and
283 <productname>libxslt</productname></term>
285 Required for XML support. Binaries can be downloaded from
286 <ulink url="http://zlatkovic.com/pub/libxml"></> or source from
287 <ulink url="http://xmlsoft.org"></>. Note that libxml2 requires iconv,
288 which is available from the same download location.
293 <term><productname>openssl</productname></term>
295 Required for SSL support. Binaries can be downloaded from
296 <ulink url="http://www.slproweb.com/products/Win32OpenSSL.html"></>
297 or source from <ulink url="http://www.openssl.org"></>.
302 <term><productname>ossp-uuid</productname></term>
304 Required for UUID-OSSP support (contrib only). Source can be
306 <ulink url="http://www.ossp.org/pkg/lib/uuid/"></>.
311 <term><productname>Python</productname></term>
313 Required for building <application>PL/Python</application>. Binaries can
314 be downloaded from <ulink url="http://www.python.org"></>.
319 <term><productname>zlib</productname></term>
321 Required for compression support in <application>pg_dump</application>
322 and <application>pg_restore</application>. Binaries can be downloaded
323 from <ulink url="http://www.zlib.net"></>.
332 <title>Special Considerations for 64-bit Windows</title>
335 PostgreSQL will only build for the x64 architecture on 64-bit Windows, there
336 is no support for Itanium processors.
340 Mixing 32- and 64-bit versions in the same build tree is not supported.
341 The build system will automatically detect if it's running in a 32- or
342 64-bit environment, and build PostgreSQL accordingly. For this reason, it
343 is important to start the correct command prompt before building.
347 To use a server-side third party library such as <productname>python</> or
348 <productname>openssl</>, this library <emphasis>must</emphasis> also be
349 64-bit. There is no support for loading a 32-bit library in a 64-bit
350 server. Several of the third party libraries that PostgreSQL supports may
351 only be available in 32-bit versions, in which case they cannot be used with
357 <title>Building</title>
360 To build all of PostgreSQL in release configuration (the default), run the
363 <userinput>build</userinput>
365 To build all of PostgreSQL in debug configuration, run the command:
367 <userinput>build DEBUG</userinput>
369 To build just a single project, for example psql, run the commands:
371 <userinput>build psql</userinput>
372 <userinput>build DEBUG psql</userinput>
374 To change the default build configuration to debug, put the following
375 in the <filename>buildenv.pl</filename> file:
377 $ENV{CONFIG}="Debug";
382 It is also possible to build from inside the Visual Studio GUI. In this
383 case, you need to run:
385 <userinput>perl mkvcbuild.pl</userinput>
387 from the command prompt, and then open the generated
388 <filename>pgsql.sln</filename> (in the root directory of the source tree)
394 <title>Cleaning and Installing</title>
397 Most of the time, the automatic dependency tracking in Visual Studio will
398 handle changed files. But if there have been large changes, you may need
399 to clean the installation. To do this, simply run the
400 <filename>clean.bat</filename> command, which will automatically clean out
401 all generated files. You can also run it with the
402 <parameter>dist</parameter> parameter, in which case it will behave like
403 <userinput>make distclean</userinput> and remove the flex/bison output files
408 By default, all files are written into a subdirectory of the
409 <filename>debug</filename> or <filename>release</filename> directories. To
410 install these files using the standard layout, and also generate the files
411 required to initialize and use the database, run the command:
413 <userinput>install c:\destination\directory</userinput>
418 If you want to install only the client applications and
419 interface libraries, then you can use these commands:
421 <userinput>install c:\destination\directory client</userinput>
427 <title>Running the Regression Tests</title>
430 To run the regression tests, make sure you have completed the build of all
431 required parts first. Also, make sure that the DLLs required to load all
432 parts of the system (such as the Perl and Python DLLs for the procedural
433 languages) are present in the system path. If they are not, set it through
434 the <filename>buildenv.pl</filename> file. To run the tests, run one of
435 the following commands from the <filename>src\tools\msvc</filename>
438 <userinput>vcregress check</userinput>
439 <userinput>vcregress installcheck</userinput>
440 <userinput>vcregress plcheck</userinput>
441 <userinput>vcregress contribcheck</userinput>
442 <userinput>vcregress modulescheck</userinput>
443 <userinput>vcregress ecpgcheck</userinput>
444 <userinput>vcregress isolationcheck</userinput>
445 <userinput>vcregress bincheck</userinput>
446 <userinput>vcregress recoverycheck</userinput>
447 <userinput>vcregress upgradecheck</userinput>
450 To change the schedule used (default is parallel), append it to the
453 <userinput>vcregress check serial</userinput>
456 For more information about the regression tests, see
457 <xref linkend="regress">.
461 Running the regression tests on client programs, with
462 <command>vcregress bincheck</>, or on recovery tests, with
463 <command>vcregress recoverycheck</>, requires an additional Perl module
467 <term><productname>IPC::Run</productname></term>
469 As of this writing, <literal>IPC::Run</> is not included in the
470 ActiveState Perl installation, nor in the ActiveState Perl Package
471 Manager (PPM) library. To install, download the
472 <filename>IPC-Run-<version>.tar.gz</> source archive from CPAN,
473 at <ulink url="http://search.cpan.org/dist/IPC-Run/"></>, and
474 uncompress. Edit the <filename>buildenv.pl</> file, and add a PERL5LIB
475 variable to point to the <filename>lib</> subdirectory from the
476 extracted archive. For example:
478 $ENV{PERL5LIB}=$ENV{PERL5LIB} . ';c:\IPC-Run-0.94\lib';
487 <title>Building the Documentation</title>
490 Building the PostgreSQL documentation in HTML format requires several tools
491 and files. Create a root directory for all these files, and store them
492 in the subdirectories in the list below.
495 <term>OpenJade 1.3.1-2</term>
498 <ulink url="http://sourceforge.net/projects/openjade/files/openjade/1.3.1/openjade-1_3_1-2-bin.zip/download"></>
499 and uncompress in the subdirectory <filename>openjade-1.3.1</filename>.
504 <term>DocBook DTD 4.2</term>
507 <ulink url="http://www.oasis-open.org/docbook/sgml/4.2/docbook-4.2.zip"></>
508 and uncompress in the subdirectory <filename>docbook</filename>.
513 <term>ISO character entities</term>
516 <ulink url="http://www.oasis-open.org/cover/ISOEnts.zip"></> and
517 uncompress in the subdirectory <filename>docbook</filename>.
521 Edit the <filename>buildenv.pl</filename> file, and add a variable for the
522 location of the root directory, for example:
524 $ENV{DOCROOT}='c:\docbook';
526 To build the documentation, run the command
527 <filename>builddoc.bat</filename>. Note that this will actually run the
528 build twice, in order to generate the indexes. The generated HTML files
529 will be in <filename>doc\src\sgml</filename>.