reload of shared library - Mailing list pgsql-bugs

From Edoardo Panfili
Subject reload of shared library
Date
Msg-id 3E65CA6A.8030408@aspix.it
Whole thread Raw
List pgsql-bugs
I'm sorry if this is not a bug.

I build a shared library that contains a single function.
I loaded it into postgres and uset it to create an index and a view.

After that i modify rebuild the shared library ,
copy the ".so" file in "/usr/lib/postgres/lib" and reload it with
"LOAD 'funzioniGDB.so';"
in pgsql
sometimes all goes well other times the system says:
-------------------------------------------------------------------
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
-------------------------------------------------------------------


and this id the dump in postgres.log
-------------------------------------------------------------------
2003-03-05 10:55:20 [1881]   DEBUG:  StartTransactionCommand
2003-03-05 10:55:20 [1881]   DEBUG:  query: LOAD 'funzioniGDB.so';
2003-03-05 10:55:20 [1881]   DEBUG:  parse tree: { QUERY :command 5
:utility ?  :resultRelation 0 :into <> :isPortal false :isBinary false
:isTemp false :hasAggs false :hasSubLinks false :rtable <> :jointree <>
:rowMarks () :targetList <> :groupClause <> :havingQual <> :distinctClause
<> :sortClause <> :limitOffset <> :limitCount <> :setOperations <>
:resultRelations ()}
2003-03-05 10:55:20 [1881]   DEBUG:  rewritten parse tree:
2003-03-05 10:55:20 [1881]   DEBUG:  { QUERY :command 5  :utility ?
:resultRelation 0 :into <> :isPortal false :isBinary false :isTemp false
:hasAggs false :hasSubLinks false :rtable <> :jointree <> :rowMarks ()
:targetList <> :groupClause <> :havingQual <> :distinctClause <>
:sortClause <> :limitOffset <> :limitCount <> :setOperations <>
:resultRelations ()}
2003-03-05 10:55:20 [1881]   DEBUG:  ProcessUtility: LOAD 'funzioniGDB.so';
2003-03-05 10:55:20 [1881]   DEBUG:  find_in_dynamic_libpath: trying
/usr/lib/postgresql/lib/funzioniGDB.so
2003-03-05 10:55:20 [1460]   DEBUG:  reaping dead processes
2003-03-05 10:55:20 [1460]   DEBUG:  child process (pid 1881) was
terminated by signal 11
2003-03-05 10:55:20 [1460]   DEBUG:  server process (pid 1881) was
terminated by signal 11
2003-03-05 10:55:20 [1460]   DEBUG:  terminating any other active server
processes
2003-03-05 10:55:20 [1460]   DEBUG:  all server processes terminated;
reinitializing shared memory and semaphores
2003-03-05 10:55:20 [1460]   DEBUG:  shmem_exit(0)
invoking IpcMemoryCreate(size=2449408)
2003-03-05 10:55:20 [1884]   DEBUG:  database system was interrupted at
2003-03-05 10:54:53 CET
2003-03-05 10:55:20 [1884]   DEBUG:  checkpoint record is at 0/AD731C0
2003-03-05 10:55:20 [1884]   DEBUG:  redo record is at 0/AD731C0; undo
record is at 0/0; shutdown TRUE
2003-03-05 10:55:20 [1884]   DEBUG:  next transaction id: 464857; next oid:
277223
2003-03-05 10:55:20 [1884]   DEBUG:  database system was not properly shut
down; automatic recovery in progress
2003-03-05 10:55:20 [1460]   DEBUG:  BackendStartup: forked pid=1885 socket=8
2003-03-05 10:55:20 [1884]   DEBUG:  ReadRecord: record with zero length at
0/AD73200
2003-03-05 10:55:20 [1884]   DEBUG:  redo is not required
2003-03-05 10:55:20 [1885]   FATAL 1:  The database system is starting up
2003-03-05 10:55:21 [1885]   DEBUG:  proc_exit(0)
2003-03-05 10:55:21 [1885]   DEBUG:  shmem_exit(0)
2003-03-05 10:55:21 [1885]   DEBUG:  exit(0)
2003-03-05 10:55:21 [1460]   DEBUG:  reaping dead processes
2003-03-05 10:55:21 [1460]   DEBUG:  child process (pid 1885) exited with
exit code 0
2003-03-05 10:55:23 [1884]   DEBUG:  database system is ready
2003-03-05 10:55:23 [1884]   DEBUG:  proc_exit(0)
2003-03-05 10:55:23 [1884]   DEBUG:  shmem_exit(0)
2003-03-05 10:55:23 [1884]   DEBUG:  exit(0)
2003-03-05 10:55:23 [1460]   DEBUG:  reaping dead processes
-------------------------------------------------------------------


