Building PostgreSQL (x86, x64) and OpenSSL using MSYS2 and MinGW under Windows

07.2019 / Category: / Tags: |

I've written already a blog post "Building PostgreSQL with MSYS2 and MinGW under Windows" a year ago. But this time I want to show you two important things:

  1. cross compiling (x86, x64) using the same run-time;
  2. compiling with the latest OpenSSL support.


That's true nowadays you won't find binaries or installations of PostgreSQL without OpenSSL support. It used not only for encryption but for compression as well.

Even though it's Windows, let's make all steps in command prompt only. Yes, I told you Linux guys, we can run console too!

Setting up the environment

First things first. I launch my msys2 shell. I assume you have it on your system, if not check installation instructions from my previous post.

c:msys64 is the msys2 installation folder.

I'm telling msys2 to run shell and use -mingw64 as a default chain. That means we will build x64 binaries. -conemu is an optional parameter, you may want to pass it in case you're a fan of ConEmu as I am. If not, just skip it.

Inside msys2 we are using Unix-like filesystem with root / and Windows drives mounted as /c, /d, etc.

We're creating /src/ folder for storing sources and cloning both PostgreSQL and OpenSSL sources.

By providing an argument of --depth 1 to the clone command, the process will copy only the latest revision of everything in the repository.

And of course, we want to build only stable releases for production, thus --branch *_STABLE. You may omit this parameter to build the latest sources from the master branch.

Building OpenSSL

Removing tests test/* is not necessary, but it may take a lot of time during development and constant remaking.

Configure OpenSSL installation with output folder /usr/local/openssl64, force produce shared libraries and use mingw64 chain.

make install_dev will install everything needed for development and further PostgreSQL build process.

Building PostgreSQL

Configure PostgreSQL installation with output folder /usr/local/postgres64, use OpenSSL --with-openssl, use additional includes /usr/local/openssl64/include and libraries from /usr/local/openssl64/lib. As you can see all paths are pointing to freshly installed OpenSSL.

In configure output pay attention to highlighted lines 17-22. In case of any trouble, you will see the proper message there.

If you want to build the whole tree, just run make. But in my example, I'm showing how to build a portion of it, in this particular case I'm building only interfaces, e.g. libpq, ecpg, etc. This is a common task for packaging and deploy of client software.


All built binaries are available at /usr/local/openssl64 and /usr/local/postgres64. Let's check:

To make that same process produce x86 binaries one should start msys2 shell with the command:

Super easy! I hope now it's become clearer. Next time I will show you how to build PostgreSQL extensions. Even if they are not supposed to be Windows ready and have no Visual Studio packages.

0 0 votes
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Hans Castorp
Hans Castorp
5 years ago

Could you also add the description on how to compile the "contrib" modules?


CYBERTEC Logo white
CYBERTEC PostgreSQL International GmbH
Römerstraße 19
2752 Wöllersdorf

+43 (0) 2622 93022-0

Get the newest PostgreSQL Info & Tools

    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    CYBERTEC PostgreSQL International GmbH
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram