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 1mJB01-0004Bx-Qi for pgsql-general@arkaria.postgresql.org; Thu, 26 Aug 2021 08:44:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mJB00-0001Vx-Q0 for pgsql-general@arkaria.postgresql.org; Thu, 26 Aug 2021 08:44:36 +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 1mJB00-0001Vp-Fi for pgsql-general@lists.postgresql.org; Thu, 26 Aug 2021 08:44:36 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJAzx-0007dB-DO for pgsql-general@lists.postgresql.org; Thu, 26 Aug 2021 08:44:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=Content-Type:MIME-Version:Reply-To:Message-ID:Subject:To: Sender:From:Date:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=C+WQicdiu4HuLXNfXDIuW0TTnHO2UL730lIVRrx46a0=; b=H6utU62WA0mGFg2xGh0KR08MLj PhCPDha5DlMXBm26l8f0vUGQUuM2B/iZP4Sk7LGOHOmfV2XD7EaOG0cs2vK1eyxj/pxDWrsxNL3hi J2Njkajc02p570U8tTb/qh5kBnPvYnc0SsqGVYm15D4VbDs5jlNb33Q0jtd0JMaDyIig=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mJAzu-0008DW-RA for pgsql-general@lists.postgresql.org; Thu, 26 Aug 2021 10:44:30 +0200 Date: Thu, 26 Aug 2021 10:44:30 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: pgsql-general Subject: Can we get rid of repeated queries from pg_dump? Message-ID: <20210826084430.GA26282@depesz.com> Reply-To: depesz@depesz.com MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I have following case: local pg_dump (v15) connecting to remote PostgreSQL (v12). I'm trying to get just schema (pg_dump -s). It's taking very long, which is kinda OK given that there is long distance and latency, but I got curious and checked queries that the pg_dump was running (select * from pg_stat_activity where application_name = 'pg_dump'). And I noticed that many of these queries repeat many times. The ones that I noticed were: SELECT pg_catalog.format_type('2281'::pg_catalog.oid, NULL) around the time that SELECT proretset, prosrc, probin, provolatile, proisstrict, prosecdef, lanname, proconfig, procost, prorows, pg_catalog.pg_get_function_arguments(p.oid) AS funcargs, pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs, pg_catalog.pg_get_function_result(p.oid) AS funcresult, proleakproof, array_to_string(protrftypes, ' ') AS protrftypes, proparallel, prokind, prosupport, NULL AS prosqlbody FROM pg_catalog.pg_proc p, pg_catalog.pg_language l WHERE p.oid = '60188'::pg_catalog.oid AND l.oid = p.prolang was called too. It seems that for every function, pg_dump is getting it's data, and then runs format_type on each parameter/output type? I'm mostly guessing here, as I didn't read the code. Wouldn't it be possible to get all type formats at once, and cache them in pg_dump? Or at the very least reuse already received information? Unfortunately it seems I can't run pg_dump closer to the db server, and the latency of queries is killing me. It's been 15 minutes, and pg_dump (called: pg_dump -v -s -f schema.dump, with env variables configuring db connection) hasn't written even single byte to schema.dump) depesz