Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ihQWi-0004Wp-MR for pgsql-performance@arkaria.postgresql.org; Wed, 18 Dec 2019 04:01:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ihQWe-0006tg-RO for pgsql-performance@arkaria.postgresql.org; Wed, 18 Dec 2019 04:01:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ihQWe-0006tS-CC for pgsql-performance@lists.postgresql.org; Wed, 18 Dec 2019 04:01:28 +0000 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ihQWb-00017u-2S for pgsql-performance@lists.postgresql.org; Wed, 18 Dec 2019 04:01:27 +0000 Received: by mail-yb1-xb41.google.com with SMTP id k17so263515ybp.1 for ; Tue, 17 Dec 2019 20:01:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=bReYv6vFhAOk7sS2dP8Y9aLkO1EVwbAEeckLG018/ow=; b=Unwr4qAvE3iBombfx0zDhqX1VYerPoHlICeJ46E1Y9/4Ped0MyuU7PLiWX9UXpFxYi JxjAsHudbOCw82vpjTEjnBIQ15XLCoYWJ8OTCOHQH3AnTticTfXJfXVPgScB3ftLvnx/ OQ5XvHJ+Bc6dUK1tfJAKj2aOh+hcxUQJDiGuIB9k6NtYFtZqsR8NpqtyMN+aHccNkoRm E1wQo7u098RCwGNYCesZpQHzeTPjRk523vsliWW5xHkdQrEipoBr1Q2wgYivf6hn8T00 NjHlZiVL9wACzGx58CE5p4Qj3ozJIkZ5liyv4WBHxyo8KKMekeDl4GF/rN4auDKX0DhN 3H7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=bReYv6vFhAOk7sS2dP8Y9aLkO1EVwbAEeckLG018/ow=; b=n8ZPcBek9y4hwV5CxIfPt+PnH/blDl41b/vVTYleFEHWmpNLX80JxD0YkX3CpTJPWS 2Lc9ebZnNeOIagKGyLwkNe09ppNKPDCGaEfQz94vKMn2jjQqUG4AgfhAOkEy1NPm4KJZ LWn82CW3gHf6PAU6/QpGKgOK47iCB2rSwY1uP90pdgkNOnfNmVP4xAn8Zv00/dx3ei/6 3QIIfCdiDzeokb2HnoCe3cwfuysw4pApr/zaxZt1mm7VPr3fyzzSkawvDxGuwc6HVTWY try69W7likqdLUFx00FnQRUAH0Hfnc9KvrUIB0TyzI7eJwMJVh06pYqmPOE5EJouughE kp5w== X-Gm-Message-State: APjAAAW9NyU8CCWzZB3ZjN7q3UCss9VoURVsWRl5YLe40KqawBhfDSBI IUNFYwqP93f7ZtEPqFNwLBoAGUaiU8M= X-Google-Smtp-Source: APXvYqyZveZ8sZc0hhhx4cFffPuFxRqwDHz7rsZlBl/XO9RKl149qiCfiQd9+QuiUp9gcYJGNfvp+Q== X-Received: by 2002:a25:c186:: with SMTP id r128mr259956ybf.319.1576641682932; Tue, 17 Dec 2019 20:01:22 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id m7sm460096ywh.24.2019.12.17.20.01.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Dec 2019 20:01:22 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id F1BEB800A79; Tue, 17 Dec 2019 22:01:19 -0600 (CST) Date: Tue, 17 Dec 2019 22:01:19 -0600 From: Justin Pryzby To: Piotr =?utf-8?Q?W=C5=82odarczyk?= Cc: pgsql-performance@lists.postgresql.org Subject: Re: shared memory size during upgrade pgsql with partitions (max_locks_per_transaction) Message-ID: <20191218040119.GE2082@telsasoft.com> References: <86a9cb749c7749c2aeca5e1ebb212598@EX13MBX02.gb.ad.corp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <86a9cb749c7749c2aeca5e1ebb212598@EX13MBX02.gb.ad.corp> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Dec 17, 2019 at 08:03:41PM +0000, Piotr Włodarczyk wrote: > Currently we're working on PSQL 11.5 and we're trying upgrade to 12.1. > > During that we have a problem: > > command: "/usr/pgsql-12/bin/pg_dump" --host /cluster/postgresql --port 50432 > --username postgres --schema-only --quote-all-identifiers --binary-upgrade > --format=custom --file="pg_upgrade_dump_281535902.custom" 'dbname=sprint' > >> "pg_upgrade_dump_281535902.log" 2>&1 > pg_dump: error: query failed: ERROR: out of shared memory > HINT: You might need to increase max_locks_per_transaction. > pg_dump: error: query was: LOCK TABLE > "some_schemaa"."table_part_80000000_2018q3" IN ACCESS SHARE MODE > > On current instance we have about one thousand of partitions, partitioned in > two levels: first by id_product, and second level by quarter of the year, as > you can see on above log. > > How have we to calculate shared memory, and (eventually > max_locks_per_transaction) to be fit to the limits during upgrade? Great question. Clearly, if you can run that (or similar) pg_dump command, then you can pg_upgrade. I think you could also do pg_upgrade --check, The query looks like FROM pg_class c... WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c', '%c') " ..and then does: if (tblinfo[i].dobj.dump && (tblinfo[i].relkind == RELKIND_RELATION || tblinfo->relkind == RELKIND_PARTITIONED_TABLE) && (tblinfo[i].dobj.dump & DUMP_COMPONENTS_REQUIRING_LOCK)) { resetPQExpBuffer(query); appendPQExpBuffer(query, "LOCK TABLE %s IN ACCESS SHARE MODE", fmtQualifiedDumpable(&tblinfo[i])); ExecuteSqlStatement(fout, query->data); } ..then filters by -N/-n/-t/-T (which doesn't apply to pg_upgrade): selectDumpableTable(&tblinfo[i], fout); So it looks like COUNT(1) FROM pg_class WHERE relkind IN ('r','p') should do it. But actually, during pg_upgrade, since nothing else is running, you actually have max_connections*max_locks_per_transaction total locks. Said differently, I think you could set max_locks_per_transaction to: SELECT (SELECT COUNT(1) FROM pg_class WHERE relkind IN ('r','p'))/current_setting('max_connections')::int; ..probably with a fudge factor of +10 for any system process (and due to integer truncation). Someone might say that pg_upgrade or pg_dump could check for that specifically.. Justin