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 1rUUry-00BHIr-IQ for pgsql-general@arkaria.postgresql.org; Mon, 29 Jan 2024 16:52:27 +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 1rUUrw-00FatY-Aw for pgsql-general@arkaria.postgresql.org; Mon, 29 Jan 2024 16:52:24 +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 1rUUru-00FatQ-JY for pgsql-general@lists.postgresql.org; Mon, 29 Jan 2024 16:52:24 +0000 Received: from fhigh2-smtp.messagingengine.com ([103.168.172.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rUUrr-003zzs-8V for pgsql-general@lists.postgresql.org; Mon, 29 Jan 2024 16:52:21 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BA4A411400A6; Mon, 29 Jan 2024 11:52:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 29 Jan 2024 11:52:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1706547137; x=1706633537; bh=3kQi2I8O/3Z39mqNjtiWV1Ovsyd7PI7zCZgbocEG+C8=; b= ebqiaX+xhTnr2twtNM3vdaQNLITHG5vZBK2Bllik4O2NdTyt18GYfsq8D+6gR7hw EmXqpU9c+dBH3erJI2uelDfZ8JF7Mi2bUpW2OpdU20+xkOWEyr8EicHbWMe8Ef2s Lr/pf/LPlmy2/lmlyAfV+q2iB6VUTVqpFiMGFHfxBfMykFys0Saw7x86Xc/RQHfa +qyUWbA9fXNV3CysIl6IbnXOyT20OnBosV3S6Nu24DfYRNW6G3MQ2w9MxXGlv0lY JRu17TbJBdTIhKFPn5rXLeRpf3W35zxgJcqOVeJeNfdbZr+9gO0AVykgyFJDQxqs L8i35HVbNEPVTN7NUcRGOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1706547137; x= 1706633537; bh=3kQi2I8O/3Z39mqNjtiWV1Ovsyd7PI7zCZgbocEG+C8=; b=N /N4VDW6vITKX1kh1tZF+JKr64d6sdoSu7ROsYe8b75WMHmnZw29t5ulE2VksO5wB THRV4BFLX2nROVPbP7nhO4kEUdyndrPfhStU69PbBO//KQCD8bwrcTQEH6fuGrJN Fo2EekkHtu0WlLh70soHA8QdGXA0q2nI6ttM3sfaQJ3HropPiKqyweMGeMpKBsIR drvYV+n3fI1OCyw9qFkMtH6jm+Q+EhGnsTH2vVS3YnYy+InIDtXVegsiCdjmFO62 xzaXPLQjlfKP9SdeZqUd4O71a7Jy3OFqYymRP8fwdBECPx+iPxMV0Rm7iWmYmyxx BfrXuMyCTk7OhyH05e7SQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtgedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtke ertddtvdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepffelgeeife fgveduhedthfekuedtffejveegffegjeevtdehgfduieetfeehjeehnecuvehluhhsthgv rhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvh gvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 29 Jan 2024 11:52:17 -0500 (EST) Message-ID: Date: Mon, 29 Jan 2024 08:52:16 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Scriptable way to validate a pg_dump restore ? To: Laura Smith , postgre References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/29/24 00:12, Laura Smith wrote: > Hi > > Let's say I've got a scenario where I'm doing a pg_dump replication rather than online streaming, e.g. due to air-gap or whatever. > > Is there a scriptable way to validate the restore ?  e.g. using doing something clever with ctid or something to ensure both the schema and all its rows were restored to the same point at which the dump was taken ? Assuming you are using pg_restore on a non-plain text dump file then from pg_restore.c: * pg_restore.c * pg_restore is an utility extracting postgres database definitions * from a backup archive created by pg_dump using the archiver * interface. * * pg_restore will read the backup archive and * dump out a script that reproduces * the schema of the database in terms of * user-defined types * user-defined functions * tables * indexes * aggregates * operators * ACL - grant/revoke * * the output script is SQL that is understood by PostgreSQL * * Basic process in a restore operation is: * * Open the Archive and read the TOC. * Set flags in TOC entries, and *maybe* reorder them. * Generate script to stdout * Exit Then: pg_restore -l -f to get the TOC mentioned above. Walk through that to verify schema is the same in the restored database. This will not tell you whether all the data was transferred. You will either have to trust from pg_dump.c: * pg_dump will read the system catalogs in a database and dump out a * script that reproduces the schema in terms of SQL that is understood * by PostgreSQL * * Note that pg_dump runs in a transaction-snapshot mode transaction, * so it sees a consistent snapshot of the database including system * catalogs. However, it relies in part on various specialized backend * functions like pg_get_indexdef(), and those things tend to look at * the currently committed state. So it is possible to get 'cache * lookup failed' error if someone performs DDL changes while a dump is * happening. The window for this sort of thing is from the acquisition * of the transaction snapshot to getSchemaData() (when pg_dump acquires * AccessShareLock on every table it intends to dump). It isn't very large, * but it can happen. Or come up with way to capture the state of the data at the time of dump and then compare to restored database. Something like Ron posted. > > Thanks ! > > Laura > > -- Adrian Klaver adrian.klaver@aklaver.com