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 1jZKL1-0001SD-M0 for pgsql-general@arkaria.postgresql.org; Thu, 14 May 2020 20:20:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZKL0-0006xl-Hj for pgsql-general@arkaria.postgresql.org; Thu, 14 May 2020 20:20:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZIaY-0004CM-Fh for pgsql-general@lists.postgresql.org; Thu, 14 May 2020 18:28:10 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jZIaR-0002ws-Fx for pgsql-general@postgresql.org; Thu, 14 May 2020 18:28:09 +0000 Received: by mail-pl1-x643.google.com with SMTP id f15so1507707plr.3 for ; Thu, 14 May 2020 11:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=gqtEu67E7Nif0Ozvt/4zUbpM1BrD4AF9Lky0e51plek=; b=beL/6udx5aS4YLxq1VfRUZOsJ35oYCypv3g7Bx4Gbn4/1FYwlBavmXWABB5063ekO1 Q4OhsUGL99RPwHtlowUnxnrw95FswxgRzwEn1bQ6FxmF9UL0nVPDBP0UCf1lBnQ4lwOj yYCTix0MPU11PvQz/cL/itYVG59lhcPA7ULBFl5wpZ/jRADOm30WewOuZlk5lIgW1bil dVmNFYPlw8yBhoiY6eOnXMBKi5SXyYRSUbkj3Bm8TLUX330NrLCYGWbNuskbau9WGKa0 H9eIdPdgBFUFaJSmnxKJAQOIwmF9KDDPfk2XmMxZF60Yyo6F/DBk9lYXiB2fuuSbJrph WRfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=gqtEu67E7Nif0Ozvt/4zUbpM1BrD4AF9Lky0e51plek=; b=FbaOmBDet3piRGbFZfXkCa6mLRPt/SYkY1VkSGL/0ryXsZKn+2qvEntH91HFPofw9B ZsCBLN0xojETP715TiM5Mr026b+HkP4dZLTAmGgjXiE0vHHwPBYD9BpdQY1GDe5wYuKc TkGwMh7Km7f4YCS22jKgIhELfSdRZVTACSE70HTYWFxR+bK5n8MYwXmBcm3zgDcHSaT8 Bo+m9VXrT4y9pPBGYP3J+4CApfeOEl8FqmHRBu1XdmZo21YRPA7+myd4sDxLYitBGgnD tEEw7xpUN/IxamDihi4zKhhH+8YlkYJJdArgRSdIIqN7PV5qtI1eKd788CKfxqsRU68I eivA== X-Gm-Message-State: AGi0PuaWniYMU+dcq49K1rg4dhJkIzkATytNKzWYHSBgdCtjre1KUGI/ zhA5EW3BtsAOnFrQgMo0esE= X-Google-Smtp-Source: APiQypL+5bqkQdJSalKxIiXcD5nLQAbN4KWjihlx0fiM6i6+hAJ8HZAFay+2VT8DkDLSJxMfWXLLBA== X-Received: by 2002:a17:90b:3018:: with SMTP id hg24mr41067403pjb.130.1589480881691; Thu, 14 May 2020 11:28:01 -0700 (PDT) Received: from ?IPv6:2601:646:c203:d270:9165:eba5:f30d:5b8a? ([2601:646:c203:d270:9165:eba5:f30d:5b8a]) by smtp.gmail.com with ESMTPSA id k2sm2930175pfd.108.2020.05.14.11.28.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 May 2020 11:28:01 -0700 (PDT) From: Eduard Rozenberg Message-Id: <3E4B3E2A-CBBE-472A-8FDE-C1A9538F2DF0@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_7B74784B-97F6-4EE1-9787-A6BA958DC666" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.14\)) Subject: Re: vacuumdb --jobs deadlock: how to avoid pg_catalog ? Date: Thu, 14 May 2020 11:27:58 -0700 In-Reply-To: Cc: pgsql-general@postgresql.org To: Adrian Klaver References: <4C3B3D43-F3BE-4BE7-A812-E3FB4E43236A@gmail.com> X-Mailer: Apple Mail (2.3445.104.14) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_7B74784B-97F6-4EE1-9787-A6BA958DC666 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 @Adrian thanks. I did a test vacuum full the "normal" non-parallel way (VACUUM FULL sql) = previously on a test db copy and saw the DB size (postgres 9.6) shrink = from 6.8 TB to 4.4 TB of actual, real disk space usage ($ df -d 1). I don't know the reason so much space was "locked up" (other than there = is a lot of data "churn" from daily updates). But I definitely do need = to do the vac full on the production db to get down to the smaller size = - cannot afford the 2.4 TB of "wasted" space on an ongoing basis. Based on your email it sounds like the vacuuming of those pg_catalog.* = tables is done regardless, as a normal part of doing vac full on my own = database. Unfortunately I still don't see an ideal way to run vacuum full in = parallel via vacuumdb without running into the expected and documented = deadlock. Only method I'm aware of is to list each table individually = with "-t table1 -t table2..." to "vacuum db --jobs" which is not = pleasant and not exceedingly beautiful. Thanks. > On May 14, 2020, at 10:35, Adrian Klaver = wrote: >=20 > On 5/14/20 8:35 AM, Eduard Rozenberg wrote: >> Hello there, >> I'm a long-time postgres user but vacuumdb newbie :). >> Using vacuumdb (v12.2) with '---jobs' to vacuum a v9.6 database on = localhost with parallel processes: >> $ time vacuumdb --full --echo -U postgres --jobs=3D8 -d = mydatabase_test -p 5434 --password >> As shown below I ran into the (100%?) predictable/expected deadlock = with sys catalog tables documented in the vacuumdb doc page = (https://www.postgresql.org/docs/12/app-vacuumdb.html). >> Question: I specified "-d mydatabase_test" - why is it also doing a = full vac on the system catalog (postgres db) which is practically = guaranteed=20 >=20 > The postgres database and the system catalogs are two separate things. >=20 >> to cause a deadlock? I don't need or want it to do a full vac on the = postgres db as I can do that myself later if I need to, and it takes no = time compared to full vac of my own 7 TB database that I am "extremely = eager" to parallelize. >=20 > See: >=20 > https://www.postgresql.org/docs/12/sql-vacuum.html = >=20 > "FULL >=20 > Selects =E2=80=9Cfull=E2=80=9D vacuum, which can reclaim more = space, but takes much longer and exclusively locks the table. This = method also requires extra disk space, since it writes a new copy of the = table and doesn't release the old copy until the operation is complete. = Usually this should only be used when a significant amount of space = needs to be reclaimed from within the table. > " >=20 > Pretty sure all that rewriting of tables bloats the system catalogs = and so they get a VACUUM FULL. >=20 >=20 > The question here is why is it necessary to do a VACUUM FULL in the = first place? >=20 >> Is my only option list all schemas.tables and feed to vacuumdb as "-t = schema1.table1 -t schema1.table2 ........" ? That's manageable but = unfortunate as it creates more work (having to list all tables) and adds = additional work for automation scripts as well. >> I've tried searching forums/goog for past issues related to this. I = did find an old discussion about possible enhancements to "vacuumdb = --jobs" to help the user avoid these predictable deadlocks, where the = conclusion was to let the user figure out a way to deal with it such as = via "-t table -t table -t table .......". >> Maybe "--jobs" should only apply to the user's own databases, and = when vacuumdb is working on system catalog tables it should apply a = strictly serial/sequential approach to handle those tables? >> Thanks! >> ------------------------------------------ >> output from vacuumdb's --echo >> ------------------------------------------ >> ... >> VACUUM (FULL) mycompanytesting.sometable1; >> VACUUM (FULL) index.mydatabasestd_missing; >> VACUUM (FULL) mycompanytesting.sometable2; >> VACUUM (FULL) mycompanytesting.sometable3; >> VACUUM (FULL) pg_catalog.pg_attribute; >> VACUUM (FULL) mycompanydata.sometable4; >> VACUUM (FULL) pg_catalog.pg_statistic; >> VACUUM (FULL) mycompanytesting.sometable5; >> VACUUM (FULL) pg_catalog.pg_proc; >> VACUUM (FULL) pg_catalog.pg_depend; >> VACUUM (FULL) pg_catalog.pg_class; >> VACUUM (FULL) pg_catalog.pg_type; >> vacuumdb: error: vacuuming of database "mydatabase_test" failed: = ERROR: deadlock detected >> DETAIL: Process 28183 waits for AccessShareLock on relation 1259 of = database 35239378; blocked by process 28182. >> Process 28182 waits for AccessShareLock on relation 1247 of database = 35239378; blocked by process 28183. >> HINT: See server log for query details. >> ------------------------------ >> /var/log/postgresql-9.6 >> ------------------------------ >> ... >> LOG: received SIGHUP, reloading configuration files >> ERROR: canceling autovacuum task >> CONTEXT: automatic vacuum of table = "mydatabase_test.someschema.sometable" >> ERROR: canceling autovacuum task >> CONTEXT: automatic vacuum of table = "mydatabase_test.someschema.sometable" >> ERROR: canceling autovacuum task >> CONTEXT: automatic vacuum of table = "mydatabase_test.pg_toast.pg_toast_35240266" >> LOG: could not receive data from client: Connection timed out >> LOG: received SIGHUP, reloading configuration files >> LOG: received SIGHUP, reloading configuration files >> ERROR: canceling autovacuum task >> CONTEXT: automatic vacuum of table = "mydatabase_test.someschema.sometable" >> LOG: received SIGHUP, reloading configuration files >> LOG: received SIGHUP, reloading configuration files >> ERROR: canceling autovacuum task >> CONTEXT: automatic vacuum of table = "mydatabase_test.pg_toast.pg_toast_35240330" >> ERROR: canceling autovacuum task >> CONTEXT: automatic vacuum of table = "mydatabase_test.someschema.sometable" >> ERROR: deadlock detected >> DETAIL: Process 28183 waits for AccessShareLock on relation 1259 of = database 35239378; blocked by process 28182. >> Process 28182 waits for AccessShareLock on relation 1247 of database = 35239378; blocked by process 28183. >> Process 28183: VACUUM (FULL) pg_catalog.pg_type; >> Process 28182: VACUUM (FULL) pg_catalog.pg_class; >> HINT: See server log for query details. >> STATEMENT: VACUUM (FULL) pg_catalog.pg_type; >> ERROR: canceling statement due to user request >> STATEMENT: VACUUM (FULL) pg_catalog.pg_class; >> ERROR: canceling statement due to user request >> STATEMENT: VACUUM (FULL) pg_catalog.pg_depend; >> ERROR: canceling statement due to user request >> STATEMENT: VACUUM (FULL) someschema.sometable >> LOG: could not send data to client: Broken pipe >> FATAL: connection to client lost >> LOG: could not send data to client: Broken pipe >> FATAL: connection to client lost >> ERROR: canceling statement due to user request >> STATEMENT: VACUUM (FULL) mycompanydata.wildcard_replacement_bkp; >> LOG: could not send data to client: Broken pipe >> STATEMENT: VACUUM (FULL) mycompanydata.wildcard_replacement_bkp; >> FATAL: connection to client lost >> ERROR: canceling statement due to user request >> STATEMENT: VACUUM (FULL) pg_catalog.pg_proc; >> LOG: could not send data to client: Broken pipe >> STATEMENT: VACUUM (FULL) pg_catalog.pg_proc; >> FATAL: connection to client lost >> ERROR: canceling statement due to user request >> STATEMENT: VACUUM (FULL) mycompanydata.cpc_tag_score2; >> LOG: could not send data to client: Broken pipe >> STATEMENT: VACUUM (FULL) mycompanydata.cpc_tag_score2; >> LOG: could not send data to client: Broken pipe >> FATAL: connection to client lost >> FATAL: connection to client lost >> LOG: received SIGHUP, reloading configuration files >> LOG: received SIGHUP, reloading configuration files >=20 >=20 > --=20 > Adrian Klaver > adrian.klaver@aklaver.com --Apple-Mail=_7B74784B-97F6-4EE1-9787-A6BA958DC666 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 @Adrian thanks.

