Thread: postgresql8.1 crushes on some inserts/updates in KOI8 encoding

postgresql8.1 crushes on some inserts/updates in KOI8 encoding

From
Alexey Beschiokov
Date:
postgresql server crushes on some inserts / upates statements.


log looks like this:
2005-11-16 20:48:58 MSK -  : LOG:  server process (PID 16010) was
terminated by signal 11
2005-11-16 20:48:58 MSK -  : LOG:  terminating any other active server
processes
2005-11-16 20:48:58 MSK - udaff : FATAL:  the database system is in
recovery mode
2005-11-16 20:48:58 MSK - udaff : WARNING:  terminating connection
because of crash of another server process

core backtrace :

#0  0x08079414 in slot_deform_tuple (slot=0x837dfe0, natts=10) at
heaptuple.c:1262
1262                    off = att_addlength(off, thisatt->attlen, tp +
off);
(gdb) bt
#0  0x08079414 in slot_deform_tuple (slot=0x837dfe0, natts=10) at
heaptuple.c:1262
#1  0x0807955f in slot_getattr (slot=0x837dfe0, attnum=10,
isnull=0xbfffe5db "\001(ч7\bdш7\b\001") at heaptuple.c:1367
#2  0x080bb7c0 in FormIndexDatum (indexInfo=0x837de28, slot=0x837dfe0,
estate=0x837dad8, values=0xbfffe62c, isnull=0xbfffe6ac "") at index.c:962
#3  0x08130f12 in ExecInsertIndexTuples (slot=0x837dfe0,
tupleid=0x8382b0c, estate=0x837dad8, is_vacuum=0 '\0') at execUtils.c:925
#4  0x08129ac5 in ExecutorRun (queryDesc=0x837d6f8,
direction=ForwardScanDirection, count=0) at execMain.c:1437
#5  0x081a8471 in ProcessQuery (parsetree=Variable "parsetree" is not
available.
) at pquery.c:174
#6  0x081a993a in PortalRun (portal=0x837b520, count=2147483647,
dest=0x834e428, altdest=0x834e428, completionTag=0xbfffe918 "") at
pquery.c:1076
#7  0x081a582f in exec_simple_query (
    query_string=0x8355d08 "INSERT INTO ra_documents ( title, author,
        author_id, body, preview, ear, keywords, parent, dt ) VALUES (
        'Cyринамская пипа', 'rak_rak', '2342', 'Мама Лены безумно любила
        дерматологические эксперименты"...) at postgres.c:1014
#8  0x081a67e2 in PostgresMain (argc=4, argv=0x8304f00,
    username=0x8304ed8 "postgres") at postgres.c:3168
#9  0x081803b6 in ServerLoop () at postmaster.c:2854
#10 0x081811e1 in PostmasterMain (argc=5,
    argv=0x8303170) at
    postmaster.c:943
#11 0x08146170 in main (argc=5, argv=0x8303170) at
    main.c:256

table structure (s.sql) and query (q.sql - koi8-r encoding) to reproduse the problem are
attached. database encoding KOI8.


postgresql version 8.1
Architecture: i686
Kernel: Linux 2.6.11 (2.6.x actually)
Linux distributions: debian (sid, unstable), gentoo

cross-posted to http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=339527

WBR,
Alexey Bestchekov

Attachment

Re: postgresql8.1 crushes on some inserts/updates in KOI8 encoding

From
Tom Lane
Date:
Alexey Beschiokov <proforg@maloletka.ru> writes:
> postgresql server crushes on some inserts / upates statements.

I've applied the attached patch as a temporary stopgap for this.

            regards, tom lane

Index: execMain.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/executor/execMain.c,v
retrieving revision 1.256.2.1
diff -c -r1.256.2.1 execMain.c
*** execMain.c    14 Nov 2005 17:43:12 -0000    1.256.2.1
--- execMain.c    19 Nov 2005 20:52:37 -0000
***************
*** 1446,1451 ****
--- 1446,1461 ----
      setLastTid(&(tuple->t_self));

      /*
+      * KLUGE SOLUTION for bug found post 8.1 release: if the tuple toaster
+      * fired on the tuple then it changed the physical tuple inside the
+      * tuple slot, leaving any extracted information invalid.  Mark the
+      * extracted state invalid just in case.  Need to fix things so that
+      * the toaster gets to run against the tuple before we materialize it,
+      * but that's way too invasive for a stable branch.
+      */
+     slot->tts_nvalid = 0;
+
+     /*
       * insert index entries for tuple
       */
      if (resultRelInfo->ri_NumIndices > 0)
***************
*** 1700,1705 ****
--- 1710,1725 ----
      (estate->es_processed)++;

      /*
+      * KLUGE SOLUTION for bug found post 8.1 release: if the tuple toaster
+      * fired on the tuple then it changed the physical tuple inside the
+      * tuple slot, leaving any extracted information invalid.  Mark the
+      * extracted state invalid just in case.  Need to fix things so that
+      * the toaster gets to run against the tuple before we materialize it,
+      * but that's way too invasive for a stable branch.
+      */
+     slot->tts_nvalid = 0;
+
+     /*
       * Note: instead of having to update the old index tuples associated with
       * the heap tuple, all we do is form and insert new index tuples. This is
       * because UPDATEs are actually DELETEs and INSERTs, and index tuple

Re: postgresql8.1 crushes on some inserts/updates in KOI8 encoding

From
Tom Lane
Date:
Alexey Beschiokov <proforg@maloletka.ru> writes:
> postgresql server crushes on some inserts / upates statements.

BTW, the patch I sent you before was incomplete; one thing I found that
it didn't cover was COPY.  There is a better solution committed here:

http://archives.postgresql.org/pgsql-committers/2005-11/msg00439.php

            regards, tom lane