pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: joel.traf@magwerks.com
To: pgsql-bugs@postgresql.org
Subject: plpython bug
Date: Sun, 05 Feb 2017 16:51:58 -0500
Message-ID: <20170205215158.AD118E06FA@smtp.hushmail.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hello Developers

found an interesting bug that causes a complete crash and resetting of
all connections to PG 9.5.0 compiled Visual C++ 1800, 64 bit
log states  server process (PID 2720) was terminated by exception
0XC0000005 
failed process was running: select upsert_items2(false)
Hint: see C include file ntstatus.h for a description of hexadecimal
value  (this error is a memory access error)
log: Terminating any other active server processes

Upsert_items2::  Is a function that copies/updates data from ERP
database to a Website database. It just iterates over all the items,
figures out how to group items together based on class, decides if the
item should be seen on the website based on rules,  Nothing
complicated.

As these are two different PG  databases, the plpython connects to the
erp database via psycopg2 copying the data into local plpython tuple
result set.   I then just executed the plpy.execute("insert on
conflict do update") for each item.  processing time was around 5
minutes to go through 12,000 items updating 5 tables on the website
database.

The users want this to be faster. The only solution i could think of
was to cut down on all context switching and data type mapping that
happens when calling plpy.execute() for each item.  So decided to just
build a really big SQL update command  then at the end plpython
function call plpy.execute().

That worked and processing time was reduced from 5 minutes to 8
seconds.  As this is work in process I started adding in more rules
that change what gets updated  and i had a couple of typo's  in the
SQL statements.

That's when i crashed the PG server hard.  Its taken me a few hours to
figure out were my mistake was, as this crash will only occur if a SQL
error is very deep in the command sent via plpy.execute().  If there
is an error in the first few lines it returns plpython SPI error.  
How deep into the SQL command an error has to be appear to cause this
access error i do not know. 

The length of the command sent via plpy.execute()  is 1,454,561 
characters long 

Any suggestions on how to narrow down at what point a bad command
causes this error??
FYI only 
The first write of this function was written in plpgsql  using DbLink
which took 15 minutes to process the same data-set,  second write used
FDW processing time was still 15 minutes, in both cases it spent all
the time getting data from the remote PG database doing executing
Fetchs.  
Thanks

view thread (2+ messages)  latest in thread

Message-ID: <20170205215158.AD118E06FA@smtp.hushmail.com>
Permalink:  ../20170205215158.AD118E06FA@smtp.hushmail.com/
Also on:    postgresql.org/message-id/20170205215158.AD118E06FA@smtp.hushmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: joel.traf@magwerks.com
  Subject: Re: plpython bug
  In-Reply-To: <20170205215158.AD118E06FA@smtp.hushmail.com>
  References: <20170205215158.AD118E06FA@smtp.hushmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox