Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TsEpO-0006uF-6z for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Jan 2013 15:41:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TsEpN-00015I-BD for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Jan 2013 15:41:29 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TsEpM-00015D-N6 for pgsql-bugs@postgresql.org; Mon, 07 Jan 2013 15:41:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TsEpL-0004xB-4C for pgsql-bugs@postgresql.org; Mon, 07 Jan 2013 15:41:28 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r07FfP2n010416; Mon, 7 Jan 2013 10:41:25 -0500 (EST) From: Tom Lane To: Magnus Hagander cc: emesika@redhat.com, pgsql-bugs Subject: Re: BUG #7792: pg_dump does not treat -c flag correctly when using tar format In-reply-to: References: <10105.1357518726@sss.pgh.pa.us> Comments: In-reply-to Magnus Hagander message dated "Mon, 07 Jan 2013 13:09:49 +0100" Date: Mon, 07 Jan 2013 10:41:25 -0500 Message-ID: <10415.1357573285@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Magnus Hagander writes: > On Mon, Jan 7, 2013 at 1:32 AM, Tom Lane wrote: >> emesika@redhat.com writes: >>> * restore.sql includes DROP statements for each object even tough -c flag >>> was not given >> I believe this is intentional - at least, pg_backup_tar.c goes out of >> its way to make it happen. (The forcible setting of ropt->dropSchema >> in _CloseArchive is the cause, and it's hard to see why that would be >> there unless the author intended this effect.) Perhaps we should remove >> that, but it would be an incompatible change. Arguing for or against >> it really requires a model of what people would be doing with the >> restore.sql script. I'm not entirely convinced that it should be >> considered equivalent to what you'd get from a plain dump run. > tar archives are more like custom archives ,arne't they? The idea > being that since you use pg_restore to restore them, you should use -c > on the pg_restore commandline, and not on the pg_dump one? And if we > didn't include it in the dump, that wouldn't even be possible. No, pg_restore depends only on what is in the TOC data structure. The restore.sql script is just an auxiliary file that's there if you extract the contents of the tar file --- pg_restore doesn't use it. On reviewing the commit history, I find that pg_backup_tar.c was created in commit c3e18804ff14f690a6d8c31b452476d0f8fcec28, and in that version the code looked like ropt = NewRestoreOptions(); ropt->dropSchema = 1; ropt->compression = 0; RestoreArchive((Archive*)AH, ropt); where the recursive call to RestoreArchive is what scans the TOC and prints the contents of restore.sql. I am not sure that in 2000 the function even had the opportunity to pass down the outer restore options to the recursive call, but it certainly didn't try. Somewhere along the line we added a link to RestoreOptions to the ArchiveHandle data structure, and since last year (commit 4317e0246c645f60c39e6572644cff1cb03b4c65) the code looks like ropt = NewRestoreOptions(); + memcpy(ropt, AH->ropt, sizeof(RestoreOptions)); ropt->dropSchema = 1; ropt->compression = 0; ropt->superuser = NULL; ropt->suppressDumpWarnings = true; + savRopt = AH->ropt; + AH->ropt = ropt; + savVerbose = AH->public.verbose; AH->public.verbose = 0; - RestoreArchive((Archive *) AH, ropt); + RestoreArchive((Archive *) AH); + AH->ropt = savRopt; AH->public.verbose = savVerbose; So at this point passing down options is the norm and forcibly setting dropSchema is the exception. (The forced clearing of superuser seems a bit debatable now too.) Maybe we should change it, but it would definitely be a user-visible behavioral change. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs