From chrup999@yahoo.com Wed Aug 1 14:11:20 2001 Received: from smtp015.mail.yahoo.com (smtp015.mail.yahoo.com [216.136.173.59]) by postgresql.org (8.11.3/8.11.1) with SMTP id f71EBKf44797 for ; Wed, 1 Aug 2001 10:11:20 -0400 (EDT) (envelope-from chrup999@yahoo.com) Received: from proxy.compucom.com (HELO Z161842) (204.214.145.2) by smtp.mail.vip.sc5.yahoo.com with SMTP; 1 Aug 2001 14:11:16 -0000 X-Apparently-From: Message-ID: <002301c11a93$d631ff00$5dd26383@corp.compucom.com> From: "Chris Ruprecht" To: "pgadmin" Subject: Memory exhausted errors Date: Wed, 1 Aug 2001 09:11:19 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0020_01C11A69.ED2074A0" X-Priority: 1 X-MSMail-Priority: High X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200108/1 X-Sequence-Number: 1932 This is a multi-part message in MIME format. ------=_NextPart_000_0020_01C11A69.ED2074A0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi all, on a daily basis, I load records from an external source into my database. = During the load, the records go through a validation process during which I= have to read anywhere between 2 and 15 records from the database. The postmaster process which does this, starts out with 10 MB memory usage = but soon swells up to about 500 MB (on a normal day). Some days, I receive = a larger amount of data and the process swells up to about 1.4 GB before it= bombs out with a 'memory exhausted' message. I believe, the answer is to have the transactions smaller, but since PL/PGS= QL runs everything is one big transaction, how would I go about that? Can I= temporarily disable transaction processing all together for this process? = (if the load fails, I can easily delete the created records by hand). Best regards, Chris ------=_NextPart_000_0020_01C11A69.ED2074A0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi all,
 
on a daily basis, I load records from an e= xternal=20 source into my database. During the load, the records go through a validati= on=20 process during which I have to read anywhere between 2 and 15 records from = the=20 database.
The postmaster process which does this, st= arts out=20 with 10 MB memory usage but soon swells up to about 500 MB (on a normal day= ).=20 Some days, I receive a larger amount of data and the process swells up to a= bout=20 1.4 GB before it bombs out with a 'memory exhausted' message.
I believe, the answer is to have the trans= actions=20 smaller, but since PL/PGSQL runs everything is one big transaction, ho= w=20 would I go about that? Can I temporarily disable transaction processing all= =20 together for this process? (if the load fails, I can easily delete the crea= ted=20 records by hand).
 
Best regards,
Chris
 
