Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uf6cO-002C0Q-1p for pgsql-general@arkaria.postgresql.org; Fri, 25 Jul 2025 00:49:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uf6cN-00D2gx-6u for pgsql-general@arkaria.postgresql.org; Fri, 25 Jul 2025 00:48:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uf6cM-00D2fg-75 for pgsql-general@lists.postgresql.org; Fri, 25 Jul 2025 00:48:59 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uf6cK-000dgM-1W for pgsql-general@postgresql.org; Fri, 25 Jul 2025 00:48:57 +0000 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.stl.internal (Postfix) with ESMTP id 3FA5C1D00899; Thu, 24 Jul 2025 20:48:55 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 24 Jul 2025 20:48:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1753404535; x=1753490935; bh=o3AX14XBo7QPAD5s4jiqamfaiyP5MkAg/oXClSn68E0=; b= eGC34elmDiot1ok6EXTuCDN8CFABoSIX/fz31yOpNuCdREf+liCg6uib90JKce7M MO7fzgliQtpxRxdkSBfGl4Sw8aA9iIiSKRi50vUgots/0wKz8zlp+dM9amLYVHRl 86xBZGflv6CCbeJTqowJRpxAEX6DIt1dGRjFsxNrCVipJUeZxjncOYWq71402wLE hiQycrYwnkPSzp36a+ASx6Y0jnkVfOQqRjRAUXw6lwxWvAJynUXTQSmLouVS+22g lv7kg89YJ6LffGjhA+aqMZrN9lxRy3EUw8Q1lZRfxOtvj6xO3Ep1pwKg5RLV8tKQ IsNRNBHNvop9V9hUMnlHBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1753404535; x= 1753490935; bh=o3AX14XBo7QPAD5s4jiqamfaiyP5MkAg/oXClSn68E0=; b=f vzyZ4SrjqoppdzRJSWauA6CoND57GIe/4vUx8PXPH+09nl6byuvAQ1sXzWpixaPp OFRZlVlXcV0xvCiPTcp1mx71EDF3QDuip0TA1rUt+4VQydG+gPBwfUbHYgnerG7d 3utrgYSteH+9fqP/EChNhhCOcWoVE3E9Asff2TRxhkocKsWtMojR4fk97c2gH82A uEQgQ64DJ7elZQubS7JubkLKby+Jm6FPhI04BaHPO15bHP+ULFH/U6GPEoCdD10k NrI9QbfgRMpZQrW6TFbuaE4ziGaQ6lZItVptP7Gawq8Rrujp2lblkBJXF0nQHvuj ObN9JiNj8RVyXcLk05xXw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdekvddufecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomheptegurhhirghn ucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqe enucggtffrrghtthgvrhhnpeevfeevudduieetgeehveehveehteefleeuhfefteefhffh hfettedtkeefudeuveenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgpdhpsh ihtghophhgrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnhgspg hrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepshhivhgrphho shhtghhrvghsseihrghhohhordgtohhmpdhrtghpthhtohepmhhmohhntghurhgvsehgmh grihhlrdgtohhmpdhrtghpthhtoheplhgruhhrvghniidrrghlsggvsegthigsvghrthgv tgdrrghtpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlhesphhoshhtghhrvghsqh hlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 24 Jul 2025 20:48:54 -0400 (EDT) Message-ID: Date: Thu, 24 Jul 2025 17:48:53 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Is there any limit on the number of rows to import using copy command To: "sivapostgres@yahoo.com" , Merlin Moncure , Laurenz Albe Cc: Pgsql-general References: <1453510076.1900935.1753260637232.ref@mail.yahoo.com> <1453510076.1900935.1753260637232@mail.yahoo.com> <2129916799.2277829.1753359532611@mail.yahoo.com> <26359739.2491053.1753401573405@mail.yahoo.com> Content-Language: en-US From: Adrian Klaver In-Reply-To: <26359739.2491053.1753401573405@mail.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/24/25 16:59, sivapostgres@yahoo.com wrote: > 1.  Testcase.  Created a new database, modified the triggers (split into > three), populated required master data, lookup tables.  Then transferred > 86420 records. Checked whether all the 86420 records inserted in table1 > and also whether the trigger created the required records in table2. >  Yes, it created. > > 2.  In the test case above, the total time taken to insert 86420 records > is 1.15 min only.   Earlier (before splitting the triggers) we waited > for more than 1.5 hrs first time and 2.5 hrs second time with no records > inserted. > > 3.  Regarding moving the logic to procedure.  Won't the trigger work? > Will it be a burden for 86420 records?  It's working, if we insert few > thousand records.  After split of trigger function, it's working for > 86420 records.  Are triggers overhead for handling even 100000 records? > In production system, the same (single) trigger is working with 3 > millions of records.  There might be better alternatives to triggers, > but triggers should also work.  IMHO. Reread this post, in the thread, from Laurenz Albe: https://www.postgresql.org/message-id/de08fd016dd9c630f65c52b80292550e0bcdea4c.camel%40cybertec.at > > 4.  Staging tables.  Yes, I have done that in another case, where there > was a need to add data / transform for few more columns.  It worked like > a charm.  In this case, since there was no need for any other > calculations (transformation), and with just column to column matching, > I thought copy command will do. There is a transformation, you are moving data to another table. That is overhead, especially if the triggers are not optimized. > > Before splitting the trigger into three, we tried > 1.  Transferring data using DataWindow / PowerBuilder (that's the tool > we use to develop our front end).  With the same single trigger, it took > few hours (more than 4 hours, exact time not noted down) to transfer the > same 86420 records.  (Datawindow fires insert statements for every > row).  Works, but the time taken is not acceptable. INSERTs by row is going to be slow, especially if the tool is doing a commit for each which I suspect it is. Check the Postgres logs. > > 2.  Next, we split the larger csv file into 8, with each file containing > 10,000 records and the last one with 16420 records.  Copy command > worked.  Works, but the time taken to split the file not acceptable.  We > wrote a batch file to split the larger csv file.  We felt batch file is > easier to automate the whole process using PowerBuilder. I find most GUI tools create extra steps and overhead. My preference are simpler tools e.g. using Python csv module to batch/stream rows that the Python psycopg2 Postgres driver can insert or copy into the database. See: https://www.psycopg.org/psycopg3/docs/basic/copy.html > > 3.  What we observed here, is insert statement succeeds and copy command > fails, if the records exceed a certain no.  Haven't arrived the exact > number of rows when the copy command fails. > > Will do further works after my return from a holiday. > > Happiness Always > BKR Sivaprakash > > > > On Thursday 24 July, 2025 at 08:18:07 pm IST, Adrian Klaver > wrote: > > > On 7/24/25 05:18, sivapostgres@yahoo.com > wrote: > > Thanks Merlin, adrain, Laurenz > > > > As a testcase, I split the trigger function into three, one each for > > insert, update, delete, each called from a separate trigger. > > > > IT WORKS!. > > It worked before, it just slowed down as your cases got bigger. You need > to provide more information on what test case you used and how you > define worked. > > > > > Shouldn't we have one trigger function for all the three trigger > > events?  Is it prohibited for bulk insert like this? > > No. Triggers are overhead and they add to the processing that need to be > done for moving the data into the table. Whether that is an issue is a > case by case determination. > > > > > I tried this in PGAdmin only, will complete the testing from the program > > which we are developing, after my return from holiday. > > From Merlin Moncure's post: > > "* reconfiguring your logic to a procedure can be a better idea; COPY > your data into some staging tables (perhaps temp, and indexed), then > write to various tables with joins, upserts, etc." > > I would suggest looking into implementing the above. > > > > > > Happiness Always > > BKR Sivaprakash > > > > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > -- Adrian Klaver adrian.klaver@aklaver.com