Triggers cause backend crash
Triggers cause backend crash
От:
"Andras Belokosztolszki" <beland1@hotmail.com>
Дата:
/*
* Andras Belokosztolszki
*
* A trigger function invoked when a predicate is is modified
* it looks up in the registered templates for this predicate the
* parties to be notified
*
* create trigger t4predt_..._trigger
* AFTER INSERT on ...
* FOR EACH ROW
* EXECUTE PROCEDURE t4predt_trig1();
*
*/
#include "executor/spi.h" /* this is what you need to work with SPI */
#include "commands/trigger.h" /* -"- and triggers */
#include "catalog/pg_type.h" /* for OID constants */
#include "MPS_triggers.h"
extern Datum t5_pred_general_trig(PG_FUNCTION_ARGS) ;
Datum t5_pred_general_trig(PG_FUNCTION_ARGS) {
TriggerData *trigdata = (TriggerData *) fcinfo->context;
TupleDesc tupdesc1;
HeapTuple rettuple;
HeapTuple rettuple_old; /* in case of update the old tuple */
Relation rel;
Trigger *trigger; /* to get trigger name */
int nargs;
char **args; /* arguments */
elog(NOTICE, "PredicateGeneralTrigger: Called");
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "PredicateGeneralTrigger: not fired by trigger manager!");
/* tuple to return */
if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) {
rettuple = trigdata->tg_newtuple;
rettuple_old = trigdata->tg_trigtuple;
} else {
rettuple = trigdata->tg_trigtuple;
rettuple_old = trigdata->tg_trigtuple; // old tuple is the default !!!
}
if (!TRIGGER_FIRED_AFTER(trigdata->tg_event)) {
elog(ERROR,"PredicateGeneralTrigger: Trigger not fired after event");
}
rel = trigdata->tg_relation;
tupdesc1 = trigdata->tg_relation->rd_att;
// check trigger parameters !!
trigger = trigdata->tg_trigger;
nargs = trigger->tgnargs;
args = trigger->tgargs;
trigdata = NULL;
/* connect to the database */
SPI_connect();
SPI_finish();
elog(NOTICE,"General trigger finished");
return PointerGetDatum(rettuple);
}Re: Triggers cause backend crash
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Andras Belokosztolszki" writes: >>Hi, I have a problem (I wrote about it before, but here is a complete example). When I have two triggers with parameters the backend crashes after a certain sequence of invocations. Attached are two very simple triggers in C (they might contain some unnecessary lines, they are a stripped version of an application I'm working on), how to compile, how to bootstrap, ... how to crash the backend
>Postgresql info:
>PostgreSQL 7.1.3 on i686-pc-linux-gnu, compiled by GCC 2.95.3
>A sample makefile (extract from mine)
>> [etc] Please don't use HTML for email. I think your problem is that you've omitted the PG_FUNCTION_INFO_V1() macro call that's needed to mark these functions as version-1 calling convention. regards, tom lane