Discussion:
PG_REORG ISSUE
(too old to reply)
suhas.basavaraj12
2012-11-28 05:37:05 UTC
Permalink
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.
I did \d affected_table , but that trigger was not there on that table .But
when i searched in schema i found below trigger

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


Rgrds
Suhas





--
View this message in context: http://postgresql.1045698.n5.nabble.com/PG-REORG-ISSUE-tp5733850.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Josh Kupershmidt
2012-11-30 00:35:10 UTC
Permalink
This thread belongs on the pg_reorg mailing list, so I am moving it there.
Post by suhas.basavaraj12
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.
Post by suhas.basavaraj12
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.
Post by suhas.basavaraj12
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
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Loading...