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 1uMXDo-00EZpi-Gk for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 19:22:52 +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 1uMXDl-003fYa-Gi for pgsql-general@arkaria.postgresql.org; Tue, 03 Jun 2025 19:22:50 +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 1uMXDl-003fYP-4r for pgsql-general@lists.postgresql.org; Tue, 03 Jun 2025 19:22:49 +0000 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uMXDj-0003Ja-3D for pgsql-general@postgresql.org; Tue, 03 Jun 2025 19:22:49 +0000 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-3d6d6d82633so16802075ab.0 for ; Tue, 03 Jun 2025 12:22:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748978565; x=1749583365; darn=postgresql.org; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=8J3676faXPU/j1Cs559fhm0sT6ipeiv/vrdU7vVrjoA=; b=Sy08xsh20CweTMghR6gjsdyHsIBzxKM3GH8UHbSxA0ucLDik83HyZcMdfOnBEJa8Tp crruU/SRdukAXIGK7omWednVdBEnMEj/ubypqYhBHACg8N+iTadn5F5c3yRH3Bb0DK1J zbGYILwObPsA0f8bIV+tQx0BcFgchzFsgHqJ4j9v1v5je5HNoKwWvalJb6qs/cTrWcqx 1soqzC1OkyxaWxwt9OixkXC9TF2Qqk9bBjoyNX8J6jYuVyZOncHaIfsKSRqjNk8REjZ6 LtKqxjER4BDkB00jtfZkFW8RVzln3tQN+clCnL5qtEyITOxVtAWNSY5Nq4uALk0e72bh lu2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748978565; x=1749583365; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8J3676faXPU/j1Cs559fhm0sT6ipeiv/vrdU7vVrjoA=; b=nbHHBsMA58A6ejO869RyVUAOctFdq6g4BbKpIdK2T33lislis/Au9i9otUbbJ7KgQK 5dGKsCwvTjZMVkUSBo8+5HcUF+wKE/Cw87Wgyoj6ld1Azi2+acnQ2nztrjvpycVTeokJ 9BFYOXrdz8Am94b7uQox/dyARObaVuJDbB4i7dXqTNfRNYfEEP88WdHP+lYNadKWinZb j3T1GF088MlN9nvdaeOlcAsjh87kz/t/XLQHS+SSkMISg3V8PrffuOw0f5H9SgZZCTla Z4ukRHsPCFDZkdMJlhrHAgxug8bC5NAvREjM2qzop875kFGiLkOBgcI1+fyQWAal0vEJ p29g== X-Gm-Message-State: AOJu0YxppYB/gQuQzZno4FK9UqVxgz70dKWmFVqo5T7HNRfqpkEROPqi JsjlVURVtE88fFCyY+drjHxdc2NATgUqOiOnDXZjQ9jUTXnd8rXZ8ISjpu6Amg== X-Gm-Gg: ASbGnctIkS3O+RuI4rtrfaimYU15qPRWlx3iX8HlFpHPDG0x/5Ny4a2jUXgYcZ3zKXP wO87wNvVAMFIOq8K86yK2pMfK14jnuVV5uzTK/QHRpKdquev/bSj36uy7g/KiUukOFjhpup5tBg 4SRXYHPvIiq5BsPIa7xwc6tTfb7t2QUCstGktnYGVQdNk7okGBfyL0l9fAgENcpuUA62kVEA7pK vvKC3oGevwO4eA5Hz9tJK9qLLH8/vPFyrKCzRE4qOM12XXN2M3M/XMZi2I+cfhrzw2WTH91JpmL MCI1hDopF5wAW8oE5hvaYxeSDfzNNacE9uDMoGB3kUg/alHkPVV5bEH63iYLiXbp X-Google-Smtp-Source: AGHT+IE1UiOokiffT0+ib5JYBCgdAizqtsOAwkk80ebhN4NnlKj5jy4tA0IL/GRCH8K6+Tf6nofGmw== X-Received: by 2002:a05:6e02:1fc3:b0:3dd:babf:9b00 with SMTP id e9e14a558f8ab-3ddbecf1cd3mr1467655ab.1.1748978564881; Tue, 03 Jun 2025 12:22:44 -0700 (PDT) Received: from smtpclient.apple ([162.218.223.15]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4fdd7ef6ae3sm2334068173.109.2025.06.03.12.22.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jun 2025 12:22:44 -0700 (PDT) From: Matthew Tice Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Sudden increase in n_dead_tup with no corresponding insert/update/delete Message-Id: <006D484F-66AC-4734-A7E5-2EFBB6CEC1FA@gmail.com> Date: Tue, 3 Jun 2025 13:22:33 -0600 To: pgsql-general@postgresql.org X-Mailer: Apple Mail (2.3826.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi all, While investigating some potential vacuum improvements to make to a = table I happened to notice that one table (along with others) will = suddenly increase the number of n_dead_tup reported in = pg_stat_user_tables without a corresponding increase in the inserts, = updates, or deletes. For instance, running this query in a 1 second loop select * from pg_stat_user_tables where relname =3D = 'casino_account_history_lines'; I can see the n_dead_tup column increases until which time the = autovacuum process finishes vacuuming the table. Example: -[ RECORD 1 ]-------+------------------------------ relid | 33378 schemaname | public relname | casino_account_history_lines seq_scan | 1122 seq_tup_read | 178229588443 idx_scan | 456779105 idx_tup_fetch | 5539267637 n_tup_ins | 45093031 n_tup_upd | 47289203 n_tup_del | 0 n_tup_hot_upd | 0 n_live_tup | 1646966715 n_dead_tup | 1356331 n_mod_since_analyze | 11498 n_ins_since_vacuum | 6288 last_vacuum | 2025-06-03 14:57:43.46009+00 last_autovacuum | 2025-06-03 19:09:21.595322+00 last_analyze | 2025-06-03 14:57:54.848185+00 last_autoanalyze | 2025-06-03 19:09:48.390396+00 vacuum_count | 2 autovacuum_count | 3973 analyze_count | 6 autoanalyze_count | 3078 -- -- At this point the table is no longer in pg_stat_progress_vacuum and = `n_dead_tup` has dropped from 1356331 to 4302 -- -[ RECORD 1 ]-------+------------------------------ relid | 33378 schemaname | public relname | casino_account_history_lines seq_scan | 1122 seq_tup_read | 178229588443 idx_scan | 456779364 idx_tup_fetch | 5539267804 n_tup_ins | 45093063 n_tup_upd | 47289232 n_tup_del | 0 n_tup_hot_upd | 0 n_live_tup | 1646961282 n_dead_tup | 4302 n_mod_since_analyze | 11559 n_ins_since_vacuum | 2 last_vacuum | 2025-06-03 14:57:43.46009+00 last_autovacuum | 2025-06-03 19:12:48.107816+00 last_analyze | 2025-06-03 14:57:54.848185+00 last_autoanalyze | 2025-06-03 19:09:48.390396+00 vacuum_count | 2 autovacuum_count | 3974 analyze_count | 6 autoanalyze_count | 3078 -- This seems normal to me, however, while still looking at = pg_stat_user_tables in a loop, `n_dead_tup` steadily increases to, in = this latest run, `5038` at which point, one second later the number = jumps to above 1.2 million: Tue 03 Jun 2025 07:13:11 PM UTC (every 1s) -[ RECORD 1 ]-------+------------------------------ relid | 33378 schemaname | public relname | casino_account_history_lines seq_scan | 1122 seq_tup_read | 178229588443 idx_scan | 456784246 idx_tup_fetch | 5539271612 n_tup_ins | 45093719 n_tup_upd | 47289968 n_tup_del | 0 n_tup_hot_upd | 0 n_live_tup | 1646961938 n_dead_tup | 5038 n_mod_since_analyze | 12951 n_ins_since_vacuum | 658 last_vacuum | 2025-06-03 14:57:43.46009+00 last_autovacuum | 2025-06-03 19:12:48.107816+00 last_analyze | 2025-06-03 14:57:54.848185+00 last_autoanalyze | 2025-06-03 19:09:48.390396+00 vacuum_count | 2 autovacuum_count | 3974 analyze_count | 6 autoanalyze_count | 3078 Tue 03 Jun 2025 07:13:12 PM UTC (every 1s) -[ RECORD 1 ]-------+------------------------------ relid | 33378 schemaname | public relname | casino_account_history_lines seq_scan | 1122 seq_tup_read | 178229588443 idx_scan | 456784464 idx_tup_fetch | 5539271752 n_tup_ins | 45093746 n_tup_upd | 47289993 n_tup_del | 0 n_tup_hot_upd | 0 n_live_tup | 1647255972 n_dead_tup | 1290579 n_mod_since_analyze | 2 n_ins_since_vacuum | 685 last_vacuum | 2025-06-03 14:57:43.46009+00 last_autovacuum | 2025-06-03 19:12:48.107816+00 last_analyze | 2025-06-03 14:57:54.848185+00 last_autoanalyze | 2025-06-03 19:13:12.125828+00 vacuum_count | 2 autovacuum_count | 3974 analyze_count | 6 autoanalyze_count | 3079 I don't understand where this large increase is coming from when there = are no corresponding inserts, updates, or deletes (at the magnitude). = This entire process repeats itself and, as mentioned, the same thing is = happening on other observed tables. I'm running version 'PostgreSQL 15.6 (Ubuntu 15.6-1.pgdg22.04+1)' Thanks, Matt=