Обсуждение: User defined type in C

Поиск
Список
Период
Сортировка

User defined type in C

От
"Armel HERVE"
Дата:
Hi everybody,

Sorry if it's not the good forum and for my poor English.

I'm trying to create a new type in C for postgreSQL (7.3.4).
This type is a structure of 4 fields including a variable length field.

When I try to insert record ino a table using this type, postgre server
crashes:
LOG:  server process (pid 10838) was terminated by signal 11
LOG:  terminating any other active server processes
WARNING:  Message from PostgreSQL backend:
        The Postmaster has informed me that some other backend
        died abnormally and possibly corrupted shared memory.
        I have rolled back the current transaction and am
        going to terminate your database system connection and exit.
        Please reconnect to the database system and repeat your query.
WARNING:  Message from PostgreSQL backend:
        The Postmaster has informed me that some other backend
        died abnormally and possibly corrupted shared memory.
        I have rolled back the current transaction and am
        going to terminate your database system connection and exit.
        Please reconnect to the database system and repeat your query.
WARNING:  Message from PostgreSQL backend:
        The Postmaster has informed me that some other backend
        died abnormally and possibly corrupted shared memory.
        I have rolled back the current transaction and am
        going to terminate your database system connection and exit.
        Please reconnect to the database system and repeat your query.
LOG:  all server processes terminated; reinitializing shared memory and
semaphores
LOG:  database system was interrupted at 2004-05-10 12:25:55 CEST
LOG:  checkpoint record is at 0/627BE1DC
LOG:  redo record is at 0/627BE1DC; undo record is at 0/0; shutdown TRUE
LOG:  next transaction id: 2026530; next oid: 342157
LOG:  database system was not properly shut down; automatic recovery in
progress
LOG:  redo starts at 0/627BE21C
LOG:  ReadRecord: record with zero length at 0/627DD5F4
LOG:  redo done at 0/627DD5D0
LOG:  database system is ready


Does anybody can help me ???
Thanks for your answers,



Armel HERVE




This is the C code:
#include "postgres.h"

#define KEY_SIZE 31

typedef struct {
      int4 globalSize;
      int64 fileSize;
      char fileKey[KEY_SIZE + 1];
      char fileName[1];
} Psfile;

#define PSFILE_BASIC_SIZE (4 + sizeof(int64) + KEY_SIZE + 1)

/**
 *
 * char *str :  string representation of a psfile.
 *              must be formatted as follow :
 *                      xxx,yyy,zzz
 *              with xxx : the name of the file
 *                   yyy : the size of the file
 *                   zzz : the key associated with the file.
 */
Psfile *psfile_in(char *str) {
        Psfile *retValue = NULL;

        int nameSize = 0;

        // In first, we look for the size of the name
        for(nameSize = 0; str[nameSize] != ',' && str[nameSize] != 0;
nameSize++) {
               // Nothing to do in this block...
        }

        if(str[nameSize] == 0) {
                // We are at the end of the string... Something is wrong!!
                elog(ERROR, "psfile_in: string representation of a psfile :
name,size,key \"%s\"", str);
                return NULL;
        }

        // Now, we have the size, so we can allocate memory for the global
structure
        retValue = (Psfile *)palloc(PSFILE_BASIC_SIZE + nameSize + 1);

        char format[15];
        sprintf(format, "%%%ds,%%li,%%s", nameSize);

        char *fileName  = retValue->fileName;
        char *fileKey   = retValue->fileKey;
        int64 *fileSize = &(retValue->fileSize);

        if(sscanf(str, format, fileName, fileSize, fileKey) != 3) {
                // Something is wrong : the number of parameters found must
be 3
                pfree(retValue);
                elog(ERROR, "psfile_in: string representation of a psfile :
name,size,key \"%s\"", str);
                return NULL;
        }

        return retValue;
}

char *psfile_out(Psfile *psfile) {
elog(LOG, "psfile_out");
        if(psfile == NULL) return NULL;

        char *retValue = NULL;

        char size[30];
        sprintf(size, "%ld", psfile->fileSize);

        retValue = (char *)palloc(strlen(psfile->fileName) + 1 +
strlen(size) + 1 + strlen(psfile->fileKey) + 1);

        sprintf(retValue, "%s,%s,%s", psfile->fileName, size,
psfile->fileKey);

        return retValue;
}

And this is the type declaration :
CREATE FUNCTION psfile_in(cstring)
    RETURNS psfile
    AS '/usr/include/pgsql/server/pslib/pslib'
    LANGUAGE C IMMUTABLE STRICT;

CREATE FUNCTION psfile_out(psfile)
    RETURNS cstring
    AS '/usr/include/pgsql/server/pslib/pslib'
    LANGUAGE C IMMUTABLE STRICT;

CREATE TYPE psfile(
    internallength = valiable,
    input = psfile_in,
    output = psfile_out,
    alignment = int4
);






Re: User defined type in C

От
Tom Lane
Дата:
"Armel HERVE" <ah.pgsql@laposte.net> writes:
> I'm trying to create a new type in C for postgreSQL (7.3.4).
> This type is a structure of 4 fields including a variable length field.

Variable-size values must start with an integer indicating their total
size (this count must include itself, btw).  Perhaps your globalSize
field is intended to serve that purpose, but if so, you forgot to set it.

            regards, tom lane

Re: User defined type in C

От
"Armel HERVE"
Дата:
You're right... I'm confuse...
I'm sorry, it's the bug which I'm looking for a while...

Thanks

Armel


-----Message d'origine-----
De : Tom Lane [mailto:tgl@sss.pgh.pa.us]
Envoyé : lundi 10 mai 2004 13:51
À : Armel HERVE
Cc : pgsql-admin@postgresql.org
Objet : Re: [ADMIN] User defined type in C

"Armel HERVE" <ah.pgsql@laposte.net> writes:
> I'm trying to create a new type in C for postgreSQL (7.3.4).
> This type is a structure of 4 fields including a variable length field.

Variable-size values must start with an integer indicating their total
size (this count must include itself, btw).  Perhaps your globalSize
field is intended to serve that purpose, but if so, you forgot to set it.

            regards, tom lane


RAM usage per connection

От
Steve Lane
Дата:
Hello all:

I have a customer with an application in production (postgres + php +
apache) where we began seeing a  number of scary messages in the logs. (It's
postgres 7.2.1, by the way).

Generally the messages seem to point to resource starvation of some kind:

FATAL 1:  out of free buffers: time to abort !


And

Sorry, too many clients already

Also some messages indicating shared memory had been corrupted. I shut down
and ran ipcclean and those messages are gone. I also boosted shared-buffers
considerably and the "out of free buffers" message is also gone.

BUT, the "sorry too many clients" message persists. The app has a spike-y
usage pattern, i.e. A large number of students sits down at once and takes a
survey in accordance with verabl instructions from the front of the
classroom, so many of them are hitting the proverbial Submit button at once.

I tried increasing max_clients, but got a message to the effect that SHMMIN
was set incorrectly on my machine ...

Let me get to my actual question (none of the above contains the question
yet :->).

Is there any guideline as to how much free RAM I need per client connection?
I think I understand that things like sort_mem play into this -- that's set
low and should remain so. But for Apache, for example, I think of 10 meg per
connection. Any similar rule of thumb for postgres?

I'll follow up as I inspect the logs, but I haven't thoroughly sifted them.
So for my now my question is the one about RAM per connection.  Any
thoughts'd be much appreciated.

-- sgl


=======================================================
Steve Lane

Vice President
The Moyer Group
14 North Peoria St Suite 2H
Chicago, IL 60607

Voice: (312) 433-2421       Email: slane@moyergroup.com
Fax:   (312) 850-3930       Web:   http://www.moyergroup.com
=======================================================


Re: RAM usage per connection

От
Tom Lane
Дата:
Steve Lane <slane@moyergroup.com> writes:
> I have a customer with an application in production (postgres + php +
> apache) where we began seeing a  number of scary messages in the logs. (It's
> postgres 7.2.1, by the way).
  ^^^^^^^^^^^^^^

Reading the CVS logs for post-7.2.1 bug fixes will curl your toes.
You're irresponsible to still be running production data on that
version.  Move up to 7.2.4 before you find out the hard way.

> I tried increasing max_clients, but got a message to the effect that SHMMIN
> was set incorrectly on my machine ...

I'd expect SHMMAX to be the issue not SHMMIN.  It's set very
conservatively on many platforms, and you should not be afraid to raise
it.

            regards, tom lane

Re: RAM usage per connection

От
Steve Lane
Дата:

> From: Tom Lane <tgl@sss.pgh.pa.us>
> Date: Wed, 12 May 2004 16:13:37 -0400
> To: Steve Lane <slane@moyergroup.com>
> Cc: pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] RAM usage per connection
>
> Steve Lane <slane@moyergroup.com> writes:
>> I have a customer with an application in production (postgres + php +
>> apache) where we began seeing a  number of scary messages in the logs. (It's
>> postgres 7.2.1, by the way).
> ^^^^^^^^^^^^^^
>
> Reading the CVS logs for post-7.2.1 bug fixes will curl your toes.
> You're irresponsible to still be running production data on that
> version.  Move up to 7.2.4 before you find out the hard way.

I spoke too hastily. It's 7.1.3. Which probably doesn't make it better :-(
>
>> I tried increasing max_clients, but got a message to the effect that SHMMIN
>> was set incorrectly on my machine ...
>
> I'd expect SHMMAX to be the issue not SHMMIN.  It's set very
> conservatively on many platforms, and you should not be afraid to raise
> it.

I was also puzzled to see the reference to SHMMIN. I'll look again.

-- steve