Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1ea4d9c

Browse files
committed
vacuumdb: Skip temporary tables in query to build list of relations
Running vacuumdb with a non-superuser while another user has created atemporary table would lead to a mid-flight permission failure,interrupting the operation. vacuum_rel() skips temporary relations ofother backends, and it makes no sense for vacuumdb to know about theserelations, so let's switch it to ignore temporary relations entirely.Adding a qual in the query based on relpersistence simplifies thegeneration of its WHERE clause in vacuum_one_database(), per se theremoval of "has_where".Author: VaibhaveS, Michael PaquierReviewed-by: Fujii MasaoDiscussion:https://postgr.es/m/CAM_eQjwfAR=y3G1fGyS1U9FTmc+FyJm9amNfY2QCZBnDDbNPZg@mail.gmail.comBackpatch-through: 12
1 parent90f5412 commit1ea4d9c

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

‎src/bin/scripts/vacuumdb.c

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ vacuum_one_database(ConnParams *cparams,
501501
intntups;
502502
boolfailed= false;
503503
boolobjects_listed= false;
504-
boolhas_where= false;
505504
constchar*initcmd;
506505
constchar*stage_commands[]= {
507506
"SET default_statistics_target=1; SET vacuum_cost_delay=0;",
@@ -675,7 +674,10 @@ vacuum_one_database(ConnParams *cparams,
675674
" LEFT JOIN pg_catalog.pg_class t"
676675
" ON c.reltoastrelid OPERATOR(pg_catalog.=) t.oid\n");
677676

678-
/* Used to match the tables or schemas listed by the user */
677+
/*
678+
* Used to match the tables or schemas listed by the user, completing the
679+
* JOIN clause.
680+
*/
679681
if (objects_listed)
680682
{
681683
appendPQExpBufferStr(&catalog_query," LEFT JOIN listed_objects"
@@ -686,14 +688,26 @@ vacuum_one_database(ConnParams *cparams,
686688
appendPQExpBufferStr(&catalog_query,"c.oid\n");
687689
else
688690
appendPQExpBufferStr(&catalog_query,"ns.oid\n");
691+
}
689692

693+
/*
694+
* Exclude temporary tables, beginning the WHERE clause.
695+
*/
696+
appendPQExpBufferStr(&catalog_query,
697+
" WHERE c.relpersistence != "CppAsString2(RELPERSISTENCE_TEMP));
698+
699+
/*
700+
* Used to match the tables or schemas listed by the user, for the WHERE
701+
* clause.
702+
*/
703+
if (objects_listed)
704+
{
690705
if (objfilter&OBJFILTER_SCHEMA_EXCLUDE)
691706
appendPQExpBuffer(&catalog_query,
692-
"WHERE listed_objects.object_oid IS NULL\n");
707+
"AND listed_objects.object_oid IS NULL\n");
693708
else
694709
appendPQExpBuffer(&catalog_query,
695-
" WHERE listed_objects.object_oid IS NOT NULL\n");
696-
has_where= true;
710+
" AND listed_objects.object_oid IS NOT NULL\n");
697711
}
698712

699713
/*
@@ -705,11 +719,9 @@ vacuum_one_database(ConnParams *cparams,
705719
if ((objfilter&OBJFILTER_TABLE)==0)
706720
{
707721
appendPQExpBuffer(&catalog_query,
708-
"%s c.relkind OPERATOR(pg_catalog.=) ANY (array["
722+
"AND c.relkind OPERATOR(pg_catalog.=) ANY (array["
709723
CppAsString2(RELKIND_RELATION)", "
710-
CppAsString2(RELKIND_MATVIEW)"])\n",
711-
has_where ?"AND" :"WHERE");
712-
has_where= true;
724+
CppAsString2(RELKIND_MATVIEW)"])\n");
713725
}
714726

715727
/*
@@ -722,25 +734,23 @@ vacuum_one_database(ConnParams *cparams,
722734
if (vacopts->min_xid_age!=0)
723735
{
724736
appendPQExpBuffer(&catalog_query,
725-
"%s GREATEST(pg_catalog.age(c.relfrozenxid),"
737+
"AND GREATEST(pg_catalog.age(c.relfrozenxid),"
726738
" pg_catalog.age(t.relfrozenxid)) "
727739
" OPERATOR(pg_catalog.>=) '%d'::pg_catalog.int4\n"
728740
" AND c.relfrozenxid OPERATOR(pg_catalog.!=)"
729741
" '0'::pg_catalog.xid\n",
730-
has_where ?"AND" :"WHERE",vacopts->min_xid_age);
731-
has_where= true;
742+
vacopts->min_xid_age);
732743
}
733744

734745
if (vacopts->min_mxid_age!=0)
735746
{
736747
appendPQExpBuffer(&catalog_query,
737-
"%s GREATEST(pg_catalog.mxid_age(c.relminmxid),"
748+
"AND GREATEST(pg_catalog.mxid_age(c.relminmxid),"
738749
" pg_catalog.mxid_age(t.relminmxid)) OPERATOR(pg_catalog.>=)"
739750
" '%d'::pg_catalog.int4\n"
740751
" AND c.relminmxid OPERATOR(pg_catalog.!=)"
741752
" '0'::pg_catalog.xid\n",
742-
has_where ?"AND" :"WHERE",vacopts->min_mxid_age);
743-
has_where= true;
753+
vacopts->min_mxid_age);
744754
}
745755

746756
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp