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 1jklFE-00042r-Av for pgsql-general@arkaria.postgresql.org; Mon, 15 Jun 2020 09:17:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jklFD-0000hv-2N for pgsql-general@arkaria.postgresql.org; Mon, 15 Jun 2020 09:17:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jklFC-0000gT-Ml for pgsql-general@lists.postgresql.org; Mon, 15 Jun 2020 09:17:30 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jklF9-0006tv-NG for pgsql-general@postgresql.org; Mon, 15 Jun 2020 09:17:30 +0000 Received: by mail-ej1-x644.google.com with SMTP id f7so16626912ejq.6 for ; Mon, 15 Jun 2020 02:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=cD1UbFWIt3jIQlszGeHbYNxXPn+W478J/A2RyhmazgM=; b=RNinsXIoMwQWvp5dyAQi+Q8Alu8+F6T8DsBnFBVLGovhccXhpY3cYXG/fNAUYpRiLn 0OCUkmPc918cS9x44H1nNmISMd0CqSnYiHbS/qQqxCHnphwDHactkQWEki+oQcfbmOtH 3l011KGw6+fYw1Xbv8aJTNd3IrPBwJT0vX0cNAU/ouB+jbA5rqgPh9F7yt+8rQtS1f6J hqGxyMQZjwJ0EHn4ga6SKI77zO7aJwq4YEYzf/tpKKc+FzjlstZgjKxgX3zaZoL0demZ dRsjM73BC8WZ7IWepP1qC9w+ogX2M/DYnQJMIabWKgPagqI8VLeUzBQRg6bcfpdJ0Xlw NIYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=cD1UbFWIt3jIQlszGeHbYNxXPn+W478J/A2RyhmazgM=; b=EtVgCifms3qUa12HexZHLtpOTpLTMAFaNzFOn1HfpISmnOjK/e1KZBBMIUJcSzogK0 Pz5bfTTQb08gd99olUxSzfQVKSnxEPO6Uhg7ESQ/CzfG9i1Ri3pa8aCj+gqKWQYEMQsg Ubn6fnI7xx9NUXOSxsh13lhbbM0NIaVPWFYVm0S+RQTWcTvhGsuZv18ivSYZwoudVNte oiCUjCJleW7KZ0m3eJ605aNtJ2u9qEnYEjtyjd3sX542pUQ7oSFcH7heqJTaAIq0zzC/ J+1s+WNjA3UhUkzS64YFYpVZXWxAbpCVYDTe59Qih5d0lbgZyNZdYMLBPUCyUng7tXK/ FDlQ== X-Gm-Message-State: AOAM533XU5STSvLQXVERvQ00IRED46BeFsRHDqz06W0v+xxOa+ziiCeC qJ9NT4oq4ENzhJtmgqlNVZeY3Q== X-Google-Smtp-Source: ABdhPJxmYenZM6h2Yh+fa6NHM7kN07G+cVh6dTGYBSDL9gvcm3XtlfqtyeT0yyfS2HG+ybAInK8JXg== X-Received: by 2002:a17:906:3e84:: with SMTP id a4mr23529692ejj.372.1592212646298; Mon, 15 Jun 2020 02:17:26 -0700 (PDT) Received: from localhost.localdomain (217-149-168-120.nat.highway.telekom.at. [217.149.168.120]) by smtp.gmail.com with ESMTPSA id o12sm7958884edq.7.2020.06.15.02.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 02:17:25 -0700 (PDT) Message-ID: Subject: Re: TOAST table size in bytes growing despite working autovacuum From: Laurenz Albe To: Kristjan Mustkivi , pgsql-general@postgresql.org Date: Mon, 15 Jun 2020 11:17:24 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, 2020-06-15 at 11:51 +0300, Kristjan Mustkivi wrote: > Dear all, > > I have a table which contains a "json" column and it gets heavily > updated. Before introducing toast.autovacuum_vacuum_scale_factor=0.05 > and toast.autovacuum_vacuum_cost_limit=1000 this table bloated to > nearly 1TB in a short while. Now the n_dead_tup value is nicely under > control but still, the table is slowly growing in size but not in > rows. The odd thing is that the value of n_live_tup in the TOAST is > twice of that in the main table. I know it is a statistical value, but > this does not feel right. > > Why is that? What to do to make it stop growing? > > select n_live_tup, n_dead_tup, last_autovacuum, autovacuum_count from > pg_stat_all_tables where relname = 'player_data_states'; > ─[ RECORD 1 ]────┬───────────────────────────── > n_live_tup │ 84730 > n_dead_tup │ 8336 > last_autovacuum │ 2020-06-15 08:23:58.88791+00 > autovacuum_count │ 11306 > > select n_live_tup, n_dead_tup, last_autovacuum, autovacuum_count from > pg_stat_all_tables where relname = 'pg_toast_293406'; > ─[ RECORD 1 ]────┬────────────────────────────── > n_live_tup │ 168486 > n_dead_tup │ 9835 > last_autovacuum │ 2020-06-15 08:33:22.566087+00 > autovacuum_count │ 41021 > > The PG server is 11.7 (Debian 11.7-2.pgdg90+1) > > And the table is > > Column │ Type │ Nullable │ Storage > ────────────────┼───────────────────┼──────────┼──────── > id │ bigint │ not null │ plain > cage_player_id │ bigint │ not null │ plain > cage_code │ integer │ not null │ plain > player_data │ json │ │ extended > update_time │ timestamp with tz │ not null │ plain > Indexes: > "player_data_states_pk" PRIMARY KEY, btree (id) > "player_data_states_uk1" UNIQUE CONSTRAINT, btree (cage_player_id, > cage_code) > Referenced by: > TABLE "awards.player_data_state_changes" CONSTRAINT > "player_data_state_changes_fk1" FOREIGN KEY (player_data_state_id) > REFERENCES awards.player_data_states(id) > Publications: > "awards" > Options: fillfactor=90, toast.autovacuum_vacuum_scale_factor=0.05, > toast.autovacuum_vacuum_cost_limit=1000 It is not surprising if there are more entries in the TOAST table than in the base table: a big value will be split in several chunks, each of which is an entry in the TOAST table. To see if the TOAST table is bloated, use pgstattuples: SELECT * FROM pgstattuple('pg_toast.pg_toast_293406'); Vacuum does not remove existing bloat, it just prevents increased bloat. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com