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 1ozYxB-0006fa-RF for pgsql-general@arkaria.postgresql.org; Mon, 28 Nov 2022 07:53:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ozYxA-0006S3-Jh for pgsql-general@arkaria.postgresql.org; Mon, 28 Nov 2022 07:53:24 +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 1ozYxA-0006Rs-4i for pgsql-general@lists.postgresql.org; Mon, 28 Nov 2022 07:53:24 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ozYx3-00029h-BZ for pgsql-general@lists.postgresql.org; Mon, 28 Nov 2022 07:53:23 +0000 Received: by mail-ej1-x631.google.com with SMTP id b2so7366792eja.7 for ; Sun, 27 Nov 2022 23:53:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=jyae5U9hDMcR7HrMxm9GwbHCfvfaYqN/gtAPe4Rzfyk=; b=orSA8QrjcjEjRKxiPTLCH9qavCzKWXLIO5yhtQ6rH2tb4jGVJ86ORMY/s9lpHAJY+c L9FHmVzgKNc8d7oeLbxPvT8YB+GkTrAZhxf6wFs1vmjqwh2/QJviJmR6lf/usqTVpmGH XiIvDJLKm6nR+Ng77eHYAgVOoBJMVS/0taarBrEAiEOdtccmP8/0OWsyUeYaekxjVzOh eof0SzzkVyefLd9J8eY/WYLUAs9s/XGK0IwQxivt3F3OF9DxDt8NMds4BVKWZcJCm1UY G6BIhEt4vQ+06Zt/aGD+EoB6ICoTRerz2oTNTY55ucvpfYvqq2HaO8Sr7TE2BMRiBkAA 4dVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=jyae5U9hDMcR7HrMxm9GwbHCfvfaYqN/gtAPe4Rzfyk=; b=Wgvf1jcJWUIYHiYiumJAjTH3Joggg0gsBHsK4pH2irHnYsdPURuVxaf5UNNV5usC6a 2ctpiGMpBAVpJ9PKZvr3AL3e2qbEKWZhIpoGK8x6DFyLnD+HIaaz47niPEAGmk2Od32Y PfCCbWHjug2cGuxFg9mF5AmBgqNhmQ27OjSLFcc5KwaYfysoPoCVESHas6tzOcdUc6kI dM2cEh9BNjmyPK80RxtjUfyPs8Ld0EdBf//8I8CrxvDts4fRCsJ9eShUNUxrcDAdrneC XTzmyumS+VYUa0uNAVZK6HID2GlIVIV7JWTxhV1JaWkh50xsG+or2nyY7vCCnzsXus65 Y66g== X-Gm-Message-State: ANoB5pklosvns0KW+LcjvERnErSlkqO0iyfVi7hEFDgXyQdeXUSbTXRw gZLx5cVTQWKckTUlxNntcVokZTXRMp8r2A== X-Google-Smtp-Source: AA0mqf74sUt6GZuwDsM01T3/rdVoekyLKxXnGTLRnDQejBvl/C44F8lruUtKpcUJGh3cVxO2AkKSAw== X-Received: by 2002:a17:906:1682:b0:78d:6ba1:74dd with SMTP id s2-20020a170906168200b0078d6ba174ddmr43383963ejd.119.1669621996123; Sun, 27 Nov 2022 23:53:16 -0800 (PST) Received: from localhost.localdomain ([2001:871:5e:b47b:e706:88d7:ceb1:a099]) by smtp.gmail.com with ESMTPSA id r9-20020a50aac9000000b00461c6e8453dsm4914689edc.23.2022.11.27.23.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 23:53:15 -0800 (PST) Message-ID: <0d8aa1b7534fd01845b7e15651b42f9d949a2dff.camel@cybertec.at> Subject: Re: autovacuum hung on simple tables From: Laurenz Albe To: senor , "pgsql-general@lists.postgresql.org" Date: Mon, 28 Nov 2022 08:53:15 +0100 In-Reply-To: References: <307bde85482f177cfd0d2bcefc00b61b601a3edc.camel@cybertec.at> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2022-11-28 at 04:05 +0000, senor wrote: > I'm a little late getting back to this but still have no solution. > > I had inadvertently executed a vacuum freeze on a table that pg_stat_activity > indicated was currently being autovacuumed. The manual vacuum succeeded while > leaving the previous autovacuum still showing active in pg_stat_activity. No, that cannot be. VACUUM processes are mutually exclusive. It could have been another autovacuum worker (different "pid"). > Manual vacuum always completes, never stalls, but also often does not appear > in pg_stat_progress_vacuum unless it's a longer process. It *does* appear in "pg_stat_progress_vacuum", but perhaps you are too slow to catch it. > It appears the process completes the vacuum but does not register that fact. > relfrozenxid of the main table is what would be expected but an associated > toast table was still very old. Cancelling all pending vacuums of the table > and manually running vacuum completes in a few seconds and both the main > relation and toast are updated as expected with last vacuum time updated > in pg_stat_all_tables. Obviously autovacuum devided to process the main table, but not the TOAST table. That is normal. Manual VACUUM processes both, unless you specify the option PROCESS_TOAST OFF. > Autoacuum and autovacuum analyze both get hung. No, they don't; not unless they are anti-wraparound autovacuum runs and you are holding high locks on the table in a long running transaction. They may be slow to complete, because in v11 autovacuum by default is very slow indeed, as "autovacuum_vacuum_cost_delay" is 20ms. > I often see the same table listed multiple times in pg_stat_activity with > different pids and: > state: active > backend_type: autovacuum worker > wait_event_type: blank > state_change: 10-15 seconds after backend_start - about how long it takes > to manually run vacuum on most tables. That can be parallel workers that are used to scan indexes. > What exactly does autovacuum rely on in the stats file? I ran strace on a > hung autovacuum process and saw a repeated read of > /run/postgresql/db_16384.stat (tempfs). The file is 740MB which is about > the same as other similar installations I've reviewed. I'm lacking in overall > experience in this though. I don't know either, and I am too lazy to read the code on that, but I suspect that it has no connection to your problem. > One final oddity: > I ran a query for oldest relfrozenxid and redirected to file. The query took > around a minute. A few seconds after it finished, I queried for 'active' in > pg_stat_activity and the oldest relfrozenxid query was still listed. > A few seconds later it had cleared. That sounds weird and is hard to believe. Are the disk or the CPU under extreme stress? Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com