Thread: How can exe files such as 'pg_dump' be called from stored functions?
Hello, Thanks for your attention. I would like to ask a question about how exe files such as 'pg_dump' can be called from stored functions. For example, a simple C code like below -------------------------------------------------------------------------------------------------------------------- int main(int argc, char **argv) { system("pg_dump -f /path/to/output/file database_name"); return 1; } -------------------------------------------------------------------------------------------------------------------- can execute 'pg_dump', which produces an output file. However, when I made it as a stored function in C, it didn't work. Within the stored function, I used the exact same 'system' command. The other parts within the function such as getting input values, calculating, and returning outputs works and no error is produced. It looks that just the system("pg_dump"); command is passed without outputting anything. I also tried to use plperlu language for this, but my results so far are very similar. When I use it as a stored function, system("pg_dump") command doesn't seem to do anything. If some can tell me how exe files such as 'pg_dump' can be called from stored functions, I would appreciate it. Thanks for your help. Sam
"Satoru Fukushima" <satoruf@gmail.com> writes: > can execute 'pg_dump', which produces an output file. However, when I > made it as a stored function in C, it didn't work. Within the stored > function, I used the exact same 'system' command. The other parts > within the function such as getting input values, calculating, and > returning outputs works and no error is produced. It looks that just > the system("pg_dump"); command is passed without outputting anything. Are you making any effort at all to check for errors? It's not apparent from this code... The simplest approach to debugging this might be to dump stderr into some file, say system("pg_dump -f /path/to/output/file database_name 2>/tmp/pgdumperrs"); and see what ends up in that file. regards, tom lane
Tom Lane wrote:
Cheers,
Steve
Like, perhaps, the owner of the PostgreSQL server process having no permission to write into /path/to/output/file?"Satoru Fukushima" <satoruf@gmail.com> writes:can execute 'pg_dump', which produces an output file. However, when I made it as a stored function in C, it didn't work. Within the stored function, I used the exact same 'system' command. The other parts within the function such as getting input values, calculating, and returning outputs works and no error is produced. It looks that just the system("pg_dump"); command is passed without outputting anything.Are you making any effort at all to check for errors? It's not apparent from this code... The simplest approach to debugging this might be to dump stderr into some file, say system("pg_dump -f /path/to/output/file database_name 2>/tmp/pgdumperrs"); and see what ends up in that file.
Cheers,
Steve
Re: How can exe files such as 'pg_dump' be called from stored functions?
From
"Satoru Fukushima"
Date:
Steve, you're right! After permission was changed, the function works! Thanks Tom, too! When I wrote my entry, although I had tried to debug by outputting errors using '<', I used it to the same directory as the output file, which prevented any message from appearing because of the same permission issue. This active mailinglist is very helpful for a novice as myself. Thanks a lot! Sam On Feb 7, 2008 6:29 PM, Steve Crawford <scrawford@pinpointresearch.com> wrote: > > Tom Lane wrote: > > "Satoru Fukushima" <satoruf@gmail.com> writes: > > > can execute 'pg_dump', which produces an output file. However, when I > made it as a stored function in C, it didn't work. Within the stored > function, I used the exact same 'system' command. The other parts > within the function such as getting input values, calculating, and > returning outputs works and no error is produced. It looks that just > the system("pg_dump"); command is passed without outputting anything. > > Are you making any effort at all to check for errors? It's not apparent > from this code... > > The simplest approach to debugging this might be to dump stderr into > some file, say > > system("pg_dump -f /path/to/output/file database_name 2>/tmp/pgdumperrs"); > > and see what ends up in that file. > > Like, perhaps, the owner of the PostgreSQL server process having no > permission to write into /path/to/output/file? > > Cheers, > Steve >