------=_NextPart_000_0020_01C11A69.ED2074A0-- _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From tgl@sss.pgh.pa.us Wed Aug 1 14:35:12 2001 Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f71EZCf55286 for ; Wed, 1 Aug 2001 10:35:12 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f71EZ5C09525; Wed, 1 Aug 2001 10:35:06 -0400 (EDT) To: "Chris Ruprecht" cc: "pgadmin" Subject: Re: Memory exhausted errors In-reply-to: <002301c11a93$d631ff00$5dd26383@corp.compucom.com> References: <002301c11a93$d631ff00$5dd26383@corp.compucom.com> Comments: In-reply-to "Chris Ruprecht" message dated "Wed, 01 Aug 2001 09:11:19 -0500" Date: Wed, 01 Aug 2001 10:35:05 -0400 Message-ID: <9522.996676505@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200108/3 X-Sequence-Number: 1934 "Chris Ruprecht" writes: > The postmaster process which does this, starts out with 10 MB memory usage = > but soon swells up to about 500 MB (on a normal day). What Postgres version are you running? If not 7.1.*, update and see if it gets better. We fixed a lot of intra-statement memory leakage in 7.1 ... regards, tom lane From chrup999@yahoo.com Wed Aug 1 14:39:51 2001 Received: from smtp013.mail.yahoo.com (smtp013.mail.yahoo.com [216.136.173.57]) by postgresql.org (8.11.3/8.11.1) with SMTP id f71Edpf56943 for ; Wed, 1 Aug 2001 10:39:51 -0400 (EDT) (envelope-from chrup999@yahoo.com) Received: from proxy.compucom.com (HELO Z161842) (204.214.145.2) by smtp.mail.vip.sc5.yahoo.com with SMTP; 1 Aug 2001 14:39:47 -0000 X-Apparently-From: Message-ID: <004801c11a97$d18f5520$5dd26383@corp.compucom.com> From: "Chris Ruprecht" To: "pgadmin" References: <002301c11a93$d631ff00$5dd26383@corp.compucom.com> <9522.996676505@sss.pgh.pa.us> Subject: Re: Memory exhausted errors Date: Wed, 1 Aug 2001 09:39:49 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200108/2 X-Sequence-Number: 1933 Tom, I'm running the latest 7.1.2 ;) Best regards, Chris ----- Original Message ----- From: "Tom Lane" To: "Chris Ruprecht" Cc: "pgadmin" Sent: Wednesday, August 01, 2001 9:35 AM Subject: Re: [ADMIN] Memory exhausted errors > "Chris Ruprecht" writes: > > The postmaster process which does this, starts out with 10 MB memory usage = > > but soon swells up to about 500 MB (on a normal day). > > What Postgres version are you running? > > If not 7.1.*, update and see if it gets better. We fixed a lot of > intra-statement memory leakage in 7.1 ... > > regards, tom lane _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From tgl@sss.pgh.pa.us Wed Aug 1 15:13:40 2001 Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f71FDef75492 for ; Wed, 1 Aug 2001 11:13:40 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f71FDXC09768; Wed, 1 Aug 2001 11:13:33 -0400 (EDT) To: "Chris Ruprecht" cc: "pgadmin" Subject: Re: Memory exhausted errors In-reply-to: <004801c11a97$d18f5520$5dd26383@corp.compucom.com> References: <002301c11a93$d631ff00$5dd26383@corp.compucom.com> <9522.996676505@sss.pgh.pa.us> <004801c11a97$d18f5520$5dd26383@corp.compucom.com> Comments: In-reply-to "Chris Ruprecht" message dated "Wed, 01 Aug 2001 09:39:49 -0500" Date: Wed, 01 Aug 2001 11:13:33 -0400 Message-ID: <9765.996678813@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200108/4 X-Sequence-Number: 1935 "Chris Ruprecht" writes: > I'm running the latest 7.1.2 ;) Oh? You'll need to give more details about exactly what you're doing, then. regards, tom lane From tgl@sss.pgh.pa.us Thu Aug 2 21:45:30 2001 Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f72LjUf18758 for ; Thu, 2 Aug 2001 17:45:30 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f72LiDC14129; Thu, 2 Aug 2001 17:44:13 -0400 (EDT) To: "Chris Ruprecht" cc: "pgadmin" Subject: Re: Memory exhausted errors In-reply-to: <002301c11a93$d631ff00$5dd26383@corp.compucom.com> References: <002301c11a93$d631ff00$5dd26383@corp.compucom.com> Comments: In-reply-to "Chris Ruprecht" message dated "Wed, 01 Aug 2001 09:11:19 -0500" Date: Thu, 02 Aug 2001 17:44:13 -0400 Message-ID: <14126.996788653@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200108/8 X-Sequence-Number: 1939 "Chris Ruprecht" writes: > on a daily basis, I load records from an external source into my database. = > During the load, the records go through a validation process during which I= > have to read anywhere between 2 and 15 records from the database. > The postmaster process which does this, starts out with 10 MB memory usage = > but soon swells up to about 500 MB (on a normal day). Some days, I receive = > a larger amount of data and the process swells up to about 1.4 GB before it= > bombs out with a 'memory exhausted' message. [ Chris was kind enough to send me his function and sample data ] Well, the good news is that CVS-tip sources leak no memory on your example: total memory consumption on my machine stabilizes at about 4Mb with 2Mb resident. Most of the credit goes to changes Jan made a couple months ago, but I did some additional cleanup just now. The bad news is that the changes associated with this are too extensive to consider back-patching into 7.1.*. The older code is just too cavalier about allowing transient memory allocated during plpgsql function execution to be left unreclaimed until the function exits. That doesn't matter for a function that doesn't run very long, but since you have a plpgsql function that iterates over tens of thousands of records, any intrafunction leak will kill you. What you might consider doing as a hack solution until 7.2 comes out is to move the body of the main loop of your function out to a separate plpgsql function, ie, make the main loop look something like for ipt in select * from dayload2 where type is null loop n := n + process_one_record(ipt); end loop; return n; This'd be a tad slower, but memory used within the process_one_record function will be freed when it exits, so that should hold down the leakage to a tolerable level. regards, tom lane From chrup999@yahoo.com Fri Aug 3 00:20:33 2001 Received: from smtp010.mail.yahoo.com (smtp010.mail.yahoo.com [216.136.173.30]) by postgresql.org (8.11.3/8.11.1) with SMTP id f730KXf66191 for ; Thu, 2 Aug 2001 20:20:33 -0400 (EDT) (envelope-from chrup999@yahoo.com) Received: from chill-025.bbnow.net (HELO ?192.168.0.4?) (24.219.2.25) by smtp.mail.vip.sc5.yahoo.com with SMTP; 3 Aug 2001 00:20:30 -0000 X-Apparently-From: User-Agent: Microsoft-Entourage/9.0.1.3108 Date: Thu, 02 Aug 2001 19:20:24 -0500 Subject: Re: Memory exhausted errors From: Chris Ruprecht To: Tom Lane , Message-ID: In-Reply-To: <14126.996788653@sss.pgh.pa.us> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Archive-Number: 200108/9 X-Sequence-Number: 1940 Tom, Thank you so very much for your research! I have broken down the load procedure into two parts and it's looking great. The run time is sort of identical (about 3 minutes for today's file) but memory usage stays under 30 MB instead of rising up to ... The old routine is busy running to compare and it currently sits at 344 MB - major difference (377 MB now). I see a very slight increase in the 'size' field (under top), about 128 KB every 4 seconds which, maybe, could be attributed to some procedural overhead? It's not a major issue (any more) - I can live with the system as it is, even if I load 500'000 records in the future, per client, per day, this will be workable. Bruce said something about 'a few months' until 7.2 will become available. Well, I think I can wait that long. And I guess, I should express my support and actually buy a CD and Bruce's book. Tom, write a book, and Buy that, too. ;-). Best regards, Chris on 08/02/2001 16:44, Tom Lane at tgl@sss.pgh.pa.us wrote: > "Chris Ruprecht" writes: >> on a daily basis, I load records from an external source into my database. = [snip] > function will be freed when it exits, so that should hold down the > leakage to a tolerable level. > > regards, tom lane _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com From tgl@sss.pgh.pa.us Fri Aug 3 00:34:03 2001 Received: from sss.pgh.pa.us ([192.204.191.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f730Y3f69902 for ; Thu, 2 Aug 2001 20:34:03 -0400 (EDT) (envelope-from tgl@sss.pgh.pa.us) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.11.4/8.11.4) with ESMTP id f730XwC14973; Thu, 2 Aug 2001 20:33:58 -0400 (EDT) To: Chris Ruprecht cc: pgsql-admin@postgresql.org Subject: Re: Memory exhausted errors In-reply-to: References: Comments: In-reply-to Chris Ruprecht message dated "Thu, 02 Aug 2001 19:20:24 -0500" Date: Thu, 02 Aug 2001 20:33:58 -0400 Message-ID: <14970.996798838@sss.pgh.pa.us> From: Tom Lane X-Archive-Number: 200108/10 X-Sequence-Number: 1941 Chris Ruprecht writes: > Thank you so very much for your research! I have broken down the load > procedure into two parts and it's looking great. The run time is sort of > identical (about 3 minutes for today's file) but memory usage stays under 30 > MB instead of rising up to ... The old routine is busy running to compare > and it currently sits at 344 MB - major difference (377 MB now). I see a > very slight increase in the 'size' field (under top), about 128 KB every 4 > seconds which, maybe, could be attributed to some procedural overhead? Residual leakage within the outer procedure's for-loop, no doubt. As long as you can live with it until 7.2 comes out, I think you'll be okay. regards, tom lane