Unix Technical Forum

Passing on a q ... Alter schema

This is a discussion on Passing on a q ... Alter schema within the pgsql Novice forums, part of the PostgreSQL category; --> Someone (a new subscriber) asked me to pass this question on. Taking awhile to get through Moderation. I believe ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 11:51 PM
Mike Ellsworth
 
Posts: n/a
Default Passing on a q ... Alter schema

Someone (a new subscriber) asked me to pass this question on. Taking
awhile to get through Moderation. I believe it's been several hours.

"Can anyone help me please ?? I would like to get
the execution of each the statement in the LOOP ( in the function
change_owner() below) each in its own transaction.

the construction like the following errors out with
ERROR: syntax error at or near "LOOP"

LOOP
BEGIN;
PERFORM change_schema_owner( sch_rec.nspname );
COMMIT;
END LOOP;

getting the same errors when I tried to start the transaction into the function
change_schema_owner()
tried something similar to
BEGIN
BEGIN;
EXECUTE 'ALTER SCHEMA ' ||sch_name || ' OWNER TO new_role' ;
COMMIT;
RETURN ;
END;

called SET TRANSACTION ISOLATION LEVEL SERIALIZABLE before the calls ..
but looks like all the LOOP calls are bieng done in one transaction since I am
getting an error like :

ERROR: out of shared memory
HINT: You may need to increase max_locks_per_transaction.
CONTEXT: SQL statement "ALTER TABLE "test"."test_ages" OWNER TO "test""
PL/pgSQL function "change_schema_owner" line 24 at execute statement



-- functions I am using for that

CREATE OR REPLACE FUNCTION owner_migration()
...
$BODY$
DECLARE
sch_rec RECORD;
BEGIN
FOR sch_rec IN SELECT * FROM pg_catalog.pg_namespace
LEFT JOIN pg_catalog.pg_user ON
pg_user.usesysid=pg_namespace.nspowner
WHERE pg_user.usename = 'test'
LOOP
PERFORM change_schema_owner( sch_rec.nspname );
END LOOP;
RETURN ;
END;

CREATE OR REPLACE FUNCTION change_schema_owner(sch_name character varying)
....
....
BEGIN
-- here I would like to have a transaction and commit it on return
EXECUTE 'ALTER SCHEMA ' ||sch_name || ' OWNER TO new_role' ;
{ statements to change owner for all the objects in the schema }

RETURN ;
END;"

Thanks for any help

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:04 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com