pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bossart, Nathan <bossartn@amazon.com>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Lyes Ameddah <lyes.amd@gmail.com>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14941: Vacuum crashes
Date: Wed, 10 Jan 2018 17:26:43 +0000
Message-ID: <CBEE19BB-6C70-424C-95E5-F8ABC7AA2185@amazon.com> (raw)
In-Reply-To: <20180110025331.GE336@paquier.xyz>
References: <CAB7nPqTyY_7rXFi_=7DX_xZad43snZvDpw-KU+SuX20euGNhbQ@mail.gmail.com>
	<CAD21AoBGtBXxsDECmVVHsM-d64nK2qiDhZ5_tOreBH86=h7Smw@mail.gmail.com>
	<AD80AE03-8A5D-40A2-99C9-C26646489E49@amazon.com>
	<48A02BB8-A7DE-4D11-9586-0BBE5E6FE4F3@amazon.com>
	<CAD21AoC9D528HBugWumq678t_GOLft-KyeGyG=VFeyKfHY4Z5A@mail.gmail.com>
	<32F4B778-292B-41AF-891A-497B8127CD59@amazon.com>
	<CAD21AoCsbqVh5P=ZA479DHrXmtUY2TxPxotE0jPiwM2+gQUjxw@mail.gmail.com>
	<5B80D67E-A664-495A-A0BE-CEA847676164@amazon.com>
	<20180109042720.GG76418@paquier.xyz>
	<4B232BD7-A97D-4461-81E6-28A49764B60E@amazon.com>
	<20180110025331.GE336@paquier.xyz>

