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 1nVMlP-0003MO-6t for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Mar 2022 00:16:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nVMlM-0005Gm-Ou for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Mar 2022 00:16:08 +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 1nVMlL-0005Ga-0o for pgsql-hackers@lists.postgresql.org; Sat, 19 Mar 2022 00:16:08 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nVMlE-0001ws-KT for pgsql-hackers@lists.postgresql.org; Sat, 19 Mar 2022 00:16:06 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B5CCE5C00B4; Fri, 18 Mar 2022 20:15:58 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 18 Mar 2022 20:15:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; bh=xfr+f5uWsH+Hbg LfVKXolf+GdOjKux/yk8472MuompA=; b=zy5Ray2WJ1/G9r3CxHDTMBmyA2Bbme qze1UUeR4zjEMJbFYbl3ThRoWMTHrfxUyMA5AQTxlUf60mdMZmySV0fmKjKjm/UG 2MRvUuK9UweC+gR5NnHTct6PaeP/Wi2LbwyXO1vCt2f8fik94kawpVQKAMzRpSiV MWbxJXbOKRrCrz8wG8jod5hDY/zVq3L3negbIvz+JgirSL0vyNt5SGXi8hAH1ZNA NGKzagUL6GXG9m/p7nbn4LnlE4s3PU/9uBQXupZPa3g7PFMwoG2QDS+vGfh6nZHC yp3K17TADjx484JuETM2zlJc6RQYe2JRtIjR5r7DifH83Fk8q2hzCOww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=xfr+f5uWsH+HbgLfVKXolf+GdOjKux/yk8472Muom pA=; b=T/DoecPnU8W6JtoJJBYGVva2ZxWbn2fzZDuCLBxnQAJhccq3TMgwbTQAW 681CXMPpIy+r0+2+dYzH2y1gYTelg2R6rGpYbFAyqrUbqy/NivPn5d8bQw49b/Qd LzbGOmUNPGveN4tDXUxA497wl65FQtqMn4prKj5zAWo4VrMJ6GyBH2epz2NktJn/ C23xrLoT4cHg2BnhxGeFJZ96IpEy2N2JWPsqKC9RRGjBfhm/d2wiX0ysFDal8V5l U8uh33Z6jp72D483lOpn8tf1u6mPWTieIalL5rQWMZp9nkUrvETH9KOmU1/CE2lu 0TW2HsSe+rVkxka3Vem9tAJmlca7A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudefjedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtugfgjgesthekredttddtjeenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepieduueejhfeufeffffffkeeitdfhleeuffeulefhkeehueejffefgffh ffffteffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Mar 2022 20:15:57 -0400 (EDT) Date: Fri, 18 Mar 2022 17:15:56 -0700 From: Andres Freund To: Nitin Jadhav Cc: Bharath Rupireddy , Matthias van de Meent , Ashutosh Sharma , Julien Rouhaud , Bruce Momjian , Tom Lane , Magnus Hagander , PostgreSQL Hackers Subject: Re: Report checkpoint progress with pg_stat_progress_checkpoint (was: Report checkpoint progress in server logs) Message-ID: <20220319001556.atuqbmafvc73pa2k@alap3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, This is a long thread, sorry for asking if this has been asked before. On 2022-03-08 20:25:28 +0530, Nitin Jadhav wrote: > * Sort buffers that need to be written to reduce the likelihood of random > @@ -2129,6 +2132,8 @@ BufferSync(int flags) > bufHdr = GetBufferDescriptor(buf_id); > > num_processed++; > + pgstat_progress_update_param(PROGRESS_CHECKPOINT_BUFFERS_PROCESSED, > + num_processed); > > /* > * We don't need to acquire the lock here, because we're only looking > @@ -2149,6 +2154,8 @@ BufferSync(int flags) > TRACE_POSTGRESQL_BUFFER_SYNC_WRITTEN(buf_id); > PendingCheckpointerStats.m_buf_written_checkpoints++; > num_written++; > + pgstat_progress_update_param(PROGRESS_CHECKPOINT_BUFFERS_WRITTEN, > + num_written); > } > } Have you measured the performance effects of this? On fast storage with large shared_buffers I've seen these loops in profiles. It's probably fine, but it'd be good to verify that. > @@ -1897,6 +1897,112 @@ pg_stat_progress_basebackup| SELECT s.pid, > s.param4 AS tablespaces_total, > s.param5 AS tablespaces_streamed > FROM pg_stat_get_progress_info('BASEBACKUP'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20); > +pg_stat_progress_checkpoint| SELECT s.pid, > + CASE s.param1 > + WHEN 1 THEN 'checkpoint'::text > + WHEN 2 THEN 'restartpoint'::text > + ELSE NULL::text > + END AS type, > + ((((((( > + CASE > + WHEN ((s.param2 & (1)::bigint) > 0) THEN 'shutdown '::text > + ELSE ''::text > + END || > + CASE > + WHEN ((s.param2 & (2)::bigint) > 0) THEN 'end-of-recovery '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param2 & (4)::bigint) > 0) THEN 'immediate '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param2 & (8)::bigint) > 0) THEN 'force '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param2 & (16)::bigint) > 0) THEN 'flush-all '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param2 & (32)::bigint) > 0) THEN 'wait '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param2 & (128)::bigint) > 0) THEN 'wal '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param2 & (256)::bigint) > 0) THEN 'time '::text > + ELSE ''::text > + END) AS flags, > + ((((((( > + CASE > + WHEN ((s.param3 & (1)::bigint) > 0) THEN 'shutdown '::text > + ELSE ''::text > + END || > + CASE > + WHEN ((s.param3 & (2)::bigint) > 0) THEN 'end-of-recovery '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param3 & (4)::bigint) > 0) THEN 'immediate '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param3 & (8)::bigint) > 0) THEN 'force '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param3 & (16)::bigint) > 0) THEN 'flush-all '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param3 & (32)::bigint) > 0) THEN 'wait '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param3 & (128)::bigint) > 0) THEN 'wal '::text > + ELSE ''::text > + END) || > + CASE > + WHEN ((s.param3 & (256)::bigint) > 0) THEN 'time '::text > + ELSE ''::text > + END) AS next_flags, > + ('0/0'::pg_lsn + ( > + CASE > + WHEN (s.param4 < 0) THEN pow((2)::numeric, (64)::numeric) > + ELSE (0)::numeric > + END + (s.param4)::numeric)) AS start_lsn, > + to_timestamp(((946684800)::double precision + ((s.param5)::double precision / (1000000)::double precision))) AS start_time, > + CASE s.param6 > + WHEN 1 THEN 'initializing'::text > + WHEN 2 THEN 'getting virtual transaction IDs'::text > + WHEN 3 THEN 'checkpointing replication slots'::text > + WHEN 4 THEN 'checkpointing logical replication snapshot files'::text > + WHEN 5 THEN 'checkpointing logical rewrite mapping files'::text > + WHEN 6 THEN 'checkpointing replication origin'::text > + WHEN 7 THEN 'checkpointing commit log pages'::text > + WHEN 8 THEN 'checkpointing commit time stamp pages'::text > + WHEN 9 THEN 'checkpointing subtransaction pages'::text > + WHEN 10 THEN 'checkpointing multixact pages'::text > + WHEN 11 THEN 'checkpointing predicate lock pages'::text > + WHEN 12 THEN 'checkpointing buffers'::text > + WHEN 13 THEN 'processing file sync requests'::text > + WHEN 14 THEN 'performing two phase checkpoint'::text > + WHEN 15 THEN 'performing post checkpoint cleanup'::text > + WHEN 16 THEN 'invalidating replication slots'::text > + WHEN 17 THEN 'recycling old WAL files'::text > + WHEN 18 THEN 'truncating subtransactions'::text > + WHEN 19 THEN 'finalizing'::text > + ELSE NULL::text > + END AS phase, > + s.param7 AS buffers_total, > + s.param8 AS buffers_processed, > + s.param9 AS buffers_written, > + s.param10 AS files_total, > + s.param11 AS files_synced > + FROM pg_stat_get_progress_info('CHECKPOINT'::text) s(pid, datid, relid, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13, param14, param15, param16, param17, param18, param19, param20); > pg_stat_progress_cluster| SELECT s.pid, > s.datid, > d.datname, This view is depressingly complicated. Added up the view definitions for the already existing pg_stat_progress* views add up to a measurable part of the size of an empty database: postgres[1160866][1]=# SELECT sum(octet_length(ev_action)), SUM(pg_column_size(ev_action)) FROM pg_rewrite WHERE ev_class::regclass::text LIKE '%progress%'; ┌───────┬───────┐ │ sum │ sum │ ├───────┼───────┤ │ 97410 │ 19786 │ └───────┴───────┘ (1 row) and this view looks to be a good bit more complicated than the existing pg_stat_progress* views. Indeed: template1[1165473][1]=# SELECT ev_class::regclass, length(ev_action), pg_column_size(ev_action) FROM pg_rewrite WHERE ev_class::regclass::text LIKE '%progress%' ORDER BY length(ev_action) DESC; ┌───────────────────────────────┬────────┬────────────────┐ │ ev_class │ length │ pg_column_size │ ├───────────────────────────────┼────────┼────────────────┤ │ pg_stat_progress_checkpoint │ 43290 │ 5409 │ │ pg_stat_progress_create_index │ 23293 │ 4177 │ │ pg_stat_progress_cluster │ 18390 │ 3704 │ │ pg_stat_progress_analyze │ 16121 │ 3339 │ │ pg_stat_progress_vacuum │ 16076 │ 3392 │ │ pg_stat_progress_copy │ 15124 │ 3080 │ │ pg_stat_progress_basebackup │ 8406 │ 2094 │ └───────────────────────────────┴────────┴────────────────┘ (7 rows) pg_rewrite without pg_stat_progress_checkpoint: 745472, with: 753664 pg_rewrite is the second biggest relation in an empty database already... template1[1164827][1]=# SELECT relname, pg_total_relation_size(oid) FROM pg_class WHERE relkind = 'r' ORDER BY 2 DESC LIMIT 5; ┌────────────────┬────────────────────────┐ │ relname │ pg_total_relation_size │ ├────────────────┼────────────────────────┤ │ pg_proc │ 1212416 │ │ pg_rewrite │ 745472 │ │ pg_attribute │ 704512 │ │ pg_description │ 630784 │ │ pg_collation │ 409600 │ └────────────────┴────────────────────────┘ (5 rows) Greetings, Andres Freund