PostGIS 2.0.1 Installation Gotcha

createdb: could not connect to database template1: FATAL: password authentication failed for user “postgres”

The short story If you are a hurry this is the essence of this post:

Problem:

You are trying to install PostGIS 2.0.1 on Windows, but you get an error and the error log says: createdb: could not connect to database template1: FATAL: password authentication failed for user "postgres"

Reason:

There is a bug in the PostGIS installer which causes the installer to fail when the password of the postgres user contains certain special characters.

Workaround:

Change the password of the postgres users so that it does not contain special characters and then reinstall PostGIS.

The longer story

If you have worked with GIS or spatial data you will most likely at some point run into PostGIS - the spatial extension for PostgreSql.

You happily go ahead and install PostgreSql 9.2 and set the password of the postgres user (which is superuser for PostgreSql) to pass^Word42. Yeah, upper, lower, numbers and special characters - super secure. Well, there’s you problem. The PostGIS installer fails if the passwords containing ^. When you go through your PostGIS installation wizard You’ll see this:

postgis installer wizard on the database connection step

And then when you click next this:

Error mesage popup "Database creation failed" during PostGIS install

In the error log you’ll see: createdb: could not connect to database template1: FATAL: password authentication failed for user "postgres"

error log screenshot

The next dialog prompts you to continue or abort the installation (abort is clicking ‘cancel’).

PostGIS installation warning - click cancel to abort installation

I think the easiest solution is to click cancel, change password for the postgres user to one without special characters and run the PostGIS installation again.

Not all special characters present a problem during installation. $ \ / ` ' " ; . + * @ all work fine, but ` ^ ´ & > ` fail as described above. ` failed and didn't write anything to the error log and the worst case < ` caused the installation to simply hang.

PostGIS can be installed on top of PostgreSql directly from the PostGIS installer or using PostgreSql’s stackbuilder. Stackbuilder is a GUI tool to help setting up the stack related to the PostgreSql database. But no matter if you install PostGIS from Stack Builder or from the PostGIS 2.0.1 installer directly this bug is present.

The bug is semi-officially recognized - see here or here

With that I wish you happy installation of PostGIS 2.0.1!