it seems that this sequence is the bad one:
1-rebuild the ".so" file
2-open pgsql
3-copy ".so" file in "/usr/lib/postgres/lib"
4-"LOAD 'funzioniGDB.so';" in pgsql

if the sequence is 1-3-2-4 all goes well.

I hope this in usefull for you

Edoardo Panfili
/***************************************************************
 * Funzioni di supporto per il sistema GuiDeBook
 * CREATE FUNCTION esterna_nome(int,boolean,text,text,text,text,text,text,text,text,text,text,text,text) RETURNS text
AS'funzioniGDB.so' LANGUAGE C WITH (iscachable); 
 * SELECT esterna_nome(4,true,'text','text','text','text','text','text','text','text','text','text','text','text');
 **************************************************************/
#include "postgresql/server/postgres.h"
#include <string.h>
#include "postgresql/server/fmgr.h"
#include "postgresql/server/utils/elog.h"
//#include "/private/var/root/edoardo/postgresql-7.3.1/src/include/postgres.h"
//#include <string.h>
//#include "/private/var/root/edoardo/postgresql-7.3.1/src/include/fmgr.h"

char *prefissoSottospecie="ssp. ";
#define LUNGHEZZA_PREF_SS 5
char *prefissoVarieta="var. ";
#define LUNGHEZZA_PREF_VAR 5
char *prefissoSottoVarieta="subvar. ";
#define LUNGHEZZA_PREF_SVAR 8
char *prefissoForma="f. ";
#define LUNGHEZZA_PREF_FO 3
char *prefissoCultivar="c.v. ";
#define LUNGHEZZA_PREF_CV 5
char *suffissoProParte="p.p. ";
#define LUNGHEZZA_POST_PP 5

