Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm trying to make a system where one computer (let's call it the server) updates it's status to a database. All other computers in the network read the most current information about the server from the database.
But, when an alarm or error occurs on the server, it has to update the server, AND the computers in the network have to be informed immediately about the error.
I was thinking about solving it this way:
- Let the server update all info in the database (PostgreSQL)
- When an alarm is inserted or removed, the database will call a trigger
- The trigger runs a program which opens a socket connection to all computers in the network, and send a message that a new alarm has occured
- The computers immediately get the alarm-info from the database
Is this the best sollution, or is there any better/faster/more direct way of doing this? And is it possible for PostgreSQL to call an external program when a trigger is called?
I'm not quite sure what exactly you are
trying to achieve, but PostgreSQL's
triggers are flexible enough to more
or less do anything that's possible in
any language known to Postgres (except
for plain SQL :}) ... you could make
a trigger stop and start any process
(that's what the interface description
says, I haven't tried it yet, though ;})
Thank you for your information. You said triggers can do almost everything possible in any known language, but the only information I can find on triggers are the triggers that when some data is inserted into the database, the trigger can make changes only within the database.
What I'm trying is this:
I want to have one table, called alarms. Whenever some data is inserted into, or removed from this table, a trigger has to be called. All the trigger has to do, is run an external program/application.
But the only information I can find on triggers, are SQL-related. I just need to make a system call or something like that. Hope it's possible.
this is the definition of a trigger, activated
by a change in a database; as you can easily
see you can do *anything* from this code
From the PostgreSQL Programmers Guide
Here is a very simple example of trigger usage. Function trigf reports the number of tuples in the triggered relation ttest and skips the operation if the query attempts to insert a null value into x (i.e - it acts as a not-null constraint but doesn't abort the transaction).
#include "executor/spi.h" /* this is what you need to work with SPI */
#include "commands/trigger.h" /* -"- and triggers */
extern Datum trigf(PG_FUNCTION_ARGS);
TriggerData *trigdata = (TriggerData *) fcinfo->context;
bool checknull = false;
int ret, i;
/* Make sure trigdata is pointing at what I expect */
elog(ERROR, "trigf: not fired by trigger manager");
/* tuple to return to Executor */
rettuple = trigdata->tg_newtuple;
rettuple = trigdata->tg_trigtuple;
/* check for null values */
checknull = true;
when = "before";
when = "after ";
tupdesc = trigdata->tg_relation->rd_att;
/* Connect to SPI manager */
if ((ret = SPI_connect()) < 0)
elog(INFO, "trigf (fired %s): SPI_connect returned %d", when, ret);
/* Get number of tuples in relation */
ret = SPI_exec("SELECT count(*) FROM ttest", 0);
if (ret < 0)
elog(NOTICE, "trigf (fired %s): SPI_exec returned %d", when, ret);
/* count(*) returns int8 as of PG 7.2, so be careful to convert */
i = (int) DatumGetInt64(SPI_getbinval(SPI_tuptable->vals,
elog (NOTICE, "trigf (fired %s): there are %d tuples in ttest", when, i);
(void) SPI_getbinval(rettuple, tupdesc, 1, &isnull);
rettuple = NULL;