postgresql/src/bin/pg_dump
Tom Lane 3d76328298 Fix pg_dump/pg_restore to emit REFRESH MATERIALIZED VIEW commands last.
Because we push all ACL (i.e. GRANT/REVOKE) restore steps to the end,
materialized view refreshes were occurring while the permissions on
referenced objects were still at defaults.  This led to failures if,
say, an MV owned by user A reads from a table owned by user B, even
if B had granted the necessary privileges to A.  We've had multiple
complaints about that type of restore failure, most recently from
Jordan Gigov.

The ideal fix for this would be to start treating ACLs as dependency-
sortable objects, rather than hard-wiring anything about their dump order
(the existing approach is a messy kluge dating to commit dc0e76ca3).
But that's going to be a rather major change, and it certainly wouldn't
lead to a back-patchable fix.  As a short-term solution, convert the
existing two-pass hack (ie, normal objects then ACLs) to a three-pass hack,
ie, normal objects then ACLs then matview refreshes.  Because this happens
in RestoreArchive(), it will also fix the problem when restoring from an
existing archive-format dump.

(Note this means that if a matview refresh would have failed under the
permissions prevailing at dump time, it'll fail during restore as well.
We'll define that as user error rather than something we should try
to work around.)

To avoid performance loss in parallel restore, we need the matview
refreshes to still be parallelizable.  Hence, clean things up enough
so that both ACLs and matviews are handled by the parallel restore
infrastructure, instead of reverting back to serial restore for ACLs.
There is still a final serial step, but it shouldn't normally have to
do anything; it's only there to try to recover if we get stuck due to
some problem like unresolved circular dependencies.

Patch by me, but it owes something to an earlier attempt by Kevin Grittner.
Back-patch to 9.3 where materialized views were introduced.

Discussion: https://postgr.es/m/28572.1500912583@sss.pgh.pa.us
2017-08-03 17:36:41 -04:00
..
po Translation updates 2017-05-08 10:10:54 -04:00
t Fix pg_dump's handling of event triggers. 2017-07-22 20:20:09 -04:00
.gitignore Clean up after pg_dump test runs. 2016-05-06 22:28:01 -04:00
common.c In pg_dump, use a bitmap to represent what to include 2016-04-06 21:45:32 -04:00
compress_io.c Fix pg_dump's errno checking for zlib I/O 2017-08-02 18:26:58 -04:00
compress_io.h Fix pg_dump's errno checking for zlib I/O 2017-08-02 18:26:58 -04:00
dumputils.c pg_dump: Don't leak memory in buildDefaultACLCommands() 2017-05-06 22:58:22 -04:00
dumputils.h pg_dump: Fix handling of ALTER DEFAULT PRIVILEGES 2017-01-31 16:24:14 -05:00
Makefile Fix broken link-command-line ordering for libpgfeutils. 2017-07-14 12:26:53 -04:00
nls.mk Translation updates 2016-05-09 10:04:41 -04:00
parallel.c Include <sys/select.h> where needed 2016-09-27 01:05:21 -03:00
parallel.h Redesign handling of SIGTERM/control-C in parallel pg_dump/pg_restore. 2016-06-02 13:28:17 -04:00
pg_backup.h pg_upgrade: Fix large object COMMENTS, SECURITY LABELS 2017-03-06 17:04:06 -05:00
pg_backup_archiver.c Fix pg_dump/pg_restore to emit REFRESH MATERIALIZED VIEW commands last. 2017-08-03 17:36:41 -04:00
pg_backup_archiver.h Fix pg_dump/pg_restore to emit REFRESH MATERIALIZED VIEW commands last. 2017-08-03 17:36:41 -04:00
pg_backup_custom.c Fix typos in comments. 2017-02-06 11:34:15 +02:00
pg_backup_db.c Ignore PQcancel errors properly 2017-05-09 14:58:51 -03:00
pg_backup_db.h Make pg_dump error cleanly with -j against hot standby 2016-05-26 22:14:23 +02:00
pg_backup_directory.c Fix pg_dump's errno checking for zlib I/O 2017-08-02 18:26:58 -04:00
pg_backup_null.c Create src/fe_utils/, and move stuff into there from pg_dump's dumputils. 2016-03-24 15:55:57 -04:00
pg_backup_tar.c Fix build on zlib-less environments 2017-08-03 14:55:18 -04:00
pg_backup_tar.h Fix tar files emitted by pg_dump and pg_basebackup to be POSIX conformant. 2012-09-28 15:19:15 -04:00
pg_backup_utils.c Clean up thread management in parallel pg_dump for Windows. 2016-05-27 12:02:09 -04:00
pg_backup_utils.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_dump.c Fix function comment for dumpACL() 2017-07-31 10:37:12 -04:00
pg_dump.h pg_dump: Fix handling of ALTER DEFAULT PRIVILEGES 2017-01-31 16:24:14 -05:00
pg_dump_sort.c pgindent run for 9.6 2016-06-09 18:02:36 -04:00
pg_dumpall.c pg_dumpall: Include --verbose option in --help output 2016-12-24 01:42:07 -05:00
pg_restore.c pg_restore: Don't allow non-positive number of jobs 2017-01-11 15:45:53 -05:00