関数特性
言語: PLPGSQL
戻り値: integer
alterTableRestore (tab_id) 複製されることからテーブル tab_id をリストアします。 オリジンノード上でこれは単に "logtrigger" トリガーを削除する事です。 購読ノード上でこれは "denyaccess" トリガーを削除し、ユーザトリガーとルールをリストアします。declare p_tab_id alias for $1; v_no_id int4; v_tab_row record; v_tab_fqname text; v_n int4; begin -- ---- -- 中枢構成にロックを取得 -- ---- lock table sl_config_lock; -- ---- -- 自らのローカルノード識別子の取得 -- ---- v_no_id := getLocalNodeId('_schemadoc'); -- ---- -- sl_table 行と現在のテーブルオリジンノードの取得 -- テーブルは現在変更状態にあることの検査 -- ---- select T.tab_reloid, T.tab_set, T.tab_altered, S.set_origin, PGX.indexrelid, slon_quote_brute(PGN.nspname) || '.' || slon_quote_brute(PGC.relname) as tab_fqname into v_tab_row from sl_table T, sl_set S, "pg_catalog".pg_class PGC, "pg_catalog".pg_namespace PGN, "pg_catalog".pg_index PGX, "pg_catalog".pg_class PGXC where T.tab_id = p_tab_id and T.tab_set = S.set_id and T.tab_reloid = PGC.oid and PGC.relnamespace = PGN.oid and PGX.indrelid = T.tab_reloid and PGX.indexrelid = PGXC.oid and PGXC.relname = T.tab_idxname for update; if not found then raise exception 'Slony-I: Table with id % not found', p_tab_id; end if; v_tab_fqname = v_tab_row.tab_fqname; if not v_tab_row.tab_altered then raise exception 'Slony-I: Table % is not in altered state', v_tab_fqname; end if; execute 'lock table ' || v_tab_fqname || ' in access exclusive mode'; -- ---- -- オリジンノードと購読ノードでは手順が異なる -- ---- if v_no_id = v_tab_row.set_origin then -- ---- -- オリジンノードでは元で追加したトリガーを単に削除します。 -- ---- execute 'drop trigger "_schemadoc_logtrigger_' || p_tab_id || '" on ' || v_tab_fqname; else -- ---- -- 購読ノードでは denyAccess トリガーの削除 -- ---- execute 'drop trigger "_schemadoc_denyaccess_' || p_tab_id || '" on ' || v_tab_fqname; -- ---- -- 元の全てのトリガーのリストア -- ---- update "pg_catalog".pg_trigger set tgrelid = v_tab_row.tab_reloid where tgrelid = v_tab_row.indexrelid; get diagnostics v_n = row_count; if v_n > 0 then update "pg_catalog".pg_class set reltriggers = reltriggers + v_n where oid = v_tab_row.tab_reloid; end if; -- ---- -- 全ての元の書き換えルールのリストア -- ---- update "pg_catalog".pg_rewrite set ev_class = v_tab_row.tab_reloid where ev_class = v_tab_row.indexrelid; get diagnostics v_n = row_count; if v_n > 0 then update "pg_catalog".pg_class set relhasrules = true where oid = v_tab_row.tab_reloid; end if; end if; -- ---- -- この構成で変更されなかったテーブルに印を付ける -- ---- update sl_table set tab_altered = false where tab_id = p_tab_id; return p_tab_id; end;