Subject: Error: No response from the backend, exiting...

From: [email-masked] (Alfredo Sanchez)
Date: Tue, 25 Feb 92 12:59:42 -0800

Last week I posted a question regarding this error.
I guess I could not make myself clear to get some help,
so let me try again. I'll really appreciate (and need)
any clue you can come up with.

During this time, i've realized that i was trying to
run my program from different machines, and that was
precluding postgres from using effectively its shared
memory mechanism. so i tought that was the origin of all
my problems. however, when i shifted to run (only) 2
copies of it in the same machine, the problem persists.
this time the results are somewhat different. sometimes
it works perfectly, allowing more than 1 program to 
access the db. other times, one program works properly
and the other exits with the message:

	Error: No response from the backend, exiting...

still other times, one program works and the other exits
with the message:

NOTICE:Feb 25 14:21:49:I have been signalled by the postmaster.
NOTICE:Feb 25 14:21:49:Some backend process has died unexpectedly and possibly
NOTICE:Feb 25 14:21:49:corrupted shared memory.  The current transaction was
NOTICE:Feb 25 14:21:49:aborted, and I am going to exit.  Please resend the
NOTICE:Feb 25 14:21:49:last query. -- The postgres backend
NOTICE:Feb 25 14:21:49:last query. -- The postgres backend
NOTICE:Feb 25 14:21:49:last query. -- The postgres backend ...

and it goes on within an infinite loop.

Am I doing the correct assumptions on the pg locking capabilities?
I mean, i would expect one program to wait for the other to finish
its transaction before proceeding to use the involved classes.

I am including a more complete copy of my program below
(I just omitted all checking done after pg commands). I'm not
asking anyone to follow it, but perhaps you can detect
anything wrong on the general proceeding.

Thanks for any help you can provide.

J Alfredo Sanchez H
-------------------
Hypertext Research Lab
Department of Computer Science
Texas A&M University

program.
________________________________________________________
typedef
      struct {
         XltIDType appid;
         XltIDType compid;
         XltIDType psid;
      } 
      XltLSTripleType;

/*
struct def above should be taken from this source file:
#include "/home2/Xlt11/source/IPC/XltIPCDefs.h"
*/

