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 1uAtOP-003X1D-DO for pgsql-novice@arkaria.postgresql.org; Fri, 02 May 2025 16:37:42 +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 1uAtON-00A3Hn-EY for pgsql-novice@arkaria.postgresql.org; Fri, 02 May 2025 16:37:40 +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 1uAtON-00A3He-0n for pgsql-novice@lists.postgresql.org; Fri, 02 May 2025 16:37:40 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uAtOL-000iKT-2u for pgsql-novice@lists.postgresql.org; Fri, 02 May 2025 16:37:39 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-43cf06eabdaso17179205e9.2 for ; Fri, 02 May 2025 09:37:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1746203856; x=1746808656; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=ZCsaUzvWjcqdPfiwby/+siMUg6HFwZwMGDzRMDI+L8s=; b=ewefGfCALmy3wbiScISZ86YO/5vjSuaNTZVKuoyLRpqvYOh4bcUnMKAfZCv6JAmjpu BZ+5V+k282FLm+FFLD+ujpoVqsd5UgWfDO66j1PgHKjcAEVq9Cs+uyddI+mHso219e3M VXwyhbdhix8+5UIF/EtefB4Y8gKcnwlKDAALamSR8+X2QPDHhNGsa0ULNHE1LXE8Iok+ u6payBqI5B+bEfRtCIkjKP71UbBTDOiTScWkbDvXY2P9Wtged5r/9AUob2YZ8M98YUj6 eg/9HyDALFflnn2nAkmjEEre665skuC3OkFUWma4FJiTLCV2O+cAep7hm1Lee3Kp2RAs VDNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746203856; x=1746808656; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZCsaUzvWjcqdPfiwby/+siMUg6HFwZwMGDzRMDI+L8s=; b=T9BgyjXcwukGbOOkTKVuaBIJNkkomI+YkO7v3tL9V2qRi7tPsfZCWoVW44Ol8DdgmD ZVH7VCdle6z9bm5PDGxLI0EKQ0cRXfRBllKTzy/pAEuDFLYdPcIb6iO3+jHZP0unDkqB slRtjceJNkeBj+4hNmyoP1LQdGqAxkuIWV3vQtWBp859MdI1Cz1cJh2lGa/dvnE02qjj MMammTqbkrsP2ILyXnZcnBbBh/mwnZud9rSO+IcIlGKW8qtrkpaS5DrOnja+d6WO+zfe fPL5ks+GlURyqR+rgL94eWEpoHT0P0xw2BhnQJS5UXS/WdXdmXAx9ss0HA1Zg51opo0v 4sdw== X-Forwarded-Encrypted: i=1; AJvYcCXvcpgqul7S/qonuGI02GGUE45DRbVzeP2HRxoP57P0YsMz3xc/96ItMR5DpGZf61T8RzsilYInTtNObF0=@lists.postgresql.org X-Gm-Message-State: AOJu0YzXXp52n9r3OVDBTIu5GJTB8S3gRxWaSocYcNGGRKdsLBBCXSXp 8/eJBghuWKn9/1ow+f+7NkG2CBv6UXcHRFtOynrEzsXi5rqgIq6XOsFj+7jbcMs= X-Gm-Gg: ASbGncsQ10QBkGtawU1Sj6VRF6BHShKLx5vxUGkq4Lm2Do+ah3hv8zPO8zWUbXhA+83 Rqc1WB2xSHsO/HX6ItG0E33cjWTwvxFXjtlKw48HPj2pJPo9yKudws5BAofdiexNgb1WLIEqI/x AkW/or7boNlKA1AvjhZSPhK+aCismlNRQsyKW1LwnkfZLsIPGlVBtdzamFyeias0akjAwMrz7C5 SO9NVgtvKlrwCNpWz1HcACRafiR4upzgd/CFHdzE76/lBRV1d3gWAsWjoIc7lyuRHI+9cZxRP68 mzpAFnwbgQnls5Ea359zH0Gylcr5FzRBDIjp/rcEgwGFqZenBm3kLpmISTbbQxWayQoSzDTh X-Google-Smtp-Source: AGHT+IHglVUGbQoBsmbyCHHIZ6EE5pUcVUq0yvB1b682lq64LSchX+o7Vu8+wplI9/Sj4xhWlfXUYw== X-Received: by 2002:a5d:64c2:0:b0:3a0:8a37:fb8e with SMTP id ffacd0b85a97d-3a099addae9mr2823271f8f.27.1746203856158; Fri, 02 May 2025 09:37:36 -0700 (PDT) Received: from localhost.localdomain ([2001:871:260:68ef:ebd1:b5e2:5a9d:7c87]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a099b17074sm2584750f8f.95.2025.05.02.09.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 May 2025 09:37:35 -0700 (PDT) Message-ID: <2568733f3acd9d6f65216acb486669ebbcdf7f6b.camel@cybertec.at> Subject: Re: Vacuum Questions From: Laurenz Albe To: Leo , pgsql-novice@lists.postgresql.org Date: Fri, 02 May 2025 18:37:35 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.54.3 (3.54.3-1.fc41) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2025-05-02 at 09:50 -0400, Leo wrote: > I have been working on AWS PostgreSQL RDS for a few years, but still not = very experienced > when it comes to performance issues.=C2=A0 Plus RDS is slightly different= from the pure=C2=A0PostgreSQL. >=20 > I am trying=C2=A0to comprehend=C2=A0exactly how vacuum works. >=20 > Here is what I am trying to do. >=20 > I am purging old records from a table (500 million rows, but I am doing i= t in sets of > 50,000,000 with a smaller loop of 100,000).=C2=A0 That works just fine. >=20 > Because of the amount of data/rows deleted, I disabled=C2=A0the autovacuu= m for this table > (I want to have control over vacuum, autovacuum does not complete anyway = due to the > timeout, sizing, etc settings that I do not want to change system wide).= =C2=A0 I will put > the autovacuum back once I am done of course. >=20 > The issue is when I start vacuuming.=C2=A0 This table has 4 indexes and a= PK that I worry about. > The PK takes about 30 minutes to vacuum and two of the indexes take about= an hour each. > The problem comes in for the other 2 indexes - they take 12+ hours each t= o vacuum: >=20 > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 vacuuming "public.pc_= workflowlog" > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 launched 4 parallel v= acuum workers for index vacuuming (planned: 4) > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 scanned index "pc_wor= kflowlog_pk" to remove 50000000 row versions > DETAIL:=C2=A0 CPU: user: 191.03 s, system: 12.43 s, elapsed: 1711.22 s > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 scanned index "workfl= owlo_u_publicid_g6uqp9lkn6e8" to remove 50000000 row versions > DETAIL:=C2=A0 CPU: user: 325.75 s, system: 19.75 s, elapsed: 2674.24 s > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 scanned index "workfl= owlo_n_workflow_2tc9k2hdtry9v" to remove 50000000 row versions > DETAIL:=C2=A0 CPU: user: 312.17 s, system: 16.94 s, elapsed: 3097.88 s > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 scanned index "workfl= owlo_n_frozenseti_2kjkbjgf3c6ro" to remove 50000000 row versions > DETAIL:=C2=A0 CPU: user: 41187.70 s, system: 216.14 s, elapsed: 42749.36 = s > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 scanned index "workfl= owlo_n_userid_14kqw6qdsnndw" to remove 50000000 row versions=C2=A0 > DETAIL:=C2=A0 CPU: user: 41280.66 s, system: 216.67 s, elapsed: 42832.16 = s > psql:/home/backup/leo/fws_vacuum.sql:6: INFO:=C2=A0 "pc_workflowlog": rem= oved 50000000 row versions in 1129870 pages >=20 > I've increased=C2=A0max_parallel_maintenance_workers to 8 for the session= and it used parallel 4 > (one for each index I assume) to handle it and the two indexes were done = in ~ an hour.=C2=A0 What > I am trying to figure out is how to force the other two large indexes to = be vacuumed in > parallel - a few workers going against an index.=C2=A0 It seems it is pos= sible to do, the index > size is large enough to kick in, but I have not been able to figure it ou= t yet.=C2=A0 Most of the > parameters are at default values. >=20 > What am I missing? I didn't look at the code, but I believe that a single index won't be scann= ed by more than a single process. > I have a few other questions.=C2=A0 Does vacuum=C2=A0time depend on the n= umber of dead rows only and > the size of the table, or does the entire storage allocation (including d= ead tuples) also > affect it? I am not certain what you mean. If you set "maintenance_work_mem" high enough, VACUUM may be able to get ri= d of all dead tuples in a single pass, which is very good for performance. But that woul= d figure under "the time depends on the number of dead tuples". > Would it be more beneficial to drop the two large indexes, purge, vacuum,= and recreate the > indexes after make more sense (I know it needs to be tested)? If you delete the majority of the rows, that may be a good move. But then, maybe the best approach would be to create a new copy of the tabl= e, copy all the "surviving" rows there, create indexes on that copy, drop the original tabl= e and replace it with the copy. That would avoid bloat, which is otherwise unavoidable if you delete a big = part of the table. > Lastly, is it better to delete all the rows (500 mil) instead of doing it= in smaller > batches, and vacuum only once? That will most likely be faster, and the bloat wouldn't be any worse. Yours, Laurenz Albe