This is a discussion on Dynamic loading of C functions within the Pgsql General forums, part of the PostgreSQL category; --> I've written a function in C, compiled it and trying to use the same function in one of my ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I've written a function in C, compiled it and trying to use the same function in one of my postgres functions like this: CREATE FUNCTION add_one(integer) RETURNS integer AS '/usr/include/pgsql/server/test_func, 'add_one' LANGUAGE C STRICT test_func is the name of my object file and add_one is the name of the function i want to call from test_func.c C file. I get the follwing error ERROR: could not access file "/usr/include/pgsql/server/test_func": No such file or directory /usr/include/pgsql/server/ is exactly the path where test_func object file resides. Don't know why isn't postgres able to find it there. Any kind of help would be appreciated. ~Jas |
| |||
| In response to "Jasbinder Bali" <jsbali@gmail.com>: > I've written a function in C, compiled it and trying to use the same > function in one of my postgres functions like this: > > CREATE FUNCTION add_one(integer) RETURNS integer > AS '/usr/include/pgsql/server/test_func, 'add_one' > LANGUAGE C STRICT > > test_func is the name of my object file and add_one is the name of > the function i want to call from test_func.c C file. > > I get the follwing error > ERROR: could not access file "/usr/include/pgsql/server/test_func": No such > file or directory > > /usr/include/pgsql/server/ is exactly the path where test_func object file > resides. > Don't know why isn't postgres able to find it there. > > Any kind of help would be appreciated. Check the permissions. Can the Postgres user read the file? I don't remember if it has to be marked executable or not, but that's something to check. -- Bill Moran Collaborative Fusion Inc. ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |
| |||
| Bill Moran <wmoran@collaborativefusion.com> writes: > In response to "Jasbinder Bali" <jsbali@gmail.com>: >> I get the follwing error >> ERROR: could not access file "/usr/include/pgsql/server/test_func": No such >> file or directory > Check the permissions. Can the Postgres user read the file? The error is pretty clearly "file not found", not "no permissions". One possibility is that the complaint is not about this file itself but about some other shared library it depends on. Try "ldd" or local equivalent on the file to see if it shows any unresolved references. Also, you might try looking in the postmaster log to see if any additional info appears there --- anything the dynamic linker spit out to stderr is not going to appear on your terminal. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| |||
| In response to Tom Lane <tgl@sss.pgh.pa.us>: > Bill Moran <wmoran@collaborativefusion.com> writes: > > In response to "Jasbinder Bali" <jsbali@gmail.com>: > >> I get the follwing error > >> ERROR: could not access file "/usr/include/pgsql/server/test_func": No such > >> file or directory > > > Check the permissions. Can the Postgres user read the file? > > The error is pretty clearly "file not found", not "no permissions". Hmmm ... I was getting PostgreSQL confused with other software that provides less precise errors. My apologies. -- Bill Moran Collaborative Fusion Inc. ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org |
| |||
| chmod 666 filename is something i've done to give permissions to all.. still doesn't work. On 6/20/06, Bill Moran <wmoran@collaborativefusion.com> wrote: > > In response to "Jasbinder Bali" <jsbali@gmail.com>: > > > I've written a function in C, compiled it and trying to use the same > > function in one of my postgres functions like this: > > > > CREATE FUNCTION add_one(integer) RETURNS integer > > AS '/usr/include/pgsql/server/test_func, 'add_one' > > LANGUAGE C STRICT > > > > test_func is the name of my object file and add_one is the name of > > the function i want to call from test_func.c C file. > > > > I get the follwing error > > ERROR: could not access file "/usr/include/pgsql/server/test_func": No > such > > file or directory > > > > /usr/include/pgsql/server/ is exactly the path where test_func object > file > > resides. > > Don't know why isn't postgres able to find it there. > > > > Any kind of help would be appreciated. > > Check the permissions. Can the Postgres user read the file? > > I don't remember if it has to be marked executable or not, but that's > something to check. > > -- > Bill Moran > Collaborative Fusion Inc. > |
| |||
| Do you need to specify ....test_func.so not ...test_func or has that changed? --elein On Tue, Jun 20, 2006 at 05:13:32PM -0400, Jasbinder Bali wrote: > chmod 666 filename is something i've done to give permissions to all.. > still doesn't work. > > > On 6/20/06, Bill Moran <wmoran@collaborativefusion.com> wrote: > > In response to "Jasbinder Bali" <jsbali@gmail.com>: > > > I've written a function in C, compiled it and trying to use the same > > function in one of my postgres functions like this: > > > > CREATE FUNCTION add_one(integer) RETURNS integer > > AS '/usr/include/pgsql/server/test_func, 'add_one' > > LANGUAGE C STRICT > > > > test_func is the name of my object file and add_one is the name of > > the function i want to call from test_func.c C file. > > > > I get the follwing error > > ERROR: could not access file "/usr/include/pgsql/server/test_func": No > such > > file or directory > > > > /usr/include/pgsql/server/ is exactly the path where test_func object > file > > resides. > > Don't know why isn't postgres able to find it there. > > > > Any kind of help would be appreciated. > > Check the permissions. Can the Postgres user read the file? > > I don't remember if it has to be marked executable or not, but that's > something to check. > > -- > Bill Moran > Collaborative Fusion Inc. > > ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| |||
| "Jasbinder Bali" <jsbali@gmail.com> writes: >>> /usr/include/pgsql/server/ is exactly the path where test_func object >>> file resides. Hmmm .... when you say "object file", do you mean it's really named "test_func.o"? If so, that's both the wrong name and the wrong type of file. Postgres is looking for a shared library, eg "test_func.so" (or on some platforms ".sl" or ".dylib"). There's some advice in our manual about the compiler switches to use to create a shared library, or see your compiler documentation. Given AS '/usr/include/pgsql/server/test_func', Postgres will look for both "test_func" and "test_func.so" (not sure which order, try the LOAD reference page for details). It won't look for "test_func.o" though. BTW, most people would say that /usr/include is exactly where NOT to put an executable file ... conventionally this kind of file goes under /usr/lib. That's not what's causing your problem, it's just a question of keeping your filesystem tidy enough to be able to find things again. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |
| |||
| yes, i've named it as .so file. On 6/20/06, Tom Lane <tgl@sss.pgh.pa.us> wrote: > > "Jasbinder Bali" <jsbali@gmail.com> writes: > >>> /usr/include/pgsql/server/ is exactly the path where test_func object > >>> file resides. > > Hmmm .... when you say "object file", do you mean it's really named > "test_func.o"? > > If so, that's both the wrong name and the wrong type of file. Postgres > is looking for a shared library, eg "test_func.so" (or on some platforms > ".sl" or ".dylib"). There's some advice in our manual about the > compiler switches to use to create a shared library, or see your > compiler documentation. > > Given AS '/usr/include/pgsql/server/test_func', Postgres will look for > both "test_func" and "test_func.so" (not sure which order, try the LOAD > reference page for details). It won't look for "test_func.o" though. > > BTW, most people would say that /usr/include is exactly where NOT to > put an executable file ... conventionally this kind of file goes under > /usr/lib. That's not what's causing your problem, it's just a question > of keeping your filesystem tidy enough to be able to find things again. > > regards, tom lane > |
| |||
| Was the object compiled on the same architecture as postgres? Sometimes when one is compiled on a 64-bit, the other on 32-bit, or two wildly different versions of gcc, I have seen this cryptic "No such file or directory". Erin On 6/20/06, Jasbinder Bali <jsbali@gmail.com> wrote: > > chmod 666 filename is something i've done to give permissions to all.. > still doesn't work. > > > > On 6/20/06, Bill Moran <wmoran@collaborativefusion.com> wrote: > > In response to "Jasbinder Bali" <jsbali@gmail.com>: > > > > > I've written a function in C, compiled it and trying to use the same > > > function in one of my postgres functions like this: > > > > > > CREATE FUNCTION add_one(integer) RETURNS integer > > > AS '/usr/include/pgsql/server/test_func, 'add_one' > > > LANGUAGE C STRICT > > > > > > test_func is the name of my object file and add_one is the name of > > > the function i want to call from test_func.c C file. > > > > > > I get the follwing error > > > ERROR: could not access file > "/usr/include/pgsql/server/test_func": No such > > > file or directory > > > > > > /usr/include/pgsql/server/ is exactly the path where test_func object > file > > > resides. > > > Don't know why isn't postgres able to find it there. > > > > > > Any kind of help would be appreciated. > > > > Check the permissions. Can the Postgres user read the file? > > > > I don't remember if it has to be marked executable or not, but that's > > something to check. > > > > -- > > Bill Moran > > Collaborative Fusion Inc. > > > > ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match |
| ||||
| I've tried everything so that my .so file is recognized but in vein. Don't know whats going wrong. ~Jas On 6/20/06, Tom Lane <tgl@sss.pgh.pa.us> wrote: > > Bill Moran <wmoran@collaborativefusion.com> writes: > > In response to "Jasbinder Bali" <jsbali@gmail.com>: > >> I get the follwing error > >> ERROR: could not access file "/usr/include/pgsql/server/test_func": No > such > >> file or directory > > > Check the permissions. Can the Postgres user read the file? > > The error is pretty clearly "file not found", not "no permissions". > > One possibility is that the complaint is not about this file itself > but about some other shared library it depends on. Try "ldd" or > local equivalent on the file to see if it shows any unresolved > references. > > Also, you might try looking in the postmaster log to see if any > additional info appears there --- anything the dynamic linker spit out > to stderr is not going to appear on your terminal. > > regards, tom lane > |