This thread belongs on the pg_reorg mailing list, so I am moving it there.
On Tue, Nov 27, 2012 at 10:37 PM, suhas.basavaraj12 <suhas.b@verse.in> wrote:
> Hi,
>
> Found a peculiar issue with reorg_trigger on one of the important table
> in the db.
>
> SELECT>ERROR: must be superuser to use reorg_trigger function.
> Due to this , table was not accessible by application and all the stored
> procedures which run on that table failed.
Well, that error message comes from the must_be_superuser() check
failing inside the reorg_trigger() function. I am wondering how you
got into this state: in order to have installed the pg_reorg.sql
package, you must have been a superuser. Did you manually change the
owner of the reorg.reorg_trigger() function to a non-superuser? Or
perhaps the user you used to load pg_reorg.sql into your database
*was* a superuser at the time, but is no longer? You can check with: \df+ reorg.reorg_trigger()
and then check whether the owner of that function is in fact a superuser.
> I did \d affected_table , but that trigger was not there on that table .But
> when i searched in schema i found below trigger
Do you still get the error when you insert a row into
"affected_table"? If not, and you don't see the z_reorg_trigger on
your "affected_table", I guess pg_reorg bailed out during processing
this table and dropped the trigger as part of its cleanup.
> CREATE FUNCTION conflicted_triggers(oid) RETURNS SETOF name
> LANGUAGE sql STABLE STRICT
> AS $_$
> SELECT tgname FROM pg_trigger
> WHERE tgrelid = $1 AND tgname >= 'z_reorg_trigger'
> $_$;
>
> CREATE FUNCTION get_create_trigger(relid oid, pkid oid) RETURNS text
> LANGUAGE sql STABLE STRICT
> AS $_$
> SELECT 'CREATE TRIGGER z_reorg_trigger' ||
> ' BEFORE INSERT OR DELETE OR UPDATE ON ' || reorg.oid2text($1) ||
> ' FOR EACH ROW EXECUTE PROCEDURE reorg.reorg_trigger(' ||
> '''INSERT INTO reorg.log_' || $1 || '(pk, row) VALUES(' ||
> ' CASE WHEN $1 IS NULL THEN NULL ELSE (ROW($1.' ||
> reorg.get_index_columns($2, ', $1.') || ')::reorg.pk_' ||
> $1 || ') END, $2)'')';
> $_$;
>
>
> CREATE TRIGGER z_reorg_trigger BEFORE INSERT OR DELETE OR UPDATE ON
> AFFECTED_TABLE
> FOR EACH ROW EXECUTE PROCEDURE reorg.reorg_trigger('INSERT INTO
> reorg.log_16793623(pk, row)
> VALUES( CASE WHEN $1 IS NULL THEN NULL ELSE
> (ROW($1.sequence_id)::reorg.pk_16793623) END, $2)');
>
> CREATE FUNCTION reorg_trigger() RETURNS trigger
> LANGUAGE c STRICT SECURITY DEFINER
> AS '$libdir/pg_reorg', 'reorg_trigger';
>
> when i checked this belonged to pg_reorg, but i do not understand why this
> error was coming
What do you mean "this belonged to pg_reorg" -- you mean the owner of
the reorg_trigger() function is pg_reorg? As noted above, the owner of
this function must be a superuser, as should be the case when you
install pg_reorg.sql into your database.
(Side note not actually related to this problem: we should really add
a check like must_be_superuser() in the client binary, so that the
client errors out right away if it is not connected as a superuser.
Otherwise, it may plow through the trigger initialization and other
steps depending on what exact permissions the user has.)
Josh