On 1/9/18, 8:54 PM, "Michael Paquier" <michael.paquier@gmail.com> wrote:
> Backpedalling a bit on this point and coming back to this message from
> Tom (https://www.postgresql.org/message-id/28748.1507071576%40sss.pgh.pa.us)
> which you just cited. Why do we actually need to issue any WARNING
> messages for unlisted relations? Contrary to what Sawada-san complained
> upthread, it looks sane to me to not log anything if a relation is not
> explicitely listed. So you should not get any warnings for a
> database-wide VACUUM if a relation is dropped while the thing is
> running, and what you proposed initially in
> https://www.postgresql.org/message-id/D3FC73E2-9B1A-4DB4-8180-55F57D116B4E@amazon.com
> is more simple, does not need to worry about any kind of timing issues,
> and is consistent with autovacuum.

Right.  I don't have a terribly strong opinion either way.  I think the
counter-argument is that logging skipped relations might provide
valuable feedback to users.  If I ran a database-wide VACUUM and a
relation was skipped due to lock contention, it might be nice to know
that so I can handle the relation individually.

Perhaps any logging changes for VACOPT_NOWAIT could be handled in a
separate thread.  For now, I've updated 0003 to remove the logging
changes.

Nathan



Attachments: download all (2 files, .tar.gz)

0003_add_nowait_vacuum_option_v4.patch (application/octet-stream, 7.8K) download diff --git a/doc/src/sgml/ref/analyze.sgml b/doc/src/sgml/ref/analyze.sgml index 10b3a9a..05882c3 100644 --- a/doc/src/sgml/ref/analyze.sgml +++ b/doc/src/sgml/ref/analyze.sgml @@ -27,6 +27,7 @@ ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replacea <phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase> VERBOSE + NOWAIT <phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase> @@ -77,6 +78,17 @@ ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replacea </varlistentry> <varlistentry> + <term><literal>NOWAIT</literal></term> + <listitem> + <para> + Specifies that <command>ANALYZE</command> should not wait for any + conflicting locks to be released: if a relation cannot be locked + immediately without waiting, the relation is skipped. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><replaceable class="parameter">table_name</replaceable></term> <listitem> <para> diff --git a/doc/src/sgml/ref/vacuum.sgml b/doc/src/sgml/ref/vacuum.sgml index b760e8e..1d7ffef 100644 --- a/doc/src/sgml/ref/vacuum.sgml +++ b/doc/src/sgml/ref/vacuum.sgml @@ -31,6 +31,7 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet VERBOSE ANALYZE DISABLE_PAGE_SKIPPING + NOWAIT <phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase> @@ -161,6 +162,17 @@ VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ <replaceable class="paramet </varlistentry> <varlistentry> + <term><literal>NOWAIT</literal></term> + <listitem> + <para> + Specifies that <command>VACUUM</command> should not wait for any + conflicting locks to be released: if a relation cannot be locked + immediately without waiting, the relation is skipped. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><replaceable class="parameter">table_name</replaceable></term> <listitem> <para> diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 1c8f115..34cf156 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -10507,6 +10507,7 @@ vacuum_option_elem: errmsg("unrecognized VACUUM option \"%s\"", $1), parser_errposition(@1))); } + | NOWAIT { $$ = VACOPT_NOWAIT; } ; AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list @@ -10534,6 +10535,7 @@ analyze_option_list: analyze_option_elem: VERBOSE { $$ = VACOPT_VERBOSE; } + | NOWAIT { $$ = VACOPT_NOWAIT; } ; analyze_keyword: diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index b72178e..2d0f581 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3116,7 +3116,7 @@ typedef enum VacuumOption VACOPT_VERBOSE = 1 << 2, /* print progress info */ VACOPT_FREEZE = 1 << 3, /* FREEZE option */ VACOPT_FULL = 1 << 4, /* FULL (non-concurrent) vacuum */ - VACOPT_NOWAIT = 1 << 5, /* don't wait to get lock (autovacuum only) */ + VACOPT_NOWAIT = 1 << 5, /* don't wait to get lock */ VACOPT_SKIPTOAST = 1 << 6, /* don't process the TOAST table, if any */ VACOPT_DISABLE_PAGE_SKIPPING = 1 << 7 /* don't skip any pages */ } VacuumOption; diff --git a/src/test/isolation/expected/vacuum-nowait.out b/src/test/isolation/expected/vacuum-nowait.out new file mode 100644 index 0000000..225ec23 --- /dev/null +++ b/src/test/isolation/expected/vacuum-nowait.out @@ -0,0 +1,64 @@ +Parsed test spec with 2 sessions + +starting permutation: lock vac_specified commit +step lock: + BEGIN; + LOCK part1 IN SHARE MODE; + +WARNING: skipping vacuum of "part1" --- lock not available +step vac_specified: VACUUM (NOWAIT) part1, part2; +step commit: + COMMIT; + + +starting permutation: lock vac_all_parts commit +step lock: + BEGIN; + LOCK part1 IN SHARE MODE; + +step vac_all_parts: VACUUM (NOWAIT) parted; +step commit: + COMMIT; + + +starting permutation: lock analyze_specified commit +step lock: + BEGIN; + LOCK part1 IN SHARE MODE; + +WARNING: skipping analyze of "part1" --- lock not available +step analyze_specified: ANALYZE (NOWAIT) part1, part2; +step commit: + COMMIT; + + +starting permutation: lock analyze_all_parts commit +step lock: + BEGIN; + LOCK part1 IN SHARE MODE; + +step analyze_all_parts: ANALYZE (NOWAIT) parted; +step commit: + COMMIT; + + +starting permutation: lock vac_analyze_specified commit +step lock: + BEGIN; + LOCK part1 IN SHARE MODE; + +WARNING: skipping vacuum of "part1" --- lock not available +step vac_analyze_specified: VACUUM (ANALYZE, NOWAIT) part1, part2; +step commit: + COMMIT; + + +starting permutation: lock vac_analyze_all_parts commit +step lock: + BEGIN; + LOCK part1 IN SHARE MODE; + +step vac_analyze_all_parts: VACUUM (ANALYZE, NOWAIT) parted; +step commit: + COMMIT; + diff --git a/src/test/isolation/isolation_schedule b/src/test/isolation/isolation_schedule index befe676..9d0dc7b 100644 --- a/src/test/isolation/isolation_schedule +++ b/src/test/isolation/isolation_schedule @@ -65,3 +65,4 @@ test: async-notify test: vacuum-reltuples test: timeouts test: vacuum-concurrent-drop +test: vacuum-nowait diff --git a/src/test/isolation/specs/vacuum-nowait.spec b/src/test/isolation/specs/vacuum-nowait.spec new file mode 100644 index 0000000..498b0a0 --- /dev/null +++ b/src/test/isolation/specs/vacuum-nowait.spec @@ -0,0 +1,42 @@ +# Test for the NOWAIT option for VACUUM and ANALYZE commands. +# +# This also verifies that log messages are not emitted for skipped relations +# that were not specified in the VACUUM or ANALYZE command. + +setup +{ + CREATE TABLE parted (a INT) PARTITION BY LIST (a); + CREATE TABLE part1 PARTITION OF parted FOR VALUES IN (1); + CREATE TABLE part2 PARTITION OF parted FOR VALUES IN (2); +} + +teardown +{ + DROP TABLE IF EXISTS parted; +} + +session "s1" +step "lock" +{ + BEGIN; + LOCK part1 IN SHARE MODE; +} +step "commit" +{ + COMMIT; +} + +session "s2" +step "vac_specified" { VACUUM (NOWAIT) part1, part2; } +step "vac_all_parts" { VACUUM (NOWAIT) parted; } +step "analyze_specified" { ANALYZE (NOWAIT) part1, part2; } +step "analyze_all_parts" { ANALYZE (NOWAIT) parted; } +step "vac_analyze_specified" { VACUUM (ANALYZE, NOWAIT) part1, part2; } +step "vac_analyze_all_parts" { VACUUM (ANALYZE, NOWAIT) parted; } + +permutation "lock" "vac_specified" "commit" +permutation "lock" "vac_all_parts" "commit" +permutation "lock" "analyze_specified" "commit" +permutation "lock" "analyze_all_parts" "commit" +permutation "lock" "vac_analyze_specified" "commit" +permutation "lock" "vac_analyze_all_parts" "commit" diff --git a/src/test/regress/expected/vacuum.out b/src/test/regress/expected/vacuum.out index 199dda6..99aad21 100644 --- a/src/test/regress/expected/vacuum.out +++ b/src/test/regress/expected/vacuum.out @@ -113,8 +113,11 @@ ERROR: relation "does_not_exist" does not exist ANALYZE vactst (i), vacparted (does_not_exist); ERROR: column "does_not_exist" of relation "vacparted" does not exist -- parenthesized syntax for ANALYZE -ANALYZE (VERBOSE) does_not_exist; +ANALYZE (NOWAIT, VERBOSE) does_not_exist; ERROR: relation "does_not_exist" does not exist +-- nowait option +VACUUM (NOWAIT) vactst; +ANALYZE (NOWAIT) vactst; DROP TABLE vaccluster; DROP TABLE vactst; DROP TABLE vacparted; diff --git a/src/test/regress/sql/vacuum.sql b/src/test/regress/sql/vacuum.sql index e7b7a7f..5e88c68 100644 --- a/src/test/regress/sql/vacuum.sql +++ b/src/test/regress/sql/vacuum.sql @@ -90,7 +90,11 @@ ANALYZE vactst, does_not_exist, vacparted; ANALYZE vactst (i), vacparted (does_not_exist); -- parenthesized syntax for ANALYZE -ANALYZE (VERBOSE) does_not_exist; +ANALYZE (NOWAIT, VERBOSE) does_not_exist; + +-- nowait option +VACUUM (NOWAIT) vactst; +ANALYZE (NOWAIT) vactst; DROP TABLE vaccluster; DROP TABLE vactst;
0002_add_parenthesized_analyzed_syntax_v2.patch (application/octet-stream, 3.6K) download diff --git a/doc/src/sgml/ref/analyze.sgml b/doc/src/sgml/ref/analyze.sgml index 83b07a0..10b3a9a 100644 --- a/doc/src/sgml/ref/analyze.sgml +++ b/doc/src/sgml/ref/analyze.sgml @@ -21,9 +21,14 @@ PostgreSQL documentation <refsynopsisdiv> <synopsis> +ANALYZE [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] [ <replaceable class="parameter">table_and_columns</replaceable> [, ...] ] ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replaceable> [, ...] ] -<phrase>where <replaceable class="parameter">table_and_columns</replaceable> is:</phrase> +<phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase> + + VERBOSE + +<phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase> <replaceable class="parameter">table_name</replaceable> [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ] </synopsis> @@ -49,6 +54,13 @@ ANALYZE [ VERBOSE ] [ <replaceable class="parameter">table_and_columns</replacea It is further possible to give a list of column names for a table, in which case only the statistics for those columns are collected. </para> + + <para> + When the option list is surrounded by parentheses, the options can be + written in any order. The parenthesized syntax was added in + <productname>PostgreSQL</productname> 11; the unparenthesized syntax + is deprecated. + </para> </refsect1> <refsect1> diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 3c76bda..d0a5203 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -306,6 +306,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query); %type <ival> opt_lock lock_type cast_context %type <ival> vacuum_option_list vacuum_option_elem + analyze_option_list analyze_option_elem %type <boolean> opt_or_replace opt_grant_grant_option opt_grant_admin_option opt_nowait opt_if_exists opt_with_data @@ -10517,6 +10518,22 @@ AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list n->rels = $3; $$ = (Node *)n; } + | analyze_keyword '(' analyze_option_list ')' opt_vacuum_relation_list + { + VacuumStmt *n = makeNode(VacuumStmt); + n->options = VACOPT_ANALYZE | $3; + n->rels = $5; + $$ = (Node *) n; + } + ; + +analyze_option_list: + analyze_option_elem { $$ = $1; } + | analyze_option_list ',' analyze_option_elem { $$ = $1 | $3; } + ; + +analyze_option_elem: + VERBOSE { $$ = VACOPT_VERBOSE; } ; analyze_keyword: diff --git a/src/test/regress/expected/vacuum.out b/src/test/regress/expected/vacuum.out index c440c7e..199dda6 100644 --- a/src/test/regress/expected/vacuum.out +++ b/src/test/regress/expected/vacuum.out @@ -112,6 +112,9 @@ ANALYZE vactst, does_not_exist, vacparted; ERROR: relation "does_not_exist" does not exist ANALYZE vactst (i), vacparted (does_not_exist); ERROR: column "does_not_exist" of relation "vacparted" does not exist +-- parenthesized syntax for ANALYZE +ANALYZE (VERBOSE) does_not_exist; +ERROR: relation "does_not_exist" does not exist DROP TABLE vaccluster; DROP TABLE vactst; DROP TABLE vacparted; diff --git a/src/test/regress/sql/vacuum.sql b/src/test/regress/sql/vacuum.sql index 92eaca2..e7b7a7f 100644 --- a/src/test/regress/sql/vacuum.sql +++ b/src/test/regress/sql/vacuum.sql @@ -89,6 +89,9 @@ ANALYZE vacparted (b), vactst; ANALYZE vactst, does_not_exist, vacparted; ANALYZE vactst (i), vacparted (does_not_exist); +-- parenthesized syntax for ANALYZE +ANALYZE (VERBOSE) does_not_exist; + DROP TABLE vaccluster; DROP TABLE vactst; DROP TABLE vacparted;

