Re: Query on support for trigger functions defined in a Shared library in Windows

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Query on support for trigger functions defined in a Shared library in Windows

Mehul Doshi-A20614

Hi,

This is related to the problem that I faced some time ago. I have
created a dll library file with inbuilt constraints and triggers.
I also built the same for Linux environment. Here's what I am facing.
Any clues as to what I am doing wrong?

Linux: Fedora Core 2 Running Postgresql 7.4.2
Windows: Windows XP Service Pack 2 running PostgreSQL 8.1.2

The testtrigfuncs.dll is placed in C:\Program Files\Test\lib\ directory
and in Linux it is placed in /opt/WMS/rel/lib/testtrigfuncs.so

On linux when I do the following it works:
createdb test
test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
trigger
test-#   AS '/opt/WMS/rel/lib/testtrigfuncs.so'
test-#   LANGUAGE C ;
CREATE FUNCTION
test=#

On Windows for the same I get: (Includes extra \ to account for Windows)

test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
trigger
test-#   AS 'C:\\Program Files\\Test\\lib\\testtrigfuncs.dll'
test-#   LANGUAGE C ;
ERROR:  could not load library "C:\Program
Files\Test\lib\testtrigfuncs.dll": The specified module could not be
found.

I went and modified the dynamic_library_path to
dynamic_library_path = 'C:\Program Files\Test\lib;$libdir'

I also added C:\Program Files\Test\lib to the PATH variable. I restarted
postgres service and then retried the below.

test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
trigger
test-#   AS 'C:\Program Files\Test\lib\testtrigfuncs.dll'
test-#   LANGUAGE C ;
ERROR:  component in parameter "dynamic_library_path" is not an absolute
path
test=#

What is this absolute path? Where do I set it? While I know that if I
place
testtrigfuncs.dll in C:\Program Files\PostgreSQL\8.1\bin folder and do
the
same it works.

test=# CREATE OR REPLACE FUNCTION trigf_stdhlr_pid_insert() RETURNS
trigger
test-#   AS 'C:\\Program Files\\PostgreSQL\\8.1\\bin\\testtrigfuncs.dll'
test-#   LANGUAGE C ;
CREATE FUNCTION
test=#

Any clues on what I need to do to go ahead would be great. I want to be
able to do the
same thing on both Linux and Windows without having to write in
PostgreSQL\bin folder
where my program has no use of being there.

Thanks & Regards,
Mehul



-----Original Message-----
From: Mehul Doshi-A20614
Sent: Wednesday, July 27, 2005 8:35 AM
To: 'Magnus Hagander'; [hidden email]
Cc: Mehul Doshi-A20614
Subject: RE: [pgsql-hackers-win32] Query on support for trigger
functions defined in a Shared library in Windows



Hi Magnus,

Thanks. That helped me. I used MingW to compile the code. I still used
8.0.0 because it is the version that we are currently working on. I will
migrate to 8.0.3 once I am Able to validate the entire setup.

I did get another problem, if you could help me out, it would be great.
Problem Description:
1) I generated the dll using the code.
2) Added the following in postgresql.conf:
dynamic_library_path = 'C:\test\lib,$libdir'
The above didn't work so I went ahead and copied the dll into C:\Program
Files\PostgreSQL\8.0\lib\
3) I restarted the postmaster both times. I got this error both times.
:25: ERROR:  could not load library "C:/Program
Files/PostgreSQL/8.0/lib/testtrigfuncs.dll": dynamic load error

