Re: executing os commands from a function

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: "Armand Pirvu (home)" <armand(dot)pirvu(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: executing os commands from a function
Date: 2016-09-30 15:36:01
Message-ID: CA+bJJbwWXUSKcWpxBnyDH8vPc=wk1sf3=iN6CsQ+QzvzAKN76A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Armand....

On Thu, Sep 29, 2016 at 11:41 PM, Armand Pirvu (home)
<armand(dot)pirvu(at)gmail(dot)com> wrote:
> I know this may sound like heresy since it involves executing an OS command from a function , but here goes
> After an insert in a table, I want to touch a file
....
> I used plsh extension but I had to use two functions and a trigger, see code below
....
> It works but can I be simpler ? Any other alternatives ? In Ingres for example I can use dbevent and an esqlc app which listens

If you are superuser ( which I supose you must be to execute plsh )
you could try to put code like this in a plpgsql, or may be even sql,
security definer ( or plain if not needed ) function:

( slighly sanitized )
In the psql prompt of a client machine:

n=# copy (select 1 as c where false) to '/tmp/ptxtst';
COPY 0

In the server machine:

postgres(at)server ~ $ stat /tmp/ptxtst
File: '/tmp/ptxtst'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 802h/2050d Inode: 4721101 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 70/postgres) Gid: ( 70/postgres)
Access: 2016-09-30 17:31:21.024617892 +0200
Modify: 2016-09-30 17:31:21.024617892 +0200
Change: 2016-09-30 17:31:21.024617892 +0200
Birth: -

Further details left for the reader.

Francisco Olarte.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2016-09-30 15:45:32 Re: executing os commands from a function
Previous Message Paul Jungwirth 2016-09-30 15:19:30 Re: Multi tenancy : schema vs databases