Bug #701: pqReadData() -- backend closed the channel unexpectedly.

Started by PostgreSQL Bugs Listalmost 24 years ago3 messagesbugs
Jump to latest
#1PostgreSQL Bugs List
pgsql-bugs@postgresql.org

Amit Mishra (amit.mishra@myrealbox.com) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
pqReadData() -- backend closed the channel unexpectedly.

Long Description
i have to fire a trigger whenever insertion is done on a table users
that calls the postgres function which inturn calls a c function .
wheever i am doing the insertion in the table it gives the followng error & terminates the backend:

pqReadData() -- backend closed the channel unexpectedly.
This probably means the backend terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

i cannot find the solution to this problem .please help.

Sample Code
the c file that contains function is as follows:

#include <stdio.h>
#include "pgsql/postgres.h"
void users();

int main()
{
users();
}

void users()
{
FILE *fp;
fp = fopen("/home/suresh/trigger/test.txt","w");
fputs("Hello this is c function",fp);
}

the postgres function that calls the c function is as follows:

create FUNCTION users() returns opaque as '/var/lib/pgsql/test.so' language 'C';

the trigger that calls the postgres function is as follows:

CREATE TRIGGER users_trg before insert on users for each row execute procedure users();

No file was uploaded with this report

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #701: pqReadData() -- backend closed the channel

On Sat, 29 Jun 2002 pgsql-bugs@postgresql.org wrote:

Short Description
pqReadData() -- backend closed the channel unexpectedly.

Long Description
i have to fire a trigger whenever insertion is done on a table users
that calls the postgres function which inturn calls a c function .
wheever i am doing the insertion in the table it gives the followng error & terminates the backend:

pqReadData() -- backend closed the channel unexpectedly.
This probably means the backend terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

i cannot find the solution to this problem .please help.

Sample Code
the c file that contains function is as follows:

#include <stdio.h>
#include "pgsql/postgres.h"
void users();

int main()
{
users();
}

void users()
{
FILE *fp;
fp = fopen("/home/suresh/trigger/test.txt","w");
fputs("Hello this is c function",fp);
}

I don't believe this is a valid trigger function. Looking at
the trigger documentation's simple example, I think the
function should return Datum and take PG_FUNCTION_ARGS (or
technically what that expands to, but...). I also think you
need a PG_FUNCTION_INFO_V1(users); and the function should
return the new row since you're using it as a before trigger.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: PostgreSQL Bugs List (#1)
Re: Bug #701: pqReadData() -- backend closed the channel unexpectedly.

pgsql-bugs@postgresql.org writes:

[ this trigger crashes the backend: ]

void users()
{
FILE *fp;
fp = fopen("/home/suresh/trigger/test.txt","w");
fputs("Hello this is c function",fp);
}

Triggers are supposed to return something --- especially BEFORE
triggers. See the examples in the manual.

regards, tom lane