Building postgres on windows
06 Oct 2013So. Lately I have been advocating a switch to postgres from various BigCo databases. I have been inferring that “postgres” is “just better”. But basically I don’t have a clue. I am not a database expert - and I did not take the advanced database classes in school. So - why I am I doing this?
Beating myself on the head with a wooden stick
I believe in having the source available for all my tools.This is just a personal preference of mine … I like to poke around to learn new stuff .. discover new ways and combine projects in new ways .. but mostly I like to learn from the insights of others. See implementation tidbits buried deep down. My list of projects to poke around in is long. Postgres is just one of the projects I’d like to poke around in. So - now I am going to poke around in postgres. Let’s see if we can compile it on window 7. I’ll just write down notes as I go along. Are you ready? Bring forward your wooden stick!
Checking out postgres on windows
So - the plan is to compile C/C++ code on windows. To do this you need a C/C++ compiler. I’ll just take the easy route here on windows and download Express 2012 for Windows Desktop . Note that you need to register to do this. Downloading and installing Visual Studio Express can take a while.
Then you need git . If you have been living under a rock for the last decade, then git is a distributed version control system - popularized by the linux kernel and github.com . You can grab a windows installer on git-scm.com . Go ahead and install it if you do not have it yet. You’ll be glad you did.
After installing git you can clone the postgres code base like this:
After a while then you should have the source code available . If you are like me ,then you’ll probably hurry into \build\postgresql\src and notice win32.make. Maybe this will work?
No luck! It fails with:
Luckily there is \build\postgresql\src\tools\msvc\build.pl .
Huh ? What’s *.pl files ? That’s perl. If you don’t know what perl is , then you are in for a treat. Grab active state perl and install it if you don’t have it yet, so you will be able to process the file.
Now. After installing perl, let’s cross our fingers and type
No?? msbuild throws up with:
Oh.you probably spotted it also. “Detected hardware platform: win32”. I ran this using the “Developer Command Prompt for VS2012” - maybe this targets win32 pr default? If I select “Microsoft Visual Studio 2012” > “Visual Studio Tools” > “VS2012 x64 Cross Tools Command Prompt” and execute “build” again - then it works!
After the compilation finished I typed:
Now I can use postgres from c:\postgres !
And now for something completely different
After finishing what I did above I throw out my custom compile and starting using the postgres zip archive again. I kept the code locally though. Right now I am poking around in the source code using “Run Source code analysis on solution”. This gives me the lowdown on what Microsoft thinks could be improved in the code. Let’s see an example:
Note that this is a random example. Right now I have a limited understanding of the postgresql codebase, so following the hardening guidelines from OWASP seems like a good idea.
But wait! There’s more
I like what I see. Looks like there is an active community for developers here . And . oh. Here is the official “Installation From Source on Windows” in the documentation. It looks solid. I’ll go check that out now :P