The log shows:
2005-07-26 22:38:07 DEBUG:  InitPostgres
2005-07-26 22:38:07 DEBUG:  StartTransaction
2005-07-26 22:38:07 DEBUG:  name: unnamed; blockState:       DEFAULT;
state: INPROGR, xid/subid/cid: 33475/1/0, nestlvl: 1, children: <>
2005-07-26 22:38:07 DEBUG:  CommitTransaction
2005-07-26 22:38:07 DEBUG:  name: unnamed; blockState:       STARTED;
state: INPROGR, xid/subid/cid: 33475/1/0, nestlvl: 1, children: <>
2005-07-26 22:38:07 DEBUG:  StartTransactionCommand
2005-07-26 22:38:07 DEBUG:  StartTransaction
2005-07-26 22:38:07 DEBUG:  name: unnamed; blockState:       DEFAULT;
state: INPROGR, xid/subid/cid: 33476/1/0, nestlvl: 1, children: <>
2005-07-26 22:38:07 DEBUG:  ProcessUtility
2005-07-26 22:38:07 DEBUG:  find_in_dynamic_libpath: trying "C:/Program
Files/PostgreSQL/8.0/lib/testtrigfuncs.dll"
2005-07-26 22:38:07 ERROR:  could not load library "C:/Program
Files/PostgreSQL/8.0/lib/testtrigfuncs.dll": dynamic load error
2005-07-26 22:38:07 DEBUG:  proc_exit(0)
2005-07-26 22:38:07 DEBUG:  shmem_exit(0)
2005-07-26 22:38:07 DEBUG:  exit(0)

However, when I ran the newly compiled postgres code (along with my test
dll in /usr/local/pgsql/lib) via msys. It didn't give me any such errors
and everything worked out fine. I don't know what I need to do to make
this dll which I built run with the already installed version of
PostgreSQL (8.0.0). I can upgrade it to 8.0.3 if it solves the problem.

Please let me know. Thanks & have a nice day.


Thanks & Regards,
Mehul

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [hidden email] so that your
       message can get through to the mailing list cleanly
Reply | Threaded
Open this post in threaded view
|

Re: Query on support for trigger functions defined in a Shared library in Windows

Magnus Hagander
> On Windows for the same I get: (Includes extra \ to account
> for Windows)
>
> test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert()
> RETURNS trigger
> test-#   AS 'C:\\Program Files\\Test\\lib\\testtrigfuncs.dll'
> test-#   LANGUAGE C ;
> ERROR:  could not load library "C:\Program
> Files\Test\lib\testtrigfuncs.dll": The specified module could
> not be found.
>
> I went and modified the dynamic_library_path to
> dynamic_library_path = 'C:\Program Files\Test\lib;$libdir'
>
> I also added C:\Program Files\Test\lib to the PATH variable.
> I restarted postgres service and then retried the below.

Are you sure you added this to the SYSTEM path and not the USER path?
Because if it's the second, it won't affect the pg service. I'd also try
a reboot after changing the one in SYSTEM - I've seen cases where it
didn't "take" even if the service was restarted.

//Magnus

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Reply | Threaded
Open this post in threaded view
|

Re: Query on support for trigger functions defined in a Shared library in Windows

Reini Urban
In reply to this post by Mehul Doshi-A20614
2006/1/24, Mehul Doshi-A20614 <[hidden email]>:

> This is related to the problem that I faced some time ago. I have
> created a dll library file with inbuilt constraints and triggers.
> I also built the same for Linux environment. Here's what I am facing.
> Any clues as to what I am doing wrong?
>
> Linux: Fedora Core 2 Running Postgresql 7.4.2
> Windows: Windows XP Service Pack 2 running PostgreSQL 8.1.2
>
> The testtrigfuncs.dll is placed in C:\Program Files\Test\lib\ directory
> and in Linux it is placed in /opt/WMS/rel/lib/testtrigfuncs.so
>
> On linux when I do the following it works:
> createdb test
> test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
> trigger
> test-#   AS '/opt/WMS/rel/lib/testtrigfuncs.so'
> test-#   LANGUAGE C ;
> CREATE FUNCTION
> test=#
>
> On Windows for the same I get: (Includes extra \ to account for Windows)
>
> test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
> trigger
> test-#   AS 'C:\\Program Files\\Test\\lib\\testtrigfuncs.dll'
> test-#   LANGUAGE C ;
> ERROR:  could not load library "C:\Program
> Files\Test\lib\testtrigfuncs.dll": The specified module could not be
> found.

Surround the path with extra "" because of the space in the path.

AS '"C:\\Program Files\\Test\\lib\\testtrigfuncs.dll"'

Or better move your lib to a path without spaces.

