Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olAJ6-0006gw-VL for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 14:44:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1olAJ5-0005VD-RY for pgsql-general@arkaria.postgresql.org; Wed, 19 Oct 2022 14:44:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1olAJ5-0005V4-HD for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 14:44:31 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1olAJ2-0006vF-Nv for pgsql-general@lists.postgresql.org; Wed, 19 Oct 2022 14:44:30 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1321a1e94b3so20915942fac.1 for ; Wed, 19 Oct 2022 07:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=zWMePlwLV3V+Wi3GCvsBfN5uuyq+K60bsl0VgvDvvys=; b=L8c/OeU2ugGArjUF06IJx5XUY1OHNZvxbb+Pi0OHOV6TQNt7oX0Haz+Yo/Ev1tBTLR /gTj8lXLGhv+gNAIRPoAB2ROJuyADxxK2W/54ug5Pwzkjk2dII9PTUVoswX3mxr8qcFO WdhofgkLbQATJk2N3iJn4J9u1MubLgVZAZKYj2K6Tz8KQmV0LbXPYmKnZLTNlRQK7BZx rM6CkZNnoy2513IkTqptIyQ5zPziVqOIgn+BTJWbCxDj3+P5Ps352TshUQjqPYkC0+Bi hn03ypXWHJmVdN0lgDm/VDy2WMZnTjzAXQjwMwqCxvIfh3niZpIN5ZG3j9K5zoawXe/T 26HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=zWMePlwLV3V+Wi3GCvsBfN5uuyq+K60bsl0VgvDvvys=; b=snkpV4eTA9t3GGhum0Miiut7rDW//cgkBH4L1px486VDnCUGmTbRN0bcR9ePJ/bY/9 BWcNzH5o3Wt150awUP1hoWOzUo8rA58AyBfqwIKCjkMgbS89KBg+WUmRfuJYiU0H5B7G NKelzSyTD2BQ1n/mDpv9vAXeBRMgfEbX4T07ag6WW+Ysd86CncA2PfYNXFoZCUuRHNJS MmXtM9yzrX7MFaVTO7fQUq9xfi47xEmiKdNnXejg/ao5ViEFwl/kKZJ+3Ue/wMX3dLn+ smJKvUYZYBBpUtuYpChV3MMS6K4Yja9zn2v+7z9EooWSSHFizqFYrMLDCVWCtOrRvbi6 tzGQ== X-Gm-Message-State: ACrzQf3w9l/hvAD4kf8dvzOCavEfAr/wqfDERIm4hFuSUqx6vxtEKrNu JPBh1epRfhSQbKXAk7W4FQTzQikflq0= X-Google-Smtp-Source: AMsMyM5mrpi6fGdr8y97E31Z9ewIBGMARh0w4xeWXKUCeJQv11HGNmzoixMeaHiFRmGjJxhjMBkJEQ== X-Received: by 2002:a05:6870:7392:b0:131:8d0e:bdb7 with SMTP id z18-20020a056870739200b001318d0ebdb7mr5092642oam.274.1666190667739; Wed, 19 Oct 2022 07:44:27 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id r8-20020a056871088800b0010e73e252b8sm7593766oaq.6.2022.10.19.07.44.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 19 Oct 2022 07:44:27 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------l9080JudXdrqbww0qqijOm23" Message-ID: Date: Wed, 19 Oct 2022 09:44:26 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: COMMIT IN STORED PROCEDURE WHILE IN A LOOP Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <353091661.109766.1666124045054.ref@mail.yahoo.com> <353091661.109766.1666124045054@mail.yahoo.com> <72BEC008-DC6C-4D80-80A6-E1634CFFA656@thebuild.com> <80B77102-84D3-4AD8-B138-1C0C3341855B@thebuild.com> <2b93e12697bb273c493b47e04c762b39a66910ab.camel@gmail.com> <1c4cb79ca48fa14246fbe78374da4ef9ac435a0a.camel@gmail.com> From: Ron In-Reply-To: <1c4cb79ca48fa14246fbe78374da4ef9ac435a0a.camel@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------l9080JudXdrqbww0qqijOm23 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 10/19/22 08:06, Mladen Gogala wrote: [snip] > >> >> Applications do this kind of thing all the time, very successfully; it >> was just that the loop was in the application rather than in the procedure. >> >> High commit rates happen all the time, and they don't break PostgreSQL.  >> For example, an IoT application collecting sensor data and doing many >> inserts per second is also doing many commits per second, since each bare >> INSERT is in its own transaction.  PostgreSQL handles it just fine. > > Point of my post is that the business logic, in your case it's IoT > sensors, determines what is transaction and when to commit. Advice like > "commit often and commit early", to paraphrase the famous Chicago mayor, > is easy to find but I would take it with grain of salt. In the normal course of operation (i.e, not when bulk loading), you /should/ commit at the end of every "business transaction". We've committed after X business  when running stovepipe "batch" jobs processing input files.  In those cases, though, we had to track progress through the file; in the case of a rollback, the application had to go back to the last input file "save point" and start over. -- Angular momentum makes the world go 'round. --------------l9080JudXdrqbww0qqijOm23 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 10/19/22 08:06, Mladen Gogala wrote:
[snip]


Applications do this kind of thing all the time, very successfully; it was just that the loop was in the application rather than in the procedure.

High commit rates happen all the time, and they don't break PostgreSQL.  For example, an IoT application collecting sensor data and doing many inserts per second is also doing many commits per second, since each bare INSERT is in its own transaction.  PostgreSQL handles it just fine.

Point of my post is that the business logic, in your case it's IoT sensors, determines what is transaction and when to commit. Advice like "commit often and commit early", to paraphrase the famous Chicago mayor, is easy to find but I would take it with grain of salt.

In the normal course of operation (i.e, not when bulk loading), you should commit at the end of every "business transaction".  We've committed after X business  when running stovepipe "batch" jobs processing input files.  In those cases, though, we had to track progress through the file; in the case of a rollback, the application had to go back to the last input file "save point" and start over.

--
Angular momentum makes the world go 'round.
--------------l9080JudXdrqbww0qqijOm23--