void Browse  (pfrom_triple, hostid, pnumtriples, pto_triples, rc)
   XltLSTripleType *pfrom_triple;	/* ORIGIN OF THE LINK TO FOLLOW */
   char hostid[16];			/* NAME OF HOST REQUESTING BROWSING OP*/
   unsigned *pnumtriples;		/* NUMBER OF DESTINATION TRIPLES FOUND*/
   XltLSTripleType **pto_triples;	/* DESTINATION TRIPLES FOUND*/
   XltRCType *rc;			/* RETURN CODE */
{
   /* LOCAL VARIABLES */
   char postquery[1024];	/* STORES QUERIES SUBMITTED TO POSTGRES */
   PortalBuffer *portalbuff;	/* POINTS TO DATA RETRIEVED FROM DB */
   char result[512];		/* STORES RESULTS FROM PG OPERATIONS */
   unsigned index;		/* SUBSCRIPT FOR ARRAY OPERATIONS */
   XltRCType lrc;		/* RETURN CODE FROM DIAGNOSTIC FUNCTIONS */

   XltAddDiagDevice (stderr, "XltFollowLink:", XltDiagEmitXltSevereWarn, &lrc); 
   /* SET DEFAULT RETURN CODE TO OK */
   *rc = OK;
   /* DIRECT POSTQUEL QUERIES TO THE DATABASE CURRENTLY BEING USED */
   PQsetdb(XltOM_DB);
   /* START POSTQUEL TRANSACTION */
   strcpy(result,PQexec("begin"));
   /* GET SIDES IN WHICH GIVEN TRIPLE PARTICIPATES */
   sprintf(postquery,"retrieve into temp1_%s (e1.sid) \
                      from e1 in %s_SIDES \
                      where e1.appid = \"%ld\"  and \
                            e1.compid = \"%ld\" and \
                            e1.psid =  \"%ld\"", 
                      hostid, XltASM_Context, pfrom_triple->appid,
                      pfrom_triple->compid, pfrom_triple->psid);
   strcpy(result, PQexec(postquery));
   /* GET ASSOCIATIONS IN WHICH RESULTING SIDES PARTICIPATE */
   sprintf(postquery,"retrieve into temp2_%s (e2.associd) \
                      from e1 in temp1_%s, \
                           e2 in %s_ASSOCS \
                      where e1.sid = e2.sid",
                      hostid, hostid, XltASM_Context);
   strcpy(result, PQexec(postquery));
   /* GET THE OTHER SIDES PARTICIPATING IN RESULTING ASSOCIATIONS */
   sprintf(postquery,"retrieve into temp3_%s (e3.sid) \
                      from e1 in temp1_%s, e2 in temp2_%s, e3 in %s_ASSOCS \
                      where e3.associd = e2.associd \
                        and e3.sid != e1.sid",
                      hostid, hostid, hostid, XltASM_Context);
   strcpy(result, PQexec(postquery));
   /* GET LINKED TRIPLES */
   sprintf(postquery, "retrieve portal p1 unique (e1.appid,e1.compid,e1.psid) \
           from e1 in %s_SIDES, e3 in temp3_%s \
           where e1.sid = e3.sid ",
           XltASM_Context,hostid);
   strcpy(result, PQexec(postquery));
   if (result[0] != 'C') {
      *rc = PG_FAILED;
      XltEmitDiag (XltDiagXltSevereWarn,&lrc,"Can't retrieve triples\n");
      return;
   }
   strcpy(result, PQexec("fetch all in p1"));
   portalbuff = PQparray("p1");
   *pnumtriples = PQntuples(portalbuff);
   /* ALLOCATE SPACE FOR TRIPLES  AND MOVE THEM THERE */
   (*pto_triples) = (XltLSTripleType *)palloc(*pnumtriples *
                   sizeof(XltLSTripleType));
   for (index = 0; index < *pnumtriples; index++) {
       (*pto_triples)[index].appid  = atoi(PQgetvalue(portalbuff,index,0));
       (*pto_triples)[index].compid = atoi(PQgetvalue(portalbuff,index,1));
       *pto_triples)[index].psid   = atoi(PQgetvalue(portalbuff,index,2));
   }
   /* CLOSE PORTAL */
   strcpy(result,PQexec("close p1"));
   /* DELETE TEMPORARILY CREATED CLASSES */
   sprintf(postquery,"destroy temp1_%s",hostid); 
   strcpy(result,PQexec(postquery));
   sprintf(postquery,"destroy temp2_%s",hostid); 
   strcpy(result,PQexec(postquery));
   sprintf(postquery,"destroy temp3_%s",hostid); 
   strcpy(result,PQexec(postquery));
   /* END POSTQUEL TRANSACTION */
   strcpy(result,PQexec("end"));
   /* TERMINATE COMMUNICATIONS WITH BACKEND */
   PQfinish();
}

main (argc, argv)
int argc;
char *argv[];
{

   unsigned long rc;
   XltLSTripleType from_triple;
   char hostid[8];
   XltLSTripleType *to_triples;
   unsigned numtriples;
   unsigned i;

   strcpy(hostid, *++argv);
   strcpy(XltASM_Context,"context1");
   from_triple.appid  = 80;
   from_triple.compid = 90;
   from_triple.psid   = 100;
   Browse (&from_triple, hostid, &numtriples, &to_triples, &rc);
   printf("Got %d triples:\n",numtriples);
   for (i=0; i<numtriples; i++) {
       printf("appid = %ld, compid= %ld, psid= %ld \n",
               to_triples[i].appid, 
               to_triples[i].compid, 
               to_triples[i].psid);
   }
}

---

From: postarch (Postgres Mailing Archive)
Date: Fri, 28 Feb 92 11:33:56 PST

> my problems. however, when i shifted to run (only) 2

As long as you are using the same host machine (i.e. the
same postmaster) this won't make any difference.

> and the other exits with the message:

This sounds like bugs in postgres rather than bugs with your
program.  It sounds like one of the backends is choking
and dying (hopefully dumping core).  Look in the directory
$POSTGRESHOME/data/base/<dbname> for a core fileaction before proceeding to use the involved classes.

Your assumptions are correct.  Postgres does two-phase locking, so if 
one program holds write locks the other must wait until the transaction 
commits or aborts before it can access the locked data.

Jeff Meredith
[email-masked]