8.2 server core dump - Mailing list pgsql-general

From Marc Evans
Subject 8.2 server core dump
Date
Msg-id 20061214074655.F70268@me.softwarehackery.com
Whole thread Raw
Responses Re: 8.2 server core dump  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi -

While working with plperl, I stumbled into a repeatable way to cause the
postgresql server to core dump. The example is shown here (yes, I know
that I didn't code $query properly for the spi_prepare, but that should
not cause a server core dump):

CREATE OR REPLACE FUNCTION insert_date_partition() RETURNS TRIGGER AS $$
   my %values = %{$_TD->{new}};
   my $table_name = $_TD->{table_name};
   my $column_name = $_TD->{args}[0];
   my $date = $values{$column_name};
   my ($ym,$query);
   if (!defined($date)) {
     @_ = (gmtime)[5,4,3];
     $date = join(' ',$_[0]+1900,$_[1],$_[2]);
     $ym = sprintf "%04d%02d",$_[0]+1900,$_[1];
   } else {
     $query = qq{ SELECT EXTRACT(year FROM '$date'::timestamp) ||
EXTRACT(month FROM '$date'::timestamp) as ym; };
     $ym = spi_exec_query($query)->{rows}[0]->{ym};
   }
   my $partition = $table_name . '_' . $ym;
   my $columns = join(',',keys(%values));
   my @data = values(%values);
   my $qs = '?,' x $#data . '?';
   $query = qq{ INSERT INTO $partition ($columns) VALUES ($qs); };
elog(INFO,$query);
   my $insert = spi_prepare($query);
   return SKIP;
$$ LANGUAGE plperlu;

CREATE TABLE test_table (
   id BIGSERIAL,
   created_at TIMESTAMP,
   count INTEGER
);

CREATE TRIGGER test_table_trigger
   BEFORE INSERT ON test_table
   FOR EACH ROW EXECUTE PROCEDURE insert_date_partition('created_at');

c3i=# insert into test_table values (1,now(),10);
INFO:  INSERT INTO test_table_200612 (created_at,count,id) VALUES (?,?,?);
server closed the connection unexpectedly

The stack trace for the resulting core dump shows:

#0  0x082e09d8 in MemoryContextDelete ()
#1  0x08175c56 in AtEOSubXact_SPI ()
#2  0x080ad740 in DefineSavepoint ()
#3  0x080ada7d in RollbackAndReleaseCurrentSubTransaction ()
#4  0x2a1c94cb in plperl_spi_prepare () from /usr/local/lib/postgresql/plperl.so
#5  0x2a1cd141 in XS__spi_prepare () from /usr/local/lib/postgresql/plperl.so
#6  0x2a24c274 in Perl_pp_entersub () from /usr/local/lib/perl5/5.8.8/mach/CORE/libperl.so
#7  0x2a245259 in Perl_runops_standard () from /usr/local/lib/perl5/5.8.8/mach/CORE/libperl.so
#8  0x2a1ef89c in S_call_body () from /usr/local/lib/perl5/5.8.8/mach/CORE/libperl.so
#9  0x2a1f4326 in Perl_call_sv () from /usr/local/lib/perl5/5.8.8/mach/CORE/libperl.so
#10 0x2a1cbf5a in plperl_call_handler () from /usr/local/lib/postgresql/plperl.so
#11 0x08145df7 in RelationBuildTriggers ()
#12 0x081462b2 in ExecBRInsertTriggers ()
#13 0x0815cc19 in ExecutorRun ()
#14 0x08205cba in FreeQueryDesc ()
#15 0x08206a83 in PortalSetResultFormat ()
#16 0x0820702c in PortalRun ()
#17 0x08202957 in pg_parse_query ()
#18 0x08204ea8 in PostgresMain ()
#19 0x081cb255 in ClosePostmasterPorts ()
#20 0x081ccfd3 in PostmasterMain ()
#21 0x08182a8c in main ()

The OS involved is FreeBSD 6.1-STABLE on a Pentium 4 (e.g. 32 bit).

Note, I attempted to submit this via the bug reporting page at
http://wwwmaster.postgresql.org/system/handleform.php but no matter which
of my several email addresses I attempted to use, the system always
complained "The email address you entered does not appear to be valid."

- Marc

pgsql-general by date:

Previous
From: Rafal Pietrak
Date:
Subject: Re: A VIEW mimicing a TABLE
Next
From: Markus Schiltknecht
Date:
Subject: Re: Large Object to Bytea Conversion