Testing Python and PostgreSQL on Windows, Part 5

I’ve got the Perl on Windows blues …

Aside from PL/pgSQL, the base distribution of PostgreSQL supports three procedural languages: Perl, Python and Tcl. When creating Pyrseas unit tests for languages (before they became EXTENSIONs), PL/Perl seemed like the “natural” choice. Perl is available on virtually all Linux and BSD base distributions, and (in contrast to Python) PL/Perl is available in both trusted and untrusted versions—a distinguishing attribute that the unit tests ought to check.

Alas, when testing on Windows I discovered that Perl isn’t as ubiquitous or as easy to deal with as it is on Linux.

The preliminary research prompted me to install Active Perl, specifically its Community Edition. Currently, the only two versions available are 5.14 and 5.16. Strangely enough, if you install one of those versions and then attempt to create the PL/Perl language under PG 8.4 or 9.0, the command succeeds, but when you try to create a function using plperl, you’ll see something like:

ERROR:  could not load library "C:/Program Files/PostgreSQL/8.4/lib/plperl.dll":
 The specified module could not be found.

Against PG 9.1 and 9.2, if you installed Perl 5.16, you’ll see the error message when issuing the CREATE EXTENSION (or LANGUAGE) statement. If you installed Perl 5.14, there should be no error.

When I first saw the error message, I was a bit puzzled since the plperl.dll libraries had all been installed and were located in the paths show in the messages. What “specified module” was missing?

Some web searching pointed me to Dependency Walker (depends.exe), a tool that appears to be indispensable if you’re going to be testing with multiple executable and DLL versions. It is analogous to Linux ldd. Depends.exe showed that plperl.dll in the 8.4 and 9.0 installations was linked with PERL510.DLL and in 9.1 and 9.2 with PER514.DLL.

Unfortunately, Active Perl has no Perl 5.10 Community Edition available, so off I was looking for an alternative. Thus I found Strawberry Perl.

The downside of Strawberry Perl’s installers is that they install it in C:\strawberry so you can’t have both Perl 5.10 and 5.14 at the same time. Someone on IRC explained that it is possible to install it in two separate paths (but it ain’t easy). For now, I chose to only install Perl 5.10. This allowed me to test Pyrseas using Python 2.7 and 3.2 against PostgreSQL 8.4, 9.0, 9.1 and 9.2, with only one Perl-related test faling (under PG 9.1 and 9.2, due to the absence of Perl 5.14).

A note of caution: Strawberry Perl installs GCC (3.4.5 in the Perl 5.10 version). If you have a pydistutils.cfg specifying a mingw32 compiler (as mentioned in my previous post), that may cause problems if you try to install or upgrade psycopg2 (or some other C extension module).

7 thoughts on “Testing Python and PostgreSQL on Windows, Part 5

    • For purposes of testing Pyrseas (whose unit tests only define some trivial Perl functions), maybe I could get away with copying PERL514.DLL to PERL510.DLL, but, if it works, that’s just a kludge, i.e., not recommended for anyone wanting to make serious use of PL/Perl under PG 8.4/9.0. A somewhat better “solution” may be to extract PERL510.DLL from a Strawberry Perl 5.10 ZIP file onto a Perl 5.14 installation, but that still looks like jury rigging.

  1. Very interesting post! Very usefull Dependency Walker and now I understand why I couldn’t make PL/Python work under PostgreSQL…

    • Hey Josep! I see that you are facing the same problem I have had. It’s been two days that I have been trying to wrap my finger around it. Have you figured out a solution? I have just installed PostgreSQL 9.2 and tried to activate PL/Python by using the normal commands of PGAdmin III (Windons 7). Thanks in advance!

      • Hi Lucio, it seems that the default PG 9.2 install (as well as 9.1) only installs plpython3u, i.e., I only see plpython3.dll in the lib directories. So it fails when you try to CREATE EXTENSION plpythonu, but it does work if you do CREATE EXTENSION plpython3u (assuming you have Python 3.2 or 3.3 installed). If you need Python 2.x support on PG 9.2, it may be best to ask on the PG mailing lists or on IRC.

  2. Pingback: Testing Python and PostgreSQL on Windows, Part 6 | Taming Serpents and Pachyderms

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.