view thread (42+ messages)  latest in thread

Message-ID: <CBEE19BB-6C70-424C-95E5-F8ABC7AA2185@amazon.com>
Permalink:  ../CBEE19BB-6C70-424C-95E5-F8ABC7AA2185@amazon.com/
Also on:    postgresql.org/message-id/CBEE19BB-6C70-424C-95E5-F8ABC7AA2185@amazon.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: bossartn@amazon.com, michael.paquier@gmail.com, sawada.mshk@gmail.com, robertmhaas@gmail.com, lyes.amd@gmail.com, tomas.vondra@2ndquadrant.com, pgsql-hackers@postgresql.org
  Subject: Re: BUG #14941: Vacuum crashes
  In-Reply-To: <CBEE19BB-6C70-424C-95E5-F8ABC7AA2185@amazon.com>
  References: <CAB7nPqTyY_7rXFi_=7DX_xZad43snZvDpw-KU+SuX20euGNhbQ@mail.gmail.com> <CAD21AoBGtBXxsDECmVVHsM-d64nK2qiDhZ5_tOreBH86=h7Smw@mail.gmail.com> <AD80AE03-8A5D-40A2-99C9-C26646489E49@amazon.com> <48A02BB8-A7DE-4D11-9586-0BBE5E6FE4F3@amazon.com> <CAD21AoC9D528HBugWumq678t_GOLft-KyeGyG=VFeyKfHY4Z5A@mail.gmail.com> <32F4B778-292B-41AF-891A-497B8127CD59@amazon.com> <CAD21AoCsbqVh5P=ZA479DHrXmtUY2TxPxotE0jPiwM2+gQUjxw@mail.gmail.com> <5B80D67E-A664-495A-A0BE-CEA847676164@amazon.com> <20180109042720.GG76418@paquier.xyz> <4B232BD7-A97D-4461-81E6-28A49764B60E@amazon.com> <20180110025331.GE336@paquier.xyz> <CBEE19BB-6C70-424C-95E5-F8ABC7AA2185@amazon.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox