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 1gj9fT-0008QA-Cv for pgsql-general@arkaria.postgresql.org; Mon, 14 Jan 2019 21:21:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gj9fR-0007eJ-KK for pgsql-general@arkaria.postgresql.org; Mon, 14 Jan 2019 21:21:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gj9fR-0007eC-8z for pgsql-general@lists.postgresql.org; Mon, 14 Jan 2019 21:21:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gj9fO-0005YN-Sr for pgsql-general@postgresql.org; Mon, 14 Jan 2019 21:21:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x0ELL4UY024233; Mon, 14 Jan 2019 16:21:04 -0500 From: Tom Lane To: Sherrylyn Branchaw cc: pgsql-general@postgresql.org Subject: Re: pg_restore restores privileges differently from psql In-reply-to: References: Comments: In-reply-to Sherrylyn Branchaw message dated "Mon, 14 Jan 2019 13:15:22 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24231.1547500864.1@sss.pgh.pa.us> Date: Mon, 14 Jan 2019 16:21:04 -0500 Message-ID: <24232.1547500864@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Sherrylyn Branchaw writes: > I'm restoring the schema from one database (prod) to another (dev). There > are users that exist in prod that don't exist in dev. When the restore job > tries to grant privileges to nonexistent users in dev, I would like it to > generate an error, which is safe to ignore, but still correctly grant > privileges to any user that does exist in dev. > That's the behavior I see when I dump to a plain file and restore it > using *psql > -f*, but not the behavior I see when I do a *pg_dump -Fc* followed by > *pg_restore.* *pg_restore *seems to treat all the *GRANT* statements for a > single object as a single statement, and when one errors out, they all > error out, meaning I'm left with no privileges on the object in question. Yeah, this is a known issue --- the various GRANTs for a specific object are stored in a single "TOC entry" in the archive, which pg_restore will send to the server in a single PQexec call, causing them to be effectively one transaction. The easiest way to deal with it is to not send pg_restore's output directly to the target server, but feed it through psql, something like pg_restore ... | psql [connection parameters] There's been some discussion of a real fix, but it seems messy. pg_restore doesn't have a parser that would be adequate to separate out multiple SQL commands in a TOC entry, and we'd rather not try to give it one (mainly because of fear of cross-version compatibility issues). regards, tom lane