Solved

triggers in background

Posted on 2004-08-24
7
705 Views
Last Modified: 2012-05-05
Hi all,

in postgresql 7.x,

is there a way to run trigger in background mode ?

What I need is :
 - When a table insert/update/delete, my trigger is running immediately.
But I don't want to wait for trigger's result. My function/procedure will return, trigger will continue to run, even it successfull or not.
Scenerio is something like this.
- I call a function
- The functions inserts or updates a table.
- Trigger relaled to this table fired AFTER INSERT/UPDATE
- Trigger return RETURN NEW always.  But need to be do some works during.
I don't care these works ended or not.

In this scenerio, since trigger running,  my function which has been insert/update the table  does NOT return.

I I want it to be finished as soon as possible. after INSERT/UPDATE without waiting trigger's operation.


0
Comment
Question by:Ege
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:rjkimble
ID: 11882965
My guess is that the answer to your question is no. I have encountered situations similar to this, and my approach has been to run an outside cron job periodically -- generally every 5 minutes or so -- and look for new work to be done. You can use your trigger to insert a row in a table that represents a queue of work to be done. The cron job then comes along and looks for records in that queue. If it finds one or more records waiting, it runs a script for each. As it finishes the work for a record, it deletes that record from the table, or it sets a flag indicating that the corresponding task has been accomplished. That strategy has worked well for me.
0
 
LVL 1

Author Comment

by:Ege
ID: 11884276
Sorry,
Guess is not enough to accept. ;)

However, I think your guess is true (I also guess like that)
But, there may be trick. So 250points question I asked.

If not, I hope to be added later. Just running an external program with linux like permissions. Nothing more. This is something like a trigger.
For non SQL operations to be done.
At least for my scenerio, I need it. Instead of running an external program which checks the database from time to time, running it just like a trigger will be better for my project.

PostgreSQL TRUSTED LANGUAGE C supports all functioanlity of C ?

If C language (since PHP as a postgresql language has too many limitations) has no limitation, then it is good.

For example, (not with plpgsql, but C),
I an URL inserted to TABLE,
then can I connect to the URL to get some information inside trigger?
with C like created trigger.

If so, then it is also good for my project. In fact, instead of not waiting triggers result, this POINT is most usufull.

Best regards.

0
 
LVL 9

Expert Comment

by:rjkimble
ID: 11884432
You could install PL/Python and use it inside your trigger. That could shell out to the OS and start an external command. That might be a way to accomplish what you want. I have no experience doing that, however.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:Ege
ID: 11884476
I don't know PL/Python.
I can use, C, PL/PgSQL, PHP only.

If I can do it by using PL/Python, then I can do it by using C!

or not.

;(
0
 
LVL 9

Expert Comment

by:rjkimble
ID: 11884797
Yes -- I suspect you'll be able to do what you want using C.
0
 
LVL 1

Author Comment

by:Ege
ID: 11910286
you will got the points by giving a running example.

Or anybody who gave a running sample, please.

;)

- eGe
0
 
LVL 3

Accepted Solution

by:
gnudiff earned 250 total points
ID: 11911279
Meaybe a working sample from documentation will work?

http://www.postgresql.org/docs/current/static/trigger-example.html

It shows a complete C example of a trigger function along with neccessary SQL, for PostGres 7.4.
Adding neccessary calls to the trigger to exec some background task (or better pass a message to some daemon which accepts and processes those independently of PG application) should be trivial.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question