Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLeG1-00072g-D9 for pgsql-general@arkaria.postgresql.org; Mon, 04 Dec 2017 00:05:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eLeG0-0006W6-T9 for pgsql-general@arkaria.postgresql.org; Mon, 04 Dec 2017 00:05:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eLeCz-0008MU-Pt for pgsql-general@lists.postgresql.org; Mon, 04 Dec 2017 00:02:05 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eLeCu-00031l-Qt for pgsql-general@lists.postgresql.org; Mon, 04 Dec 2017 00:02:04 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 8FD18140E; Mon, 4 Dec 2017 01:01:58 +0100 (CET) Date: Mon, 4 Dec 2017 01:01:58 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: large numbers of inserts out of memory strategy Message-ID: <20171204000158.e5mngdl4ffvpslhz@hjp.at> References: <87d5d3c9-66e4-c29d-bece-79f2909cccb9@2ndquadrant.com> <8431416a-2ab2-d580-19bd-2c7e3353960d@2ndquadrant.com> <26623.1511927991@sss.pgh.pa.us> <20171130102209.6q6djwimzzj5opge@hjp.at> <20171130174005.jc3t5km2f2n4qmk7@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="c4wcipbf7gfwho6k" Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --c4wcipbf7gfwho6k Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2017-11-30 14:27:58 -0600, Ted Toth wrote: > On Thu, Nov 30, 2017 at 11:40 AM, Peter J. Holzer wrot= e: > > On 2017-11-30 08:43:32 -0600, Ted Toth wrote: > >> One thing that is unclear to me is when commits occur while using psql > >> would you know where in the docs I can find information on this > >> subject? > > > > By default psql enables autocommit which causes an implicit commit after > > every statement. With a do block I'm not sure whether that means after > > the do block or after each statement within the do block. I'd just turn > > autocommit off and add explicit commits wherever I wanted them. >=20 > So you think I can turn off autocommit and put BEGIN/COMMITs in a > large file and then postmaster won't have to parse the whole thing > when I feed it to it via psql? No, if you still had one giant do block it would need to parse it completely. I was thinking of the case where you have many small do blocks, each with a few insert statements (one do block per "thing"). In this case it would parse and execute each do block before moving on to the next. But I wasn't sure whether the default autocommit would mean one commit after each do block or one commit after each insert statement (David answered this - thanks), and in any case you probably wouldn't want to commit after each "thing", so I suggested turning autocommit off and adding an explicit commit at the end or possibly after every nth thing. > > Still: Is there a reason why you use a python script to create an sql > > script instead of directly issuing the sql queries from your python > > script? >=20 > I already had code that generated JSON so it was relatively easy to > add code and a cmd line arg to generate SQL instead. Ok. that sounds like a good reason. hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --c4wcipbf7gfwho6k Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlokkHEACgkQ8g5IURL+ KF0atg/9F5/xgmua76uHzZcA40E5p4c14YtpZ2yu+lAdtOQh4Kt8n/Mz8n7KXcbp rPq0LBEyu6zWglziykH3TydK2rCrEWOFp5D6HeonHvoYaSPo6aiU4nrTTjKfLVjE V0JlKjqyKwYjuQa2xXOWUf3bxNGEiAGZzRgc6E9MDCE6DR80uCFSnX6NLCly3eR3 1Ts0A3ZjxkU/1ixBaZu5VF0J+N5XX9JCaCRfOizbmNkU2LYZx6tRKtBpMShc//8D epneaxL+2ayJbFsGqhRIHDGyZsJRwHtYS/Ng6saApgsOumyuu1dbSxhJ8j4cN1QE gQuNos/9hpXafGx9I7Qfwq+AArRkUvXaruE9MbRucj2o3xWlK6fbrBEmm3ydu/+I BK9SQfC4YDQEqWoQL02GRDnyphQ1nmdKvrpHUwL2D820dJUSYPCxCbQcmBWhAi34 V74WeFOl6qsbB5ATC+X2Rh3CZQRBYDb/o/WdoQzY4D48gpMcSTW7wqBXgXbwV6Lr esVOZ0b2d3u3FBQnPQ35HFq/8Kj9kJEnI5RSzuC2TA4ecKitjtSaxvJAHt2s/Cxk EXz87GzuxRcT/baNmLgc9Ap7eVQAf7ctwtfzBJdYZF3cnkq0mmwosP9P8H6snyaD ICAI+BDfc9om4pEHuaDYRtaoa45OS4JJleC2IcMQy1YJMYHTljk= =FXcU -----END PGP SIGNATURE----- --c4wcipbf7gfwho6k--