#define TEST_IBRIDO(n) {if(ibrido==n){buffer[caratteriInseriti]='x';buffer[caratteriInseriti+1]='
';caratteriInseriti+=2;}}
#define INSERISCI_PARTE(parte)
{memcpy(buffer+caratteriInseriti,VARDATA(parte),VARSIZE(parte)-VARHDRSZ);caratteriInseriti+=VARSIZE(parte)-VARHDRSZ+1;buffer[caratteriInseriti-1]='
';}

#define IBRIDO_GENERE 1
#define IBRIDO_SPECIE 2
#define IBRIDO_SOTTOSPECIE 3
#define IBRIDO_VARIETA 4
#define IBRIDO_SOTTOVARIETA 5
#define IBRIDO_FORMA 6
#define IBRIDO_CULTIVAR 7

PG_FUNCTION_INFO_V1(esterna_nome);

Datum esterna_nome(PG_FUNCTION_ARGS){
    char buffer[300];
    int  caratteriInseriti=0; // tiene il conto dei caratteri presenti in buffer
    int ibrido = PG_GETARG_INT32(0);
    bool proParte = PG_GETARG_BOOL(1);
    text *genere                  = (PG_ARGISNULL( 2) || VARSIZE(PG_GETARG_TEXT_P( 2))==VARHDRSZ
?NULL:PG_GETARG_TEXT_P(2));
    text *specieNome         = (PG_ARGISNULL( 3) || VARSIZE(PG_GETARG_TEXT_P( 3))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(3));
    text *specieAutore       = (PG_ARGISNULL( 4) || VARSIZE(PG_GETARG_TEXT_P( 4))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(4));
    text *sottospecieNome    = (PG_ARGISNULL( 5) || VARSIZE(PG_GETARG_TEXT_P( 5))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(5));
    text *sottospecieAutore  = (PG_ARGISNULL( 6) || VARSIZE(PG_GETARG_TEXT_P( 6))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(6));
    text *varietaNome        = (PG_ARGISNULL( 7) || VARSIZE(PG_GETARG_TEXT_P( 7))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(7));
    text *varietaAutore      = (PG_ARGISNULL( 8) || VARSIZE(PG_GETARG_TEXT_P( 8))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(8));
    text *sottoVarietaNome   = (PG_ARGISNULL( 9) || VARSIZE(PG_GETARG_TEXT_P( 9))==VARHDRSZ ?NULL:PG_GETARG_TEXT_P(9));
    text *sottoVarietaAutore = (PG_ARGISNULL(10) || VARSIZE(PG_GETARG_TEXT_P(10))==VARHDRSZ
?NULL:PG_GETARG_TEXT_P(10));
    text *formaNome          = (PG_ARGISNULL(11) || VARSIZE(PG_GETARG_TEXT_P(11))==VARHDRSZ
?NULL:PG_GETARG_TEXT_P(11));
    text *formaAutore        = (PG_ARGISNULL(12) || VARSIZE(PG_GETARG_TEXT_P(12))==VARHDRSZ
?NULL:PG_GETARG_TEXT_P(12));
    text *cultivar           = (PG_ARGISNULL(13) || VARSIZE(PG_GETARG_TEXT_P(13))==VARHDRSZ
?NULL:PG_GETARG_TEXT_P(13));
    text *nomeEsterno;

    //elog(DEBUG,">>>>>entrato nella funzione\n");

    // si inseriscono in ordine tutti i pezzi che servono

    // genere
    if(ibrido==IBRIDO_GENERE){
        buffer[0]='X';
        buffer[1]=' ';
        caratteriInseriti=2;

    }
    INSERISCI_PARTE(genere);
    // specie
    TEST_IBRIDO(IBRIDO_SPECIE);
    if(specieNome!=NULL){
        INSERISCI_PARTE(specieNome);
        if(specieAutore!=NULL){
            INSERISCI_PARTE(specieAutore);
        }
    }
    // sottospecie
    if(sottospecieNome!=NULL){
        memcpy(buffer+caratteriInseriti,prefissoSottospecie,LUNGHEZZA_PREF_SS);
        caratteriInseriti+=LUNGHEZZA_PREF_SS;
        TEST_IBRIDO(IBRIDO_SOTTOSPECIE);
        INSERISCI_PARTE(sottospecieNome);
        if(sottospecieAutore!=NULL){
            INSERISCI_PARTE(sottospecieAutore);
        }
    }
    // varieta
    if(varietaNome!=NULL){
        memcpy(buffer+caratteriInseriti,prefissoVarieta,LUNGHEZZA_PREF_VAR);
        caratteriInseriti+=LUNGHEZZA_PREF_VAR;
        TEST_IBRIDO(IBRIDO_VARIETA);
        INSERISCI_PARTE(varietaNome);
        if(varietaAutore!=NULL){
            INSERISCI_PARTE(varietaAutore);
        }
    }
    // sotto varieta
    if(sottoVarietaNome!=NULL){
        memcpy(buffer+caratteriInseriti,prefissoSottoVarieta,LUNGHEZZA_PREF_SVAR);
        caratteriInseriti+=LUNGHEZZA_PREF_SVAR;
        TEST_IBRIDO(IBRIDO_SOTTOVARIETA);
        INSERISCI_PARTE(sottoVarietaNome);
        if(sottoVarietaAutore!=NULL){
            INSERISCI_PARTE(sottoVarietaAutore);
        }
    }
    // forma
    if(formaNome!=NULL){
        memcpy(buffer+caratteriInseriti,prefissoForma,LUNGHEZZA_PREF_FO);
        caratteriInseriti+=LUNGHEZZA_PREF_FO;
        TEST_IBRIDO(IBRIDO_FORMA);
        INSERISCI_PARTE(formaNome);
        if(formaAutore!=NULL){
            INSERISCI_PARTE(formaAutore);
        }
    }
    // cultivar
    if(cultivar!=NULL){
        memcpy(buffer+caratteriInseriti,prefissoCultivar,LUNGHEZZA_PREF_CV);
        caratteriInseriti+=LUNGHEZZA_PREF_CV;
        TEST_IBRIDO(IBRIDO_CULTIVAR);
        INSERISCI_PARTE(cultivar);
    }
    //pro parte
    if(proParte==true){
        memcpy(buffer+caratteriInseriti,suffissoProParte,LUNGHEZZA_POST_PP);
        caratteriInseriti+=LUNGHEZZA_POST_PP;
    }

    nomeEsterno=(text *)palloc(caratteriInseriti-1+VARHDRSZ);
    memcpy(VARDATA(nomeEsterno),buffer,caratteriInseriti-1);
    VARATT_SIZEP(nomeEsterno)=caratteriInseriti-1+VARHDRSZ;

    PG_RETURN_TEXT_P(nomeEsterno);
}

pgsql-bugs by date:

Previous
From: "shura"
Date:
Subject: Problem with TIME datatype
Next
From: Tom Lane
Date:
Subject: Re: Problem with TIME datatype