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 1tvFHY-002j5p-CN for pgsql-general@arkaria.postgresql.org; Thu, 20 Mar 2025 12:45:56 +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 1tvFHW-00144m-AX for pgsql-general@arkaria.postgresql.org; Thu, 20 Mar 2025 12:45:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tvFHV-00144e-Up for pgsql-general@lists.postgresql.org; Thu, 20 Mar 2025 12:45:54 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tvFHT-0008SY-1y for pgsql-general@lists.postgresql.org; Thu, 20 Mar 2025 12:45:53 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-548409cd2a8so781786e87.3 for ; Thu, 20 Mar 2025 05:45:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742474750; x=1743079550; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=g4/Z3varPDFUsIHzpo46kRDgt391guJ28bhCbfW1Yp4=; b=nbLZgoX4RYVVkWtoByHn1QgiTcFLmUe7pSPgHfuKaF2Cx9FirfquACNjDmU3tE9ZZJ BizC1qeQSGHIQ7KuSasAkChIShIqe8C2/xmdQ5BD7lMCez8QwhwBQnI9PQZrFRPY1SEN UY0ZQyEOf7KFNs2luGRK2bzqCSYd4Ezfg0kzOmA0IaLMMCa8SfXIqhgkyGJCYog460zV /3SYoU2gKHI5WDmstYScWcWFlbekECbgCiVtGKof5mvlM5XZtiqpyopiKKn5EFcbjxBN K4Mytvvm+tCbi7W/r5mvYRcwL7fC6diGkKSwE7Ao+pTphDd4aiugsMxsLmMvTaBR8uM7 owJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742474750; x=1743079550; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g4/Z3varPDFUsIHzpo46kRDgt391guJ28bhCbfW1Yp4=; b=PSWRJBn4S0v1pqR3LvrdlGGVPazPwQu7k0t3+Itj3iB2tcQNc0tEIAf+f+VYkOJqep LCKfqfK42lAiq/VeNweIUU1TCFQdAxJ39BZdBo9E05eDAX/iTVZbUwJa9NdA5/qzbTqH QgXRyXm5WWc/eTj2t4ea2N7gQisgAIFEgiz6+9rb6+1RSCWTh8EMzjO555gsjgznK2Jv F+54f05D/XRv2nHCZwofh/AlEw97VjO7BDq7U4CyXZddure2I31qb5kI9Bio+7u0DAAW 3sdpMmgbLTrBldxROWkOXRWdoWASetVwwBA2q3NO4RXn8iiZytIpfphP/vpcAfgexNWE Q1QQ== X-Gm-Message-State: AOJu0Yyw/u0vmD90p7yFwc2HW1fOcdqiz08OJsMLy4+h/UA8idL0wiai IzeXawmctqy0i5dzFfXsB8uRCYBr2PGNhHZvBiZg77Q/zxN4DVIjoMBWT/oBNLpA7oNd/NM1g9a HPy/K7TtYZXSQWvHiJC3f3SbibDQ= X-Gm-Gg: ASbGncu2C+g50RklaO1jcDYgKHE2QbI6ziPobtTffKhRPXyKGqgsqkeZkYcFsOdAKbn iOlpOf/0F+y72JEoeyvoSivXm3XHJ1oWUMASKA0cDh93i7pjnnrt0AU+eYcWmt3zc+59dLx+r9q wkwfL5qHFuJN425N2tCtlZKgo= X-Google-Smtp-Source: AGHT+IEiRdhhjkC7h4sKmz5rteLVQFP6ebB++b3botXwT+qENwKSTI+Ybf6wQTqW5nXzcvmedCJF9LGRB4SBdC2IBTw= X-Received: by 2002:a05:6512:3d19:b0:549:8537:79d6 with SMTP id 2adb3069b0e04-54acb224461mr2797044e87.48.1742474750261; Thu, 20 Mar 2025 05:45:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Paul Allen Date: Thu, 20 Mar 2025 16:45:39 +0400 X-Gm-Features: AQ5f1JqDYthHZe8lRmd7r8xoVuMDa4zrmRThfMJfbT-xnWX8ENAjQ5pwlrKwHT4 Message-ID: Subject: Re: Bloated toast table with empty associated table To: Ron Johnson Cc: "pgsql-generallists.postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > It's the general principle that the _scale_factor defaults are in my expe= rience too high. Sorry, didn't mentioned Ok, thanks, I will use the cron task. It's toast behaviour still seems odd to me. Is there a way to prevent this behaviour at all, to not store rows which were failed to insert? On Thu, Mar 20, 2025 at 4:28=E2=80=AFPM Ron Johnson wrote: > > On Thu, Mar 20, 2025 at 8:22=E2=80=AFAM Paul Allen = wrote: >> >> > Instantaneously and repeatedly, while ignoring the error? >> Yes, that's how it should work and I probably can't do anything about it= . >> >> > Your _scale_factor values are too high. Drop them down to about 5%. >> >> Okay, but what about altering controlzone_passage table, where I set >> all _scale_factor >> values to 0? If this did not have an effect, then how will the value >> of 5% affect? Maybe I >> misunderstand, but the table does not change by any number of rows and >> its logical size >> remains zero. Anyway I will try it. > > > It's the general principle that the _scale_factor defaults are in my expe= rience too high. > > Like I said: "That's not the proximate cause, though" of this table's blo= at. > >> >> > I'd create a cron entry that does a regular "vacuumdb -d the_db -t co= ntrolzone_passage". How often you run it depends on how quickly it bloats. >> >> Seems like it is the only solution for now. > > > The autovacuum daemon can't know/see everything. > >> >> On Thu, Mar 20, 2025 at 4:03=E2=80=AFPM Ron Johnson wrote: >> > >> > On Thu, Mar 20, 2025 at 7:40=E2=80=AFAM Paul Allen wrote: >> >> >> >> Hello. >> >> >> >> Preconditions. >> >> >> >> I have some empty table and constantly try to execute `insert ... on >> >> conflict do update ...` on it. My data in row which I try to insert i= s >> >> invalid by violation of foreing key constraint, so I am getting error >> >> while inserting and table keeps being empty. This table have some byt= ea >> >> columns with default storage type. It's purpose is to keep images. >> >> PostgreSQL version is 15, everything is default, autovacuum settings = is >> >> >> >> ``` >> >> autovacuum on >> >> autovacuum_analyze_scale_factor 0.1 >> >> autovacuum_analyze_threshold 50 >> >> autovacuum_freeze_max_age 200000000 >> >> autovacuum_max_workers 3 >> >> autovacuum_multixact_freeze_max_age 400000000 >> >> autovacuum_naptime 60 >> >> autovacuum_vacuum_cost_delay 20 >> >> autovacuum_vacuum_cost_limit -1 >> >> autovacuum_vacuum_scale_factor 0.2 >> >> autovacuum_vacuum_threshold 50 >> >> autovacuum_work_mem -1 >> >> log_autovacuum_min_duration -1 >> > >> > >> > Your _scale_factor values are too high. Drop them down to about 5%. >> > >> > That's not the proximate cause, though. >> > >> >> >> >> ``` >> >> >> >> Problem. >> >> >> >> My backend application attempts unsuccessfully repeatedly to insert t= he >> >> same ~100 rows with images, >> > >> > >> > Instantaneously and repeatedly, while ignoring the error? >> > >> >> >> >> and despite table's row count remains 0, >> >> toast table's size is growing up permanently, reaching 100, 200, 300 = GB >> >> until it takes all available space. >> >> >> >> VACUUM FULL fixes this, but a want some automatic solution. I tried t= o >> >> alter table, believing that the settings below would force autovacuum= to >> >> clean toast anyway, but it had no effect. >> >> >> >> ``` >> >> alter table controlzone_passage set ( >> >> autovacuum_enabled =3D true, >> >> toast.autovacuum_enabled =3D true, >> >> autovacuum_vacuum_threshold =3D 0, >> >> toast.autovacuum_vacuum_threshold =3D 0, >> >> autovacuum_vacuum_scale_factor =3D 0, >> >> toast.autovacuum_vacuum_scale_factor =3D 0, >> >> autovacuum_analyze_threshold =3D 0, >> >> autovacuum_analyze_scale_factor =3D 0); >> >> ``` >> >> >> >> At the moment, my assumption is that the autovacuum is not working >> >> because the number of rows in the table does not change and remains >> >> zero. Any solution will suit me, for example, not to write rows to to= ast >> >> if their insertion failed. Or the proper setting of the autovacuum. >> >> Please tell me what can be done. >> > >> > >> > I'd create a cron entry that does a regular "vacuumdb -d the_db -t co= ntrolzone_passage". How often you run it depends on how quickly it bloats. >> > >> > -- >> > Death to , and butter sauce. >> > Don't boil me, I'm still alive. >> > lobster! > > > > -- > Death to , and butter sauce. > Don't boil me, I'm still alive. > lobster!