autovacuum and reloptions

Started by Alvaro Herreraover 17 years ago36 messageshackers
Jump to latest
#1Alvaro Herrera
alvherre@2ndquadrant.com

So I gave up waiting for someone else to do the reloptions patch for
autovacuum and started work on it myself. What I soon discovered is
that on first blush it seems a lot easier than I had expected.

On second look, however, the problem is that I seem to be
forced to declare all the autovacuum-related options and their parsing
properties in reloptions.c. This seems very ugly. I'd very much prefer
to be able to declare the options in autovacuum.c and let the rest of
the code just ignore them.

However, parseRelOptions seems inclined to barf about options it doesn't
know about. Maybe that's fine with the current usage, but I think it
would be better to leave the options in StdRdOptions alone, and have the
autovacuum options defined elsewhere, which seems to require an API
change to parseRelOptions -- though I'm not sure what's appropriate.

AFAICS this is completely uncharted territory -- the current code
understands only fillfactor as a valid option. If we were down the
route of just adding the new options just like fillfactor is currently
dealt with, the API would get really ugly very quickly.

It seems to me we should provide a way to "register" valid options, so
that autovacuum.c could inform reloptions.c what are the valid keys that
a normal option parsing should just ignore (and, conversely, what
options should it ignore when parsing for autovacuum). Thinking more
about it, it seems to me that the treatment that fillfactor currently
gets should be ripped out in favor of being registered too, somehow ...

Before we waste too much time thinking how this registering is to be
done, does anybody think that the current approach is OK and thus I
should just add the autovacuum options directly into StdRdOptions and
default_reloptions?

--
Alvaro Herrera Developer, http://www.PostgreSQL.org/
"El Maquinismo fue proscrito so pena de cosquilleo hasta la muerte"
(Ijon Tichy en Viajes, Stanislaw Lem)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#1)
Re: autovacuum and reloptions

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

On second look, however, the problem is that I seem to be
forced to declare all the autovacuum-related options and their parsing
properties in reloptions.c. This seems very ugly.

That was in fact the intended design, and is why the functions exist in
a separate file reloptions.c rather than having been dumped into some
existing place like heapam.c. I don't see anything very wrong with
having autovacuum options in StdRdOptions and default_reloptions().

There might at some point be a good case for inventing a plugin approach
here, but since autovacuum is a pretty much core component now, I don't
see the need to do so for it.

regards, tom lane

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#2)
Re: autovacuum and reloptions

Tom Lane wrote:

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

On second look, however, the problem is that I seem to be
forced to declare all the autovacuum-related options and their parsing
properties in reloptions.c. This seems very ugly.

That was in fact the intended design, and is why the functions exist in
a separate file reloptions.c rather than having been dumped into some
existing place like heapam.c. I don't see anything very wrong with
having autovacuum options in StdRdOptions and default_reloptions().

Hmm, OK. However, given that the various AMs amoptions also use
default_reloptions, they are going to accept the autovacuum options too.
Is that OK?

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#3)
Re: autovacuum and reloptions

Alvaro Herrera <alvherre@commandprompt.com> writes:

Hmm, OK. However, given that the various AMs amoptions also use
default_reloptions, they are going to accept the autovacuum options too.
Is that OK?

Well, we might want to split default_reloptions into two versions,
one for heaps and the other for indexes. But it doesn't bother me a
whole lot if we don't.

regards, tom lane

#5Bruce Momjian
bruce@momjian.us
In reply to: Alvaro Herrera (#1)
Re: autovacuum and reloptions

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

Before we waste too much time thinking how this registering is to be
done, does anybody think that the current approach is OK and thus I
should just add the autovacuum options directly into StdRdOptions and
default_reloptions?

Given Simon's suggestion that i/o parameters should be per-tablespace I think
we might need to refactor this further.

I wonder if we could piggy-back on guc parameters. So you would register a guc
variable with a flag saying it's sensible to be set per-tablespace or
per-table.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's PostGIS support!

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#5)
Re: autovacuum and reloptions

Gregory Stark <stark@enterprisedb.com> writes:

I wonder if we could piggy-back on guc parameters.

God, no. GUC is hopelessly complex already, we should *not* try to make
it track different values of a parameter for different tables.

Attaching a reloptions-like column to pg_tablespace might not be
unreasonable ... but I think that has little to do with Alvaro's
immediate problem.

regards, tom lane

#7ITAGAKI Takahiro
itagaki.takahiro@oss.ntt.co.jp
In reply to: Alvaro Herrera (#1)
Re: autovacuum and reloptions

Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

So I gave up waiting for someone else to do the reloptions patch for
autovacuum and started work on it myself.

Is it needed to keep backward compatibility?

I'd like to suggest to keep pg_catalog.pg_autovacuum as a system view
even after the options is put into reloptons, and the view to be
updatable using RULEs if possible.

Current pg_autovacuum-table approach has a benefit that
we can configure options by rule, for example:

INSERT INTO pg_autovacuu SELECT ... FROM pg_class WHERE ...;

But we will not able to do that if the settings will be in reloptions
because ALTER TABLE SET cannot be used with JOINs.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: ITAGAKI Takahiro (#7)
Re: autovacuum and reloptions

ITAGAKI Takahiro <itagaki.takahiro@oss.ntt.co.jp> writes:

Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

So I gave up waiting for someone else to do the reloptions patch for
autovacuum and started work on it myself.

Is it needed to keep backward compatibility?

I'd like to suggest to keep pg_catalog.pg_autovacuum as a system view
even after the options is put into reloptons, and the view to be
updatable using RULEs if possible.

Ugh. No. It has been explicitly stated all along that pg_autovacuum
was a temporary API and that anyone depending on it could expect future
trouble.

But we will not able to do that if the settings will be in reloptions
because ALTER TABLE SET cannot be used with JOINs.

Any mechanism that a rule might use to set reloptions would be just
as usable in a join as the rule itself ...

regards, tom lane

#9Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#6)
Re: autovacuum and reloptions

Tom Lane wrote:

Gregory Stark <stark@enterprisedb.com> writes:

I wonder if we could piggy-back on guc parameters.

God, no. GUC is hopelessly complex already, we should *not* try to make
it track different values of a parameter for different tables.

Are there any more specific reasons than "it's very complex"? After
all, all the autovacuum options already exist as GUC parameters, so you
don't have to repeat all the validation code, for example.

#10Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#9)
Re: autovacuum and reloptions

Peter Eisentraut <peter_e@gmx.net> writes:

Tom Lane wrote:

God, no. GUC is hopelessly complex already, we should *not* try to make
it track different values of a parameter for different tables.

Are there any more specific reasons than "it's very complex"?

That one seems quite sufficient to me; but consider dump/restore if you
need more.

regards, tom lane

In reply to: Alvaro Herrera (#1)
Re: autovacuum and reloptions

Alvaro Herrera escreveu:

So I gave up waiting for someone else to do the reloptions patch for
autovacuum and started work on it myself. What I soon discovered is
that on first blush it seems a lot easier than I had expected.

Sorry about that. :( I was swamped with PGCon Brasil and then I took
some days to rest. I'm expecting to finish it before next CF.

What did I already do? I refactored reloptions.c to support multiple
options. I tried to follow up the same way GUC do (of course, it is much
simpler). I'm thinking about removing (replacing?) StdRdOptions 'cause
we need a different struct to store reloptions. Suggestions?

I'm attaching the WIP patch so you can comment on it. I want to continue
working on it but I'm afraid you already did more than I do (in this
case, let me know for not duplicating efforts).

--
Euler Taveira de Oliveira
http://www.timbira.com/

Attachments:

relopt5.difftext/plain; name=relopt5.diffDownload+442-96
#12Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira de Oliveira (#11)
Re: autovacuum and reloptions

Euler Taveira de Oliveira wrote:

What did I already do? I refactored reloptions.c to support multiple
options. I tried to follow up the same way GUC do (of course, it is much
simpler). I'm thinking about removing (replacing?) StdRdOptions 'cause
we need a different struct to store reloptions. Suggestions?

I'm attaching the WIP patch so you can comment on it. I want to continue
working on it but I'm afraid you already did more than I do (in this
case, let me know for not duplicating efforts).

Interesting. The main problem with this patch is that it loses the
ability to pass to parseRelOptions the set of options that are valid for
each context. Right now all callers use the same list comprising only
fillfactor, but my guess is that once we add new options it will make
sense to start differentiating. It makes no sense for indexes to have
autovacuum options, for example.

This is why I suggested in the email that started this thread we needed
some sort of registering capability (which was thrown down). I think
the main idea in your patch is fine, and better than what I was doing
which was just adding every option in default_reloptions. However it
needs to be adjusted somehow so that it doesn't mix all the options.
Maybe we could add a "category" bitmask for which each option would be
valid.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

In reply to: Alvaro Herrera (#12)
Re: autovacuum and reloptions

Alvaro Herrera escreveu:

Maybe we could add a "category" bitmask for which each option would be
valid.

The category tests are fine, that's why I introduced relopt_gen.kind but
I'm not using it yet. I'll try to refactor it to use bitmask (some
options could be used to both -- fillfactor) and to add it in the
validation code.

--
Euler Taveira de Oliveira
http://www.timbira.com/

#14Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira de Oliveira (#13)
Re: autovacuum and reloptions

Euler Taveira de Oliveira wrote:

Alvaro Herrera escreveu:

Maybe we could add a "category" bitmask for which each option would be
valid.

The category tests are fine, that's why I introduced relopt_gen.kind but
I'm not using it yet.

Ah, right, I hadn't noticed the kind stuff, maybe because it's unused
;-)

I'll try to refactor it to use bitmask (some options could be used to
both -- fillfactor) and to add it in the validation code.

Right, that's why I suggested using a bitmask.

Okay, so I'll let you deal with this for a while yet. A minor
suggestion: label the enum members distinctively, i.e. instead of
RO_BOOL perhaps use RELOPT_TYPE_BOOL, and RO_HEAP should be
RELOPT_KIND_HEAP (note this cannot be a plain enum, each category needs
a separate bit).

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#14)
Re: autovacuum and reloptions

Alvaro Herrera <alvherre@commandprompt.com> writes:

Okay, so I'll let you deal with this for a while yet. A minor
suggestion: label the enum members distinctively, i.e. instead of
RO_BOOL perhaps use RELOPT_TYPE_BOOL, and RO_HEAP should be
RELOPT_KIND_HEAP (note this cannot be a plain enum, each category needs
a separate bit).

My first reaction was that the categories should just be the different
possible values of relkind. However, it also seems possible that there
could be index-AM-specific reloptions. So maybe what we need is a
categorization that is like relkind but breaks down RELKIND_INDEX into a
category per AM.

regards, tom lane

#16Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira de Oliveira (#11)
Re: autovacuum and reloptions

Euler Taveira de Oliveira wrote:

Alvaro Herrera escreveu:

So I gave up waiting for someone else to do the reloptions patch for
autovacuum and started work on it myself. What I soon discovered is
that on first blush it seems a lot easier than I had expected.

Sorry about that. :( I was swamped with PGCon Brasil and then I took
some days to rest. I'm expecting to finish it before next CF.

So did this go anywhere?

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

#17ITAGAKI Takahiro
itagaki.takahiro@oss.ntt.co.jp
In reply to: Alvaro Herrera (#12)
Re: autovacuum and reloptions

I have a comment about reloptions of autovacuum parameters:
I'd like to have an easier way to extract individual parameters.

Alvaro Herrera <alvherre@commandprompt.com> wrote:

Euler Taveira de Oliveira wrote:

What did I already do? I refactored reloptions.c to support multiple
options. I tried to follow up the same way GUC do (of course, it is much
simpler). I'm thinking about removing (replacing?) StdRdOptions 'cause
we need a different struct to store reloptions. Suggestions?

Interesting.

We store reloptions as an array of 'key=value' text, but there is
no official way to read each parameter. I always create an user
defined function to extract fillfactors, but it would be better
if we have a standard method to do that.

---- [brute force way]
CREATE FUNCTION pg_fillfactor(reloptions text[], relam OID)
RETURNS integer AS
$$
SELECT (regexp_matches(array_to_string($1, '/'),
'fillfactor=([0-9]+)'))[1]::integer AS fillfactor
UNION ALL
SELECT CASE $2
WHEN 0 THEN 100 -- heap
WHEN 403 THEN 90 -- btree
WHEN 405 THEN 70 -- hash
WHEN 783 THEN 90 -- gist
WHEN 2742 THEN 100 -- gin
END
LIMIT 1;
$$
LANGUAGE sql STABLE;
----

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

In reply to: ITAGAKI Takahiro (#17)
Re: autovacuum and reloptions

ITAGAKI Takahiro escreveu:

[Sorry for the delay. I'm preparing the final patch and in a day or so
I'll post it.]

I have a comment about reloptions of autovacuum parameters:
I'd like to have an easier way to extract individual parameters.

Alvaro Herrera <alvherre@commandprompt.com> wrote:

Euler Taveira de Oliveira wrote:

What did I already do? I refactored reloptions.c to support multiple
options. I tried to follow up the same way GUC do (of course, it is much
simpler). I'm thinking about removing (replacing?) StdRdOptions 'cause
we need a different struct to store reloptions. Suggestions?

Interesting.

We store reloptions as an array of 'key=value' text, but there is
no official way to read each parameter. I always create an user
defined function to extract fillfactors, but it would be better
if we have a standard method to do that.

We will have an official function (getRelOptions()?) to extract the
reloption (autovacuum) parameters because we need to transform
pg_autovacuum catalog table in a view to maintain backward compatibility.

--
Euler Taveira de Oliveira
http://www.timbira.com/

#19Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira de Oliveira (#18)
Re: autovacuum and reloptions

Euler Taveira de Oliveira wrote:

We will have an official function (getRelOptions()?) to extract the
reloption (autovacuum) parameters because we need to transform
pg_autovacuum catalog table in a view to maintain backward compatibility.

Why? I'd say don't waste your time. If anything, it can be done after
the initial patch has been committed.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

#20ITAGAKI Takahiro
itagaki.takahiro@oss.ntt.co.jp
In reply to: Euler Taveira de Oliveira (#18)
Re: autovacuum and reloptions

Euler Taveira de Oliveira <euler@timbira.com> wrote:

We will have an official function (getRelOptions()?) to extract the
reloption (autovacuum) parameters

Yeah, I want it, but...

because we need to transform
pg_autovacuum catalog table in a view to maintain backward compatibility.

I don't think we need pg_autovacuum in 8.4 because it is a deprecated API.
However, we should provide some easier methods to create an user-defined
pg_autovacuum view in case that users really need it.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

In reply to: Euler Taveira de Oliveira (#18)
#22Robert Haas
robertmhaas@gmail.com
In reply to: Euler Taveira de Oliveira (#21)
In reply to: Robert Haas (#22)
#24Robert Haas
robertmhaas@gmail.com
In reply to: Euler Taveira de Oliveira (#23)
#25Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Robert Haas (#24)
#26Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#25)
In reply to: Alvaro Herrera (#26)
#28Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira de Oliveira (#27)
#29Peter Eisentraut
peter_e@gmx.net
In reply to: Alvaro Herrera (#28)
#30Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#28)
#31Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#30)
#32Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#30)
In reply to: Alvaro Herrera (#32)
#34Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Euler Taveira de Oliveira (#33)
In reply to: Alvaro Herrera (#34)
#36Jaime Casanova
jcasanov@systemguards.com.ec
In reply to: Euler Taveira de Oliveira (#35)