I did a test vacuum full the "normal" non-parallel way = (VACUUM FULL sql) previously on a test db copy and saw the DB size = (postgres 9.6) shrink from 6.8 TB to 4.4 TB of actual, real disk space = usage ($ df -d 1).

I don't know the reason so much space was "locked up" (other = than there is a lot of data "churn" from daily updates). But I = definitely do need to do the vac full on the production db to get down = to the smaller size - cannot afford the 2.4 TB of "wasted" space on an = ongoing basis.

Based on your email it sounds like the vacuuming of those = pg_catalog.* tables is done regardless, as a normal part of doing vac = full on my own database.

Unfortunately I still don't see an ideal way to run vacuum = full in parallel via vacuumdb without running into the expected and = documented deadlock. Only method I'm aware of is to list each table = individually with "-t table1 -t table2..." to "vacuum db --jobs" which = is not pleasant and not exceedingly beautiful.

Thanks.

On May 14, 2020, at 10:35, = Adrian Klaver <adrian.klaver@aklaver.com> wrote:

On 5/14/20 8:35 AM, Eduard = Rozenberg wrote:
Hello there,
I'm a = long-time postgres user but vacuumdb newbie :).
Using = vacuumdb (v12.2) with '---jobs' to vacuum a v9.6 database on localhost = with parallel processes:
$ time vacuumdb --full --echo -U = postgres --jobs=3D8 -d mydatabase_test -p 5434 --password
As= shown below I ran into the (100%?) predictable/expected deadlock with = sys catalog tables documented in the vacuumdb doc page (https://www.postgresql.org/docs/12/app-vacuumdb.html).
Question: I specified "-d mydatabase_test" - why is it also = doing a full vac on the system catalog (postgres db) which is = practically guaranteed 

The postgres database and the system catalogs are two = separate things.

to cause a deadlock? I don't need or = want it to do a full vac on the postgres db as I can do that myself = later if I need to, and it takes no time compared to full vac of my own = 7 TB database that I am "extremely eager" to parallelize.

See:

https://www.postgresql.org/docs/12/sql-vacuum.html

"FULL

   Selects = =E2=80=9Cfull=E2=80=9D vacuum, which can reclaim more space, but takes = much longer and exclusively locks the table. This method also requires = extra disk space, since it writes a new copy of the table and doesn't = release the old copy until the operation is complete. Usually this = should only be used when a significant amount of space needs to be = reclaimed from within the table.
"

Pretty sure = all that rewriting of tables bloats the system catalogs and so they get = a VACUUM FULL.


The question here is why is it necessary to do a VACUUM FULL = in the first place?

Is my only option list all = schemas.tables and feed to vacuumdb as "-t schema1.table1 -t = schema1.table2 ........" ? That's manageable but unfortunate as it = creates more work (having to list all tables) and adds additional work = for automation scripts as well.
I've tried searching = forums/goog for past issues related to this. I did find an old = discussion about possible enhancements to "vacuumdb --jobs" to help the = user avoid these predictable deadlocks, where the conclusion was to let = the user figure out a way to deal with it such as via "-t table -t table = -t table .......".
Maybe "--jobs" should only apply to the = user's own databases, and when vacuumdb is working on system catalog = tables it should apply a strictly serial/sequential approach to handle = those tables?
Thanks!
------------------------------------------
output= from vacuumdb's --echo
------------------------------------------
...VACUUM (FULL) mycompanytesting.sometable1;
VACUUM (FULL) index.mydatabasestd_missing;
VACUUM= (FULL) mycompanytesting.sometable2;
VACUUM (FULL) = mycompanytesting.sometable3;
VACUUM (FULL) = pg_catalog.pg_attribute;
VACUUM (FULL) = mycompanydata.sometable4;
VACUUM (FULL) = pg_catalog.pg_statistic;
VACUUM (FULL) = mycompanytesting.sometable5;
VACUUM (FULL) = pg_catalog.pg_proc;
VACUUM (FULL) pg_catalog.pg_depend;
VACUUM (FULL) pg_catalog.pg_class;
VACUUM = (FULL) pg_catalog.pg_type;
vacuumdb: error: vacuuming of = database "mydatabase_test" failed: ERROR:   deadlock = detected
DETAIL:  Process 28183 waits for = AccessShareLock on relation 1259 of database 35239378; blocked by = process 28182.
Process 28182 waits for AccessShareLock on = relation 1247 of database 35239378; blocked by process 28183.
HINT:  See server log for query details.
------------------------------
/var/log/postgresql-9.6
------------------------------
...
LOG:  received SIGHUP, reloading configuration files
ERROR:  canceling autovacuum task
CONTEXT: =  automatic vacuum of table = "mydatabase_test.someschema.sometable"
ERROR: =  canceling autovacuum task
CONTEXT:  automatic = vacuum of table "mydatabase_test.someschema.sometable"
ERROR:  canceling autovacuum task
CONTEXT: =  automatic vacuum of table = "mydatabase_test.pg_toast.pg_toast_35240266"
LOG: =  could not receive data from client: Connection timed out
LOG:  received SIGHUP, reloading configuration files
LOG:  received SIGHUP, reloading configuration files
ERROR:  canceling autovacuum task
CONTEXT: =  automatic vacuum of table = "mydatabase_test.someschema.sometable"
LOG:  received = SIGHUP, reloading configuration files
LOG:  received = SIGHUP, reloading configuration files
ERROR: =  canceling autovacuum task
CONTEXT:  automatic = vacuum of table "mydatabase_test.pg_toast.pg_toast_35240330"
ERROR:  canceling autovacuum task
CONTEXT: =  automatic vacuum of table = "mydatabase_test.someschema.sometable"
ERROR: =  deadlock detected
DETAIL:  Process 28183 waits = for AccessShareLock on relation 1259 of database 35239378; blocked by = process 28182.
Process 28182 waits for AccessShareLock on = relation 1247 of database 35239378; blocked by process 28183.
Process 28183: VACUUM (FULL) pg_catalog.pg_type;
Process 28182: VACUUM (FULL) pg_catalog.pg_class;
HINT:  See server log for query details.
STATEMENT:  VACUUM (FULL) pg_catalog.pg_type;
ERROR:  canceling statement due to user request
STATEMENT:  VACUUM (FULL) pg_catalog.pg_class;
ERROR:  canceling statement due to user request
STATEMENT:  VACUUM (FULL) pg_catalog.pg_depend;
ERROR:  canceling statement due to user request
STATEMENT:  VACUUM (FULL) someschema.sometable
LOG:  could not send data to client: Broken pipe
FATAL:  connection to client lost
LOG: =  could not send data to client: Broken pipe
FATAL: =  connection to client lost
ERROR:  canceling = statement due to user request
STATEMENT:  VACUUM = (FULL) mycompanydata.wildcard_replacement_bkp;
LOG: =  could not send data to client: Broken pipe
STATEMENT: =  VACUUM (FULL) mycompanydata.wildcard_replacement_bkp;
FATAL:  connection to client lost
ERROR: =  canceling statement due to user request
STATEMENT: =  VACUUM (FULL) pg_catalog.pg_proc;
LOG:  could = not send data to client: Broken pipe
STATEMENT: =  VACUUM (FULL) pg_catalog.pg_proc;
FATAL: =  connection to client lost
ERROR:  canceling = statement due to user request
STATEMENT:  VACUUM = (FULL) mycompanydata.cpc_tag_score2;
LOG:  could not = send data to client: Broken pipe
STATEMENT:  VACUUM = (FULL) mycompanydata.cpc_tag_score2;
LOG:  could not = send data to client: Broken pipe
FATAL:  connection = to client lost
FATAL:  connection to client lost
LOG:  received SIGHUP, reloading configuration files
LOG:  received SIGHUP, reloading configuration files


-- Adrian Klaver
adrian.klaver@aklaver.com

= --Apple-Mail=_7B74784B-97F6-4EE1-9787-A6BA958DC666--