Compiling PostgreSQL on Windows

Source: Internet
Author: User

1. Source Code download and preparation
PostgreSQL uses the flex and yacc scripts respectively for lexical and Syntax Parsing, that is, the. l and. y files in the source code are generated by them. c and. H files.
For more details, see:
Http://, this website cannot be accessed directly and you can find a solution)
These two tools have not been completely completed in the Windows environment. In addition, considering their versions, I generate a syntax engine in Linux. For the operation steps, see (2 ).

References: Mechanical Industry Press of lex and yacc

(1) download the package. The advantage of this method is that you do not need to use flex and bison.
International community
Domestic image
In step 2, you do not need to generate any files in Linux.

(2) The clone community git code library requires: git flex bison
Git is a powerful and confusing code management tool. Learn how to use it on the official website:
Http:// unfortunately, find a solution on your own)
In Windows, Cygwin can be installed, git and openssh can be installed, and git can be used in the Cygwin environment.

Note that the compilation switch must be consistent. The following steps a-e must be executed in Linux.
A). Clone the code library
Git clone
B). To configure compilation parameters, you may need to install some Development kits and install them according to the error prompt.
./Configure -- prefix =/usr/local/pg93b1 \
-- Enable-nls = "zh_CN zh_TW "\
-- Without-perl \
-- Without-python \
-- Without-tcl \
-- Without-gssapi \
Without-krb5 \
-- Without-pam \
-- Without-ldap \
-- Without-bonjour \
-- With-openssl \
-- With-libxml -- with-libxslt \
-- Enable-thread-safety \
-- With-zlib \
-- Without-selinux
C) Compile the kernel
D) Compile the peripheral modules.
Cd contrib & make
Cd ..
E) Compile the isolation test script
Cd src/test/isolation & make
F) copy the following file to the same location of the source code in Windows.
Src \ backend \ bootstrap \ bootparse. c
Src \ backend \ bootstrap \ bootpattern. c
Src \ backend \ parser \ gram. c
Src \ backend \ parser \ gram. h
Src \ backend \ parser \ scan. c
Src \ backend \ replication \ repl_gram.c
Src \ backend \ replication \ repl_scanner.c
Src \ backend \ utils \ misc \ guc-file.c
Src \ bin \ psql \ psqlscan. c
Contrib \ cube \ cubeparse. c
Contrib \ cube \ cubescan. c
Contrib \ seg \ segparse. c
Contrib \ seg \ segscan. c
Src \ interfaces \ ecpg \ preproc \ pgc. c
Src \ interfaces \ ecpg \ preproc. c
Src \ interfaces \ ecpg \ preproc. h
Src \ pl \ plpgsql \ src \ pl_gram.c
Src \ pl \ plpgsql \ src \ pl_gram.h
Src \ test \ isolation \ specparse. c
Src \ test \ isolation \ specw.c

2. Download and prepare Windows Development Kit
For the list of Development kits required for compiling PostgreSQL in Windows, see 16.1.1. Requirements.

Download OpenSSL, which is comprehensive here.

Openssl is also available here, but the version is old.
Download iconv, libxml2, libxslt, and zlib from here. We recommend that you use

Download gettext here

The package updates on the in the document are far behind gnu, but still available.

Decompress the downloaded package to the c: \ pgbuild directory.

3. Download from Microsoft VC. The express version is sufficient for us and is free of charge.
After installation, we recommend that you install all patches.

4. Modify src \ tools \ msvc \ to point to the downloaded SDK.
Nls => "C: \ pgbuild \ gettext"
Openssl => "C: \ pgbuild \ OpenSSL"
Xml => "C :\\ pgbuild \ libxml2"
Xslt => "C :\\ pgbuild \ libxslt"
Iconv => "C: \ pgbuild \ iconv"
Zlib => "C: \ pgbuild \ zlib"

6. Download and install ActivePerl

7. Open the program menu "Microsoft Visual Studio 2010"-> "Visual Studio Tools"-> "Visual Studio Command Prompt (2010)"
If it is another version, it should be noted that it is a 32-bit version, but you cannot be sure of its attributes. The parameter x86 is behind vcvarsall. bat.
Set path = % path %; C: \ pgbuild \ iconv \ bin;
Set path = % path % C: \ ActivePerl-5.12.x \ bin;
Set path = % path % C: \ pgbuild \ gettext \ bin;
Go to the PostgreSQL source code src \ tools \ msvc and run build. bat.
Run after compilation: install. bat <target directory>

8. At this point, the compilation is complete, but some dll files need to be manually copied. Find the dll files in the Development Kit directory in step 2 based on the file missing error prompt.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.