Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with $libdir on PostgreSQL

In short, my question is "why doesn't $libdir work on my PSQL installation."

CREATE FUNCTION st_box2d_in(cstring) RETURNS box2d
    AS '$libdir/liblwgeom', 'BOX2DFLOAT4_in'
    LANGUAGE c IMMUTABLE STRICT;

yields an error

could not access file "$libdir/liblwgeom": No such file or directory

while

CREATE FUNCTION st_box2d_in(cstring) RETURNS box2d
    AS '/usr/local/pgsql/lib/liblwgeom', 'BOX2DFLOAT4_in'
    LANGUAGE c IMMUTABLE STRICT;

works correctly.

The output of

% pg_config --pkglibdir
/usr/local/pgsql/lib

appears to be correct.

like image 384
Joe Germuska Avatar asked Aug 28 '09 19:08

Joe Germuska


2 Answers

I struggled with this error as well. I solved it by linking in the PostGIS lib manually to the liblwgeom file, like this:

ln -s /usr/lib/postgis/1.5.1/postgres/8.4/lib/postgis-1.5.so 
    /usr/lib/postgresql/8.4/lib/liblwgeom

I have no idea why PostGIS installs itself in the 'wrong' directory, or why PostgreSQL looks for a file named liblwgeom when it seems to be the same file which PostGIS calls postgis-1.5.so

All I know is that that seems to have fixed my problem.

like image 151
Johan.l Avatar answered Nov 05 '22 07:11

Johan.l


Edited out original reply for it was wrong

Now that I've looked up postgresql code I have to admit that this string is supposed to be expanded since 2001 ;-). The expansion is very limited though. It only expands $libdir followed by directory separator. Still, your output indicates that the string wasn't expanded, because the reported string here is the string actually used for loading library.

That means that substitution failed. Looking at it closer I can see that the expansion only succeeds if target file actually exists. Assuming your directory separator is / and DLSUFFIX is .so and the file /usr/local/pgsql/lib/liblwgeom.so actually exists, I have no faintest clue why the hell it fails ;-)

like image 1
Michael Krelin - hacker Avatar answered Nov 05 '22 06:11

Michael Krelin - hacker