代码:
# 1. Cleanup, in case we run this script more than once
psql -U postgres -c 'DROP DATABASE IF EXISTS t1'
rm -rf t1_dump
# 2. Create database and grant all to janbet
psql -U postgres -c 'CREATE DATABASE t1'
psql -d t1 -U postgres -c 'GRANT ALL ON DATABASE t1 TO janbet'
# 3. Check access to schema public (it works)
psql -d t1 -U janbet -c 'CREATE TABLE public.x AS SELECT 1'
# 4. Create pg_dump
pg_dump -d t1 -U janbet --format=d --file=t1_dump
# 5. Restore database t1
pg_restore -d t1 -U postgres --clean t1_dump
# 6. Check access to schema public
psql -d t1 -U janbet -c 'CREATE TABLE public.y AS SELECT 1'
输出:
DROP DATABASE
CREATE DATABASE
GRANT
SELECT 1
ERROR: permission denied for schema public
在psql中,dn+在还原之前返回:
List of schemas
Name | Owner | Access privileges | Description
--------+----------+----------------------+------------------------
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
在恢复之后:
List of schemas
Name | Owner | Access privileges | Description
--------+----------+-------------------+------------------------
public | postgres | | standard public schema
所以,很明显一些特权是缺失的。问题:
为什么pg_恢复变更特权?
如果这是一个bug,还有其他类似的问题吗?
是否有经批准的解决方法?我知道
GRANT USAGE ON SCHEMA public TO janbet
工作得很好,但也许这不是必要的?我在google上找到了this,但我的问题没有明确的答案。
版本:
version
-----------------------------------------------------------------------------------------------------------------------------
PostgreSQL 10.4 (Ubuntu 10.4-0ubuntu0.18.04) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0, 64-bit
最佳答案
This对您链接的bug报告的响应同意这是一个bug,我同意这一观点。
我相信没人能解决这个问题。。。
也许你可以戳到黑客名单。
关于postgresql - pg_restore --clean删除对模式public的访问,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51673254/