> I went and modified the dynamic_library_path to
> dynamic_library_path = 'C:\Program Files\Test\lib;$libdir'
>
> I also added C:\Program Files\Test\lib to the PATH variable. I restarted
> postgres service and then retried the below.
>
> test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
> trigger
> test-#   AS 'C:\Program Files\Test\lib\testtrigfuncs.dll'
> test-#   LANGUAGE C ;
> ERROR:  component in parameter "dynamic_library_path" is not an absolute
> path
> test=#
>
> What is this absolute path? Where do I set it? While I know that if I
> place
> testtrigfuncs.dll in C:\Program Files\PostgreSQL\8.1\bin folder and do
> the
> same it works.
>
> test=# CREATE OR REPLACE FUNCTION trigf_stdhlr_pid_insert() RETURNS
> trigger
> test-#   AS 'C:\\Program Files\\PostgreSQL\\8.1\\bin\\testtrigfuncs.dll'
> test-#   LANGUAGE C ;
> CREATE FUNCTION
> test=#
>
> Any clues on what I need to do to go ahead would be great. I want to be
> able to do the
> same thing on both Linux and Windows without having to write in
> PostgreSQL\bin folder
> where my program has no use of being there.
>
> Thanks & Regards,
> Mehul
>
>
>
> -----Original Message-----
> From: Mehul Doshi-A20614
> Sent: Wednesday, July 27, 2005 8:35 AM
> To: 'Magnus Hagander'; [hidden email]
> Cc: Mehul Doshi-A20614
> Subject: RE: [pgsql-hackers-win32] Query on support for trigger
> functions defined in a Shared library in Windows
>
>
>
> Hi Magnus,
>
> Thanks. That helped me. I used MingW to compile the code. I still used
> 8.0.0 because it is the version that we are currently working on. I will
> migrate to 8.0.3 once I am Able to validate the entire setup.
>
> I did get another problem, if you could help me out, it would be great.
> Problem Description:
> 1) I generated the dll using the code.
> 2) Added the following in postgresql.conf:
> dynamic_library_path = 'C:\test\lib,$libdir'
> The above didn't work so I went ahead and copied the dll into C:\Program
> Files\PostgreSQL\8.0\lib\
> 3) I restarted the postmaster both times. I got this error both times.
> :25: ERROR:  could not load library "C:/Program
> Files/PostgreSQL/8.0/lib/testtrigfuncs.dll": dynamic load error
>
> The log shows:
> 2005-07-26 22:38:07 DEBUG:  InitPostgres
> 2005-07-26 22:38:07 DEBUG:  StartTransaction
> 2005-07-26 22:38:07 DEBUG:  name: unnamed; blockState:       DEFAULT;
> state: INPROGR, xid/subid/cid: 33475/1/0, nestlvl: 1, children: <>
> 2005-07-26 22:38:07 DEBUG:  CommitTransaction
> 2005-07-26 22:38:07 DEBUG:  name: unnamed; blockState:       STARTED;
> state: INPROGR, xid/subid/cid: 33475/1/0, nestlvl: 1, children: <>
> 2005-07-26 22:38:07 DEBUG:  StartTransactionCommand
> 2005-07-26 22:38:07 DEBUG:  StartTransaction
> 2005-07-26 22:38:07 DEBUG:  name: unnamed; blockState:       DEFAULT;
> state: INPROGR, xid/subid/cid: 33476/1/0, nestlvl: 1, children: <>
> 2005-07-26 22:38:07 DEBUG:  ProcessUtility
> 2005-07-26 22:38:07 DEBUG:  find_in_dynamic_libpath: trying "C:/Program
> Files/PostgreSQL/8.0/lib/testtrigfuncs.dll"
> 2005-07-26 22:38:07 ERROR:  could not load library "C:/Program
> Files/PostgreSQL/8.0/lib/testtrigfuncs.dll": dynamic load error
> 2005-07-26 22:38:07 DEBUG:  proc_exit(0)
> 2005-07-26 22:38:07 DEBUG:  shmem_exit(0)
> 2005-07-26 22:38:07 DEBUG:  exit(0)
>
> However, when I ran the newly compiled postgres code (along with my test
> dll in /usr/local/pgsql/lib) via msys. It didn't give me any such errors
> and everything worked out fine. I don't know what I need to do to make
> this dll which I built run with the already installed version of
> PostgreSQL (8.0.0). I can upgrade it to 8.0.3 if it solves the problem.
>
> Please let me know. Thanks & have a nice day.
>
>
> Thanks & Regards,
> Mehul
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to [hidden email] so that your
>        message can get through to the mailing list cleanly
>


--
Reini Urban
http://phpwiki.org/
http://spacemovie.mur.at/

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org
Reply | Threaded
Open this post in threaded view
|

Re: Query on support for trigger functions defined in a Shared library in Windows

Mehul Doshi-A20614
In reply to this post by Mehul Doshi-A20614

Hi,

Here's a weird scenario that seems to be coming out of so many different
options.
a) When the dll is placed in C:\Program Files\PostgreSQL\8.0\bin it
works.
b) When the dll is placed in C:\Program Files\Test\lib, it fails if
dynamic_library_path is set to 'C:\Program Files\Test\lib;$libdir'

However I had help from two people on this,
i) Jean Marc: Replace \ with / i.e dynamic_library_path is set to
'C:/Program Files/Test/lib;$libdir'
ii) Thomas Hallgreen: Do \\ instead of just \. i.e. dynamic_library_path
is set to 'C:\\Program Files\\Test\\lib;$libdir'

Now both of these "start to" work after some time only. There is no
logic that I can explain as to how they work.
Here's what I have tried to do to understand this behavior.

a) Uninstall postgres completely and delete the data folder.
b) Re-install Postgres.
c) Modify the postgresql.conf file with either of the methods. I used
method (ii) since it is more Windows like.
d) Modify the System Variable PATH to contain the extra term "C:\Program
Files\Test\lib"
d) Now I stop the service, start the service. I even rebooted my system.
e) On a new command prompt, I test it out ... Error as before. I can
verify the PATH variable does have C:\Program Files\Test\lib in it.
f) Anyways since I can't do much, I go back and add the dll to the bin
folder and start using it.
g) I can now go back to first command prompt and retest it starts to
work!!!. It works with libdir.
i)I can also go back and modify and delete the dll file that I placed in
the bin folder.
j) I can again retest the dll and it works fine.

Infact it starts to take the dynamic path perfectly.
test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
trigger
test-#   AS 'testrigfuncs'
test-#   LANGUAGE C ;
CREATE FUNCTION
test=# \q

I have tried this on 4 different systems running Windows XP (Service
Packs 1 & 2) using PostgreSQL 8.0 as well as PostgreSQL 8.1.
Any clues as to why it won't work till I placed the dll in
Postgresql\bin folder and then once I have placed the dll there and
used it, it starts to work at either places even if I delete the dll
from the bin folder.

Thanks & Regards,
Mehul


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Magnus
Hagander
Sent: Friday, January 27, 2006 2:32 AM
To: Mehul Doshi-A20614; [hidden email]
Subject: Re: [pgsql-hackers-win32] Query on support for trigger
functions defined in a Shared library in Windows

> On Windows for the same I get: (Includes extra \ to account for
> Windows)
>
> test=# CREATE OR REPLACE FUNCTION trigf_test_pid_insert() RETURNS
> trigger
> test-#   AS 'C:\\Program Files\\Test\\lib\\testtrigfuncs.dll'
> test-#   LANGUAGE C ;
> ERROR:  could not load library "C:\Program
> Files\Test\lib\testtrigfuncs.dll": The specified module could not be
> found.
>
> I went and modified the dynamic_library_path to dynamic_library_path =

> 'C:\Program Files\Test\lib;$libdir'
>
> I also added C:\Program Files\Test\lib to the PATH variable.
> I restarted postgres service and then retried the below.

Are you sure you added this to the SYSTEM path and not the USER path?
Because if it's the second, it won't affect the pg service. I'd also try
a reboot after changing the one in SYSTEM - I've seen cases where it
didn't "take" even if the service was restarted.

//Magnus

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster