Thread: PostgreSQL 9.0.2. This is a Bug?
This is a bug?
A developer is writing a function in C code and when he makes some change and replace the old library with the new one and if run CREATE OR REPLACE FUNCTION Postgre crash and restart. After restart CREATE OR REPLACE FUNCTION does not crash postgres, only the first time.
He makes a function test.
Function's Sorce code:
#include "postgres.h"
#include "fmgr.h"
#include <sys/utsname.h>
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
PG_FUNCTION_INFO_V1(testfuncion);
Datum testfuncion( PG_FUNCTION_ARGS )
{
int32 iParam01,
iParam02;
char cTexto[30]={0};
iParam01 = PG_GETARG_INT32(0);
iParam02 = PG_GETARG_INT32(1);
sprintf(cTexto, "iParam01: %i iParam02: %i", iParam01, iParam02 );
elog( NOTICE, cTexto );
PG_RETURN_INT32(iParam01 * -1);
}
makefile:
CC = gcc
CFLAGS = -fPIC
CPPFLAGS = -I/usr/include -I/usr/local/pgsql/include/server/ -I/usr/local/include -I./
all:
rm -f *.o
rm -f *.so
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o ./bin/testFuncion.o testFuncion.c
$(CC) $(CFLAGS) $(CPPFLAGS) -shared -o ./bin/testFuncion.so ./bin/testFuncion.o
@cp ./bin/testFuncion.so /somefolder/testFuncion.so
@echo " "
@echo OK ... Compilado ... OK
@echo " "
PostgreSQL' logs:
CC = gcc
CFLAGS = -fPIC
CPPFLAGS = -I/usr/include -I/usr/local/pgsql/include/server/ -I/usr/local/include -I./
all:
rm -f *.o
rm -f *.so
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o ./bin/testFuncion.o testFuncion.c
$(CC) $(CFLAGS) $(CPPFLAGS) -shared -o ./bin/testFuncion.so ./bin/testFuncion.o
@cp ./bin/testFuncion.so /somefolder/testFuncion.so
@echo " "
@echo OK ... Compilado ... OK
@echo " "
PostgreSQL' logs:
<2011-01-14 12:52:49 MST 10.43.69.141(55946) somedb someuser 18484 idle 64> DEBUG: StartTransactionCommand
<2011-01-14 12:52:49 MST 10.43.69.141(55946) somedb someuser 18484 idle 65> DEBUG: StartTransaction
<2011-01-14 12:52:49 MST 10.43.69.141(55946) somedb someuser 18484 idle 66> DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children:
<2011-01-14 12:52:49 MST 10.43.69.141(55946) somedb someuser 18484 idle 67> LOG: statement: CREATE OR REPLACE FUNCTION testfuncion(integer,integer)
RETURNS int AS
'/somefolder/testFuncion.so', 'testfuncion'
LANGUAGE c IMMUTABLE STRICT;
<2011-01-14 12:52:49 MST 10.43.69.141(55946) somedb someuser 18484 CREATE FUNCTION 68> DEBUG: ProcessUtility
<2011-01-14 12:52:49 MST 18297 654> DEBUG: reaping dead processes
<2011-01-14 12:52:49 MST 18297 655> DEBUG: server process (PID 18484) was terminated by signal 11: Segmentation fault
<2011-01-14 12:52:49 MST 18297 656> LOG: server process (PID 18484) was terminated by signal 11: Segmentation fault
<2011-01-14 12:52:49 MST 18297 657> LOG: terminating any other active server processes
Fabricio <fabrixio1@hotmail.com> writes: > A developer is writing a function in C code and when he makes some change and replace the old library with the new oneand if run CREATE OR REPLACE FUNCTION Postgre crash and restart. After restart CREATE OR REPLACE FUNCTION does not crashpostgres, only the first time. He makes a function test. You didn't say what platform this is, but overwriting an actively-used .so file isn't a safe thing to do on all systems. There's nothing Postgres can do about that. regards, tom lane
gcc 4.5.1
This .so files works fine in older postgres's versions.
Postgres has support for this, but postgres team says do not use it?
thanks tom, regards...
> To: fabrixio1@hotmail.com
> CC: pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] PostgreSQL 9.0.2. This is a Bug?
> Date: Fri, 14 Jan 2011 17:41:31 -0500
> From: tgl@sss.pgh.pa.us
>
> Fabricio <fabrixio1@hotmail.com> writes:
> > A developer is writing a function in C code and when he makes some change and replace the old library with the new one and if run CREATE OR REPLACE FUNCTION Postgre crash and restart. After restart CREATE OR REPLACE FUNCTION does not crash postgres, only the first time. He makes a function test.
>
> You didn't say what platform this is, but overwriting an actively-used
> .so file isn't a safe thing to do on all systems. There's nothing
> Postgres can do about that.
>
> regards, tom lane
Fabricio <fabrixio1@hotmail.com> writes: > Linux Slackware 13.1gcc 4.5.1 > This .so files works fine in older postgres's versions.Postgres has support for this, but postgres team says do not useit? It's not whether the .so works, it's whether you can overwrite it while it's already open in some process. I think you'll find that that crashes any version of Postgres, or most other programs too. A bit of googling turns up references like these: http://www.mail-archive.com/um-linux@listserv.umd.edu/msg02922.html http://stackoverflow.com/questions/3855004/overwriting-library-file-causes-segmentation-fault regards, tom lane