[COMMITTERS] pgsql: Fix pg_dump/pg_restore to emit REFRESH MATERIALIZED VIEWcommand

Поиск
Список
Период
Сортировка
От Tom Lane
Тема [COMMITTERS] pgsql: Fix pg_dump/pg_restore to emit REFRESH MATERIALIZED VIEWcommand
Дата
Msg-id E1ddNne-0001jw-Vx@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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

Branch
------
REL9_4_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b93217653b6874a71f3e981882cdc0dd36c0e540

Modified Files
--------------
src/bin/pg_dump/pg_backup_archiver.c | 357 +++++++++++++++++++++++------------
src/bin/pg_dump/pg_backup_archiver.h |  25 +++
2 files changed, 260 insertions(+), 122 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: [COMMITTERS] pgsql: Fix build on zlib-less environments
Следующее
От: Peter Eisentraut
Дата:
Сообщение: [COMMITTERS] pgsql: Add missing ALTER USER variants