postmaster core dumps with SPI_repalloc

Поиск
Список
Период
Сортировка
От Andrey Y. Mosienko
Тема postmaster core dumps with SPI_repalloc
Дата
Msg-id 3CE0E49E.905EC7B9@ttn.ru
обсуждение исходный текст
Ответы Re: postmaster core dumps with SPI_repalloc  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hello All!

I noticed when I create memory pool with SPI_palloc(less than 100) and then
try to reallocate it with SPI_repalloc postmaster core dumps.

But when first SPI_palloc(100 or bigger) everything works fine!

What can be wrong?

Here is trigger example:

CREATE SEQUENCE base_id_seq;

CREATE TABLE "base" (
    "id" int4 DEFAULT nextval('base_id_seq'::text) NOT NULL,
    "field" text NOT NULL,
    "field_m" text NOT NULL,
    "field_n" text NOT NULL,
    "changed" timestamp NOT NULL DEFAULT NOW(),
    PRIMARY KEY ("id"), UNIQUE ("id")
);

INSERT INTO "base" (field, field_m, field_n) VALUES ('test', 'test', 'test');

CREATE FUNCTION archive() RETURNS OPAQUE AS
'/home/feo/WORK/backup/archive.so' LANGUAGE 'C';

CREATE TRIGGER "archive" AFTER UPDATE
    ON base FOR EACH ROW
    EXECUTE PROCEDURE archive();

archive.c:

#include "executor/spi.h"       /* this is what you need to work with SPI */
#include "commands/trigger.h"   /* -"- and triggers */

extern Datum archive(PG_FUNCTION_ARGS);

PG_FUNCTION_INFO_V1(archive);

Datum
archive(PG_FUNCTION_ARGS)
{
    //TriggerData *trigdata = (TriggerData *) fcinfo->context;

    int             ret, i;
    char*           sql;
    char*           fields_names;
    char*           values;

    // Ok ... this is a trigger function ...
    // were we called from a trigger??
    //
    if (!CALLED_AS_TRIGGER(fcinfo))
        elog(ERROR, "archive: not fired by trigger manager");

    // Connect to the SPI manager
    //
    if( (ret = SPI_connect()) == SPI_OK_CONNECT ) {
        fields_names = SPI_palloc(100);
        values = SPI_palloc(100);
        sql = SPI_palloc(40);

        for (i = 0; i < 10; i++) {
            SPI_repalloc(fields_names, sizeof(fields_names) + 100);
            SPI_repalloc(values, sizeof(values) + 100);
        };
        SPI_pfree(fields_names);
        SPI_pfree(values);
        SPI_pfree(sql);

        SPI_finish();
    };
    // Or if everything failes (no SPI connection)
    // we'll just return ... nothing!
    return PointerGetDatum(NULL);
}

PgSQL log:
DEBUG:  query: update base set field_m = 'test4', changed = NOW() where id = '1';
DEBUG:  server process (pid 5909) was terminated by signal 11

--
with respection Andrey Feofilactovich.
e-mail: feo@ttn.ru, feo@feo.org.ru
ICQ: 28073807

В списке pgsql-general по дате отправления:

Предыдущее
От: "Darko Prenosil"
Дата:
Сообщение: Re: if exists?
Следующее
От: Martín Marqués
Дата:
Сообщение: Re: restoreing dumps fail