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 1ridFS-000h8V-GV for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Mar 2024 16:39:06 +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 1ridFQ-00EGCZ-Ey for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Mar 2024 16:39:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ridFQ-00EGCR-5h for pgsql-hackers@lists.postgresql.org; Fri, 08 Mar 2024 16:39:04 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1ridFH-003VSK-UO for pgsql-hackers@lists.postgresql.org; Fri, 08 Mar 2024 16:39:02 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2d2505352e6so31116971fa.3 for ; Fri, 08 Mar 2024 08:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709915935; x=1710520735; 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=OWevZQ3XyECrE9+aOVa6VXOiUeDgkVlpwxKKYFK60Bk=; b=RjFevTUVIyiq8Rjl04Ofd/O9MOFfOvYxaJsmBGHT0zWG6IbjighRckEQo5NpXAKnRL n/N31OuVl+Fs5BBCB2+KNiLqjGbvFOmfbftZgxl2uJ2WxT6ur02CDE9m8JP5eqtx+PnV qU78A7pPO2JIh5qwb7r5IQRgOtYby+WOKfzLT8Ncji4zvIRIPSXUTtwIiUkUyMm4swV+ 1X90HcQoaGWRpuofdN5N+DhyxwEDr6q+P2IbN6jLuzjWd5pYsRoIC3doS2+tl5xMRS2P /7i8NhrnDl/v3fS/0fgcc7YTp+z5skDyLRWtz+M8YNC/OETQjfAno0MsRqypTSJgZ37A eRGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709915935; x=1710520735; 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=OWevZQ3XyECrE9+aOVa6VXOiUeDgkVlpwxKKYFK60Bk=; b=AQcj9hXLe7ME0DK801wv/NT81+zkJf0kYVItW4n6tHMcE8YkNHnUNp5fqnoGjyU+rd /c8gPWg3sY73ycw293ujWWCdKdwagcpYwg3MU4Qk7iHsz+rUAEfIA3tls7YLpo58Vo1f feUDjxgT/AVG52sEnqiX7yZS4hvVO/ybpU4/74p/BVmSyvpEGceH2b8xeUKB1Nn2URL5 aXShCFA99mEPTARGM0PdFFVe+VHvCq5cg7lvO4OHVMRFXKBUHdbNs/i6H3gEmDl4Iwf1 TeF8ZaxDFMuipStQnl1CO7+YXtn0bVX5xVQUQpVU0+ngJqyIS2Ha/q7ZwOQ5gGCqiXGB ikOA== X-Forwarded-Encrypted: i=1; AJvYcCWoIoeQ2wkpwDv/vFWrQrAjw/0wcs+mRiCMi/hOK1ryQ3MxKjlHC4UcCSLnHA1pDugdO0hWJ+knoJtopOqSQdgdC1ZZjElBQ2D0ArHxA5KZIFyF X-Gm-Message-State: AOJu0Yx9sdW9zmpyOXW4tT9SEvHIQXhHsaPvgwbetP6+SdyuiCG28Gwv cRkYjGRXX4v4pR+bfqB3ggooMPwi6rI4TLNhwNl7WkP9x3nUSB7mLN3iMpkkY9as0W6Pet+KU2j 2SEgYZIwIeesy35eGmdOoBK2m3Io= X-Google-Smtp-Source: AGHT+IGfkuBpoD8blEZn1KrZoNHhgjx7eW7xQVegX7h5Qu78vrnLPlTuJ1l7FKmDCfSt0h91eYkSoiAa7U4piENqsVw= X-Received: by 2002:a2e:9f07:0:b0:2d4:22b6:e77d with SMTP id u7-20020a2e9f07000000b002d422b6e77dmr830947ljk.3.1709915935165; Fri, 08 Mar 2024 08:38:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bharath Rupireddy Date: Fri, 8 Mar 2024 22:08:43 +0530 Message-ID: Subject: Re: Identify transactions causing highest wal generation To: Tomas Vondra Cc: Gayatri Singh , pgsql-hackers@lists.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 On Fri, Mar 8, 2024 at 9:10=E2=80=AFPM Tomas Vondra wrote: > > On 3/8/24 15:50, Gayatri Singh wrote: > > Hello Team, > > > > Can you help me with steps to identify transactions which caused wal > > generation to surge ? > > > > You should probably take a look at pg_waldump, which prints information > about WAL contents, including which XID generated each record. Right. pg_walinspect too can help get the same info for the available WAL if you are on a production database with PG15 without any access to the host instance. > I don't know what exactly is your goal, Yeah, it's good to know the use-case if possible. > but sometimes it's not entirely > direct relationship.For example, a transaction may delete a record, > which generates just a little bit of WAL. But then after a checkpoint a > VACUUM comes around, vacuums the page to reclaim the space of the entry, > and ends up writing FPI (which is much larger). You could argue this WAL > is also attributable to the original transaction, but that's not what > pg_waldump will allow you to do. FPIs in general may inflate the numbers > unpredictably, and it's not something the original transaction can > affect very much. Nice. If one knows the fact that there can be WAL generated without associated transaction (no XID), there won't be surprises when the amount of WAL generated by all transactions is compared against the total WAL on the database. Alternatively, one can get the correct amount of WAL generated including the WAL without XID before and after doing some operations as shown below: postgres=3D# SELECT pg_current_wal_lsn(); pg_current_wal_lsn -------------------- 0/52EB488 (1 row) postgres=3D# create table foo as select i from generate_series(1, 1000000) = i; SELECT 1000000 postgres=3D# update foo set i =3D i +1 where i%2 =3D 0; UPDATE 500000 postgres=3D# SELECT pg_current_wal_lsn(); pg_current_wal_lsn -------------------- 0/D2B8000 (1 row) postgres=3D# SELECT pg_wal_lsn_diff('0/D2B8000', '0/52EB488'); pg_wal_lsn_diff ----------------- 134007672 (1 row) postgres=3D# SELECT pg_size_pretty(pg_wal_lsn_diff('0/D2B8000', '0/52EB488'= )); pg_size_pretty ---------------- 128 MB (1 row) -- Bharath Rupireddy PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com