Postgresql 使用pg_Dump转储数据库,忽略我们无权访问的表

Postgresql 使用pg_Dump转储数据库,忽略我们无权访问的表,postgresql,pg-dump,database-dump,Postgresql,Pg Dump,Database Dump,我有一个脚本,其中pg_dump失败,并显示如下消息: pg_dump -h db1 --format plain --encoding UTF8 --schema=public --schema-only --no-owner me pg_dump: [archiver (db)] query failed: ERROR: permission denied for relation notmytable pg_dump: [archiver (db)] query was: LOCK TA

我有一个脚本,其中pg_dump失败,并显示如下消息:

pg_dump -h db1 --format plain --encoding UTF8 --schema=public --schema-only --no-owner me
pg_dump: [archiver (db)] query failed: ERROR:  permission denied for relation notmytable
pg_dump: [archiver (db)] query was: LOCK TABLE public.notmytable IN ACCESS SHARE MODE
这将导致整个转储中止

有没有办法:

忽略不属于用户的表? 忽略错误? 我真的不希望这些表在转储中,所以即使我们可以访问它们,也不能完全解决问题


Postgres 9.6.3

似乎没有标准的方法来实现这一点,但是使用-exclude table标志,我们可以使用一种变通方法:

export EXCLUDETABLE=$psql-t-h$HOST-d$DBNAME-c select'-exclude table='| | | string_aggtablename'-exclude table='来自pg_catalog.pg_表,其中tableowner与'myuser'不同; 这将EXCLUDETABLE设置为-exclude table=foo-exclude table=blah

现在我们将其传递给pg_dump:

echo从转储中排除这些表:$EXCLUDETABLE pg_dump-h$HOST-format plain-encoding UTF8-schema=public-schema only-no owner$EXCLUDETABLE$DBNAME>public-schema.sql