Re: sql_drop Event Triggerg

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: sql_drop Event Triggerg
Date: 2013-03-15 17:01:37
Message-ID: 20130315170137.GA3719@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera escribió:

> > I am inclined to think that putting this logic in ProcessUtility isn't
> > scalable, even for CREATE, and even moreso for ALTER, unless we can
> > put it around everything in that function, rather than each command
> > individually. Suppose for example that on entry to that function we
> > simply did this:
> >
> > if (isCompleteQuery)
> > ++CompleteQueryNestingLevel;
> >
> > ...and at exit, we did the reverse. This could work a bit like the
> > GUC nesting level.
>
> Hmm, this seems an interesting idea to explore.

Okay, here's a patch implementing the spirit of this idea. We don't
keep track of a nesting level per se; I tried that approach and it
seemed a dead end. Instead I created a pair of macros that are pretty
much the same as UTILITY_BEGIN_DROP, except that they enclose the whole
of ProcessUtility instead of individual commands. These macros set up a
context for event_trigger.c to record affected actions/objects.
Currently this only keeps track of dropped objects (which is what this
particular patch is all about), but it appears reasonably simple to
extend to objects created, and subcommands of ALTER.

I have also modified the return type of
pg_event_trigger_dropped_objects, so that instead of object name it
returns object identity (as well as object type and schema name). For
example, for functions the identity is the signature; for tables, it's
the name. Each object type has its own format, modelled after the
COMMENT syntax (some object types don't have COMMENT support, so I had
to come up with some. This might need further discussion to arrive at
the best possible rendering for each object class). I had to add a
nearly-duplicate of getObjectDescription for this, which needs a bit
more work yet so that it doesn't schema-qualify the object names even
when not in path (most objects are not qualified, but I think operators
and types still are.)

(There's no SQL-callable function to get the object identity, such as
what we have as pg_describe_object. Not sure how important this is.)

Also, we need to ensure that unsupported object types such as
pg_default_acl rows are not reported. I have not tested this yet.
Supposedly this is part of a future patch that will encompass all DCL
commands (grant, revoke, create/drop roles, etc).

This patch also adds event trigger support for DROP OWNED (a two-line
change).

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachment Content-Type Size
dropped_objects.8.patch text/x-diff 63.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-03-15 17:53:40 Re: Strange Windows problem, lock_timeout test request
Previous Message Tom Lane 2013-03-15 16:27:54 Re: buffer assertion tripping under repeat pgbench load