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 1mdZ41-0004fu-Sk for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Oct 2021 14:29:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdZ40-0003tB-Cn for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Oct 2021 14:29:00 +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 1mdZ3z-0003su-Vm for pgsql-hackers@lists.postgresql.org; Thu, 21 Oct 2021 14:29:00 +0000 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mdZ3w-00058A-Ez for pgsql-hackers@lists.postgresql.org; Thu, 21 Oct 2021 14:28:59 +0000 Received: by mail-il1-x134.google.com with SMTP id g8so282043ilr.7 for ; Thu, 21 Oct 2021 07:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :in-reply-to:user-agent; bh=y9y4lMe7sYlix3JTD0zR8w/LGTmI2MOSdpfa0E8Q5DQ=; b=hO5QYibl4Lt47swMdhpJYCPTi3wr5Qrc6kJjOi6KK4S+bqJED2xUXmMPadRKjNoi/h C+gkhhuIfqZa66ZRyl4b5sAlFouTxAsWug3A374DGUf92U3eJ1YDPGLd9SfVdwXVPAlB ap5EVMtCmQMWDYBb4WPQsmwjsmaPczVmiAcrYOdCi7ipezT2fSVxRNflP4Np95Iu2V+2 EkCNwWJDhOUbWqG+tH4jAe8K1qaWUM+qfnMr6jYhET4xgZtBnpYyXEgiOzRgNULEsPR/ RlTWVThiF+WpYHTypZYwljw0CYLGEYabEYKDtOa/K1qlMalWlWBmHTZIXXnMwpdZ5SNY fsLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=y9y4lMe7sYlix3JTD0zR8w/LGTmI2MOSdpfa0E8Q5DQ=; b=uZAp4MnFsHYMkd5fs4IiBWBfnfX7zqymU+VPk6nloyu9Vo3/WO7xUpDsu2c7XoZih9 2XvM5a2E6eK38KKEMYNGOCxelPyMdYFglkyVmL2YUP0l3kB2xS/11Qzzt7V3W2RGxbCz ej5/3C0Utuh9y6iqdPNb9aP1Hy07KsB7zqS7yJ8F9dAYo4jnX9RsaGmh6J7W6GayTDcm tNZhmai+tlFKB6uV3smgsGpbadVl6yjcW6CwXV3vz9YzHUZ/0Cvgi/6gAbu64P/X0k+h mTxoZ/8pIbXvwIB7ZTN0jROSSQaPXsSpbjo8uLHQ4Ic74va0akTySMctjrahgFc/cfQO Whag== X-Gm-Message-State: AOAM53364HXupedJ3FyMqXCEscpaFEAZdlvZsJmfB/ayFdniFR6RagXf kOVBEAIvYRvbTL1bkYgWh8EVNliLSQ8b4Q== X-Google-Smtp-Source: ABdhPJzYFWzwp0fJ6PAu37LaUTW1G93M5P/Bfs2dquPyZd7eIjNCnvwmKh2Vk7GD54b2eR3/NGIYfQ== X-Received: by 2002:a05:6e02:1b01:: with SMTP id i1mr3904443ilv.157.1634826534124; Thu, 21 Oct 2021 07:28:54 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id v63sm2647816ioe.17.2021.10.21.07.28.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 07:28:53 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id E4A6C800ACE; Thu, 21 Oct 2021 09:28:52 -0500 (CDT) Date: Thu, 21 Oct 2021 09:28:52 -0500 From: Justin Pryzby To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Assorted improvements in pg_dump Message-ID: <20211021142852.GD741@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1462940.1634496313@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Oct 20, 2021 at 05:14:45PM -0400, Tom Lane wrote: > Lastly, patch 0003 addresses the concern I raised at [3] that it's > unsafe to call pg_get_partkeydef() and pg_get_expr(relpartbound) > in getTables(). Looking closer I realized that we can't cast > pg_class.reloftype to regtype at that point either, since regtypeout > is going to notice if the type has been concurrently dropped. > > In [3] I'd imagined that we could just delay those calls to a second > query in getTables(), but that doesn't work at all: if we apply > these functions to every row of pg_class, we still risk failure > against any relation that we didn't lock. So there seems little > alternative but to push these functions out to secondary queries > executed later. > > Arguably, 0003 is a bug fix that we should consider back-patching. > However, I've not heard field reports of the problems it fixes, > so maybe there's no need to bother. > [3] https://www.postgresql.org/message-id/1462940.1634496313%40sss.pgh.pa.us FYI, I see this issue happen in production environment. Grepping logfiles on ~40 servers, I see it happened at least 3 times since October 1. Our backup script is probably particularly sensitive to this: it separately dumps each "old" partition once and for all. We're more likely to hit this since pg_dump is called in a loop. I never reported it, since I think it's a documented issue, and it's no great problem, so long as it runs the next day. But it'd be a pain to find that the backup was incomplete when we needed it. Also, I use the backups to migrate to new servers, and it would be a pain to start the job at a calculated time expecting it to finish at the beginning of a coordinated maintenance window, but then discover that it had failed and needs to be rerun with fingers crossed. On Sun, Oct 17, 2021 at 02:45:13PM -0400, Tom Lane wrote: > While poking at pg_dump for some work I'll show later, I grew quite > unhappy with the extent to which people have ignored this advice > given near the head of getTables(): > > * Note: in this phase we should collect only a minimal amount of > * information about each table, basically just enough to decide if it is > * interesting. We must fetch all tables in this phase because otherwise > * we cannot correctly identify inherited columns, owned sequences, etc. > > Far from collecting "a minimal amount of information", we have > repeatedly stuffed extra joins and expensive sub-selects into this > query. That's fairly inefficient if we aren't interested in dumping > every table, but it's much worse than that: we are collecting all this > info *before we have lock* on the tables. That means we are at > serious risk of data skew in any place where we consult server-side > functions, eg pg_get_partkeydef(). For example: > > regression=# create table foo(f1 int) partition by range(f1); > CREATE TABLE > regression=# begin; drop table foo; > BEGIN > DROP TABLE > > Now start a pg_dump in another shell session, wait a second or two, > and > > regression=*# commit; > COMMIT > > and the pg_dump blows up: > > $ pg_dump -s regression > pg_dump: error: query failed: ERROR: could not open relation with OID 37796 ...