Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dkWLi-0004hO-Nq for pgsql-bugs@arkaria.postgresql.org; Wed, 23 Aug 2017 14:09:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dkWLh-00056e-Pe for pgsql-bugs@arkaria.postgresql.org; Wed, 23 Aug 2017 14:09:37 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dkWDc-00084Y-9p for pgsql-bugs@postgresql.org; Wed, 23 Aug 2017 14:01:16 +0000 Received: from www2248.sakura.ne.jp ([182.48.49.188]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dkWDW-00018O-Pj for pgsql-bugs@postgresql.org; Wed, 23 Aug 2017 14:01:14 +0000 Received: from fsav301.sakura.ne.jp (fsav301.sakura.ne.jp [153.120.85.132]) by www2248.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id v7NE14be033690; Wed, 23 Aug 2017 23:01:04 +0900 (JST) (envelope-from fujimoto@ceptord.net) Received: from www2248.sakura.ne.jp (182.48.49.188) by fsav301.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav301.sakura.ne.jp); Wed, 23 Aug 2017 23:01:04 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav301.sakura.ne.jp) Received: from localhost (p423030-omed01.osaka.ocn.ne.jp [153.155.214.30]) (authenticated bits=0) by www2248.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id v7NE13ug033673 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 23 Aug 2017 23:01:03 +0900 (JST) (envelope-from fujimoto@ceptord.net) Date: Wed, 23 Aug 2017 23:00:58 +0900 From: Fujimoto Seiji To: Masahiko Sawada Cc: pgsql-bugs Subject: Re: BUG #14788: `pg_restore -c` won't restore schema access privileges. Message-ID: <20170823140058.2ojn2ajcamd43s76@holly> References: <20170821104439.1455.12525@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) 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 Thanks! That discussion thread is very informative. My understanding is: 1. By default, a newly created schema has an empty ACL. It means that normal users cannot access it without permission granted explicitly. 2. However, "public" schema has special semantics; It gets created with permissive ACL so that anyone can access it. 3. Since 9.6, pg_dump stops to output this "special" privilege part to the dump (for some internal reasons). 9.6.3 tries to fix this issue by patching `pg_dump -c` behavior. Although I'm not so sure that the current behavior ("-c option affects 'custom' format dumps") is intended one, it seems we can reasonably work around this issue. So thanks for the response. It really was a lot of help. On Wed, Aug 23, 2017 at 05:06:43PM +0900, Masahiko Sawada wrote: > On Mon, Aug 21, 2017 at 7:44 PM, wrote: > > The following bug has been logged on the website: > > > > Bug reference: 14788 > > Logged by: Fujimoto Seiji > > Email address: fujimoto@ceptord.net > > PostgreSQL version: 9.6.4 > > Operating system: Linux 4.9.0 (Debian 9.1) > > Description: > > > > ## How to reproduce > > > > 1. Create a new database: > > > > $ createdb --template=template0 test > > $ psql -c '\dn+' test > > list of schemas > > name | owner | access privileges | description > > --------+----------+----------------------+------------------------ > > public | postgres | postgres=uc/postgres+| standard public schema > > | | =uc/postgres | > > (1 row) > > > > 2. pg_dump the database with 'custom' format: > > > > $ pg_dump -Fc -f test.dump test > > > > 3. Restore the dump with '-c' option: > > > > $ pg_restore -c -d test test.dump > > > > > > ## Bug/Problem > > > > Now all the access privileges on the public schema are gone: > > > > $ psql -c '\dn+' test > > List of schemas > > Name | Owner | Access privileges | Description > > --------+----------+-------------------+------------------------ > > public | postgres | | standard public schema > > (1 row) > > > > > > ## Expected behabior > > > > Granted privileges gets restored correctly. > > > > > > ## Additional notes > > > > Interestingly, if the database has been dumped with '-c' option, > > pg_restore > > will restore the schema privileges correctly. > > > > $ createdb --template=template0 test > > $ pg_dump -Fc -c -f test.dump > > $ pg_restore -c -d test test.dump > > $ psql -c '\dn+' test > > List of schemas > > Name | Owner | Access privileges | Description > > --------+----------+----------------------+------------------------ > > public | postgres | postgres=UC/postgres+| standard public schema > > | | =UC/postgres | > > (1 row) > > > > (I do not understand why '-c' option affects the custom format dump. > > This behaviour itself contradicts what the documentation states) > > > >> -c > >> --clean > >> > >> ... > >> This option is only meaningful for the plain-text format. For the > > archive > >> formats, you can specify the option when you call pg_restore. > >> > >> https://www.postgresql.org/docs/9.6/static/app-pgdump.html > > > > I think it's not a bug. This behavior is introduced in PostgreSQL > 9.6.3 by a discussion[1]. For the reason, please see PostgreSQL 9.6.3 > release note[2]. > > ---- > Fix pg_dump/pg_restore to correctly handle privileges for the public > schema when using --clean option (Stephen Frost) > Other schemas start out with no privileges granted, but public does > not; this requires special-case treatment when it is dropped and > restored due to the --clean option. > ---- > > [1] https://www.postgresql.org/message-id/3534542.o3cNaKiDID%40techfox > [2] https://www.postgresql.org/docs/current/static/release-9-6-3.html > > Regards, > > -- > Masahiko Sawada > NIPPON TELEGRAPH AND TELEPHONE CORPORATION > NTT Open Source Software Center -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs