Re: Run a unix or perl command in a trigger

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: THIERRY(dot)MISSIMILLY(at)bull(dot)net (Thierry Missimilly)
Cc: pgsql-general(at)postgresql(dot)org (postgres general)
Subject: Re: Run a unix or perl command in a trigger
Date: 2004-07-03 13:33:47
Message-ID: 200407031333.i63DXlHW015538@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I wonder to know if it is possible to launch a Perl program or a unix
> comand in a trigger function.
> I have tried to do that in a C trigger developed with the SPI function.
> But my examples does not work and i don't have any error messages in the
> postgres logfile.
> So, i ask you your opinion and an example of code if your trigger works.

I guess I'm not sure what you mean by 'launch'. Do you need to query the
results?

Here's a plperlu function that runs an external shell script.

I've not tried it in a trigger, but it should work. This function
needs to be created as a superuser since it uses 'untrusted' perl.

It creates a security hole in that anyone who has write access to the
postgres user home directory can run ANYTHING.
--
Mike Nolan

create or replace function submit_batch(varchar, varchar)
returns varchar
security invoker
as '

# perl body goes here
# parameters: user ID
# batch id

$command = "/home/postgres/submit_batch.job "
. "$_[0]" . " " . "$_[1]" ;

$x = system($command);

return $x;
' language plperlu;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2004-07-03 13:48:25 Re: Problems restarting after database crashed (signal 11).
Previous Message Martin Marques 2004-07-03 13:11:32 Re: incremental backups?