[Tip] PostgreSQL Tip of the Day - loading a PostGIS database dump

| No Comments | No TrackBacks

I was given a Postgres database dump to analyze today created by "pg_dump -Fc". The source database included PostGIS 1.3.x extensions. I'm not sure if this is standard with PostGIS, but the related database objects were all dumped with a hard-coded library path, specifically /usr/lib/postgresql/8.3/lib. On my machine, I have many PostgreSQL clusters (essentially at least one for every supported branch dating back to 7.3.x), but they are not located under /usr/lib/postgresql.

As such, I needed a quick fix. To wit:

pg_restore database.with.postgis.tgz > db.w.postgis.dmp
sed 's|/usr/lib/postgresql/8.3/lib|$libdir|g' < db.w.postgis.dmp > db.w.postgis.dmp.new

The first line extracts the dump file from the compressed "custom" format into a human readable text SQL file. The second line replaces the hard-coded library path with the special PostgreSQL $libdir variable. This will always point to the correct location for any given PostgreSQL cluster. You can always discover where this is by running:

pg_config --libdir

No TrackBacks

TrackBack URL: http://blog.credativ.com/mt-tb.cgi/177

Leave a comment