ddlscript_prepare(integer, integer)

6.43. ddlscript_prepare(integer, integer)

Function Properties

Language: PLPGSQL

Return Type: integer

Prepare for DDL script execution on origin

declare
	p_set_id			alias for $1;
	p_only_on_node		alias for $2;
	v_set_origin		int4;
begin
	-- ----
	-- Grab the central configuration lock
	-- ----
	lock table sl_config_lock;

	-- ----
	-- Check that the set exists and originates here
	-- ----
	select set_origin into v_set_origin
			from sl_set
			where set_id = p_set_id
			for update;
	if not found then
		raise exception 'Slony-I: set % not found', p_set_id;
	end if;
	if p_only_on_node = -1 then
		if v_set_origin <> getLocalNodeId('_schemadoc') then
			raise exception 'Slony-I: set % does not originate on local node',
				p_set_id;
		end if;
		-- ----
		-- Create a SYNC event
		-- ----
		perform createEvent('_schemadoc', 'SYNC', NULL);
	else
		-- If running "ONLY ON NODE", there are two possibilities:
		-- 1.  Running on origin, where denyaccess() triggers are already shut off
		-- 2.  Running on replica, where we need the LOCAL role to suppress denyaccess() triggers
		execute 'create temp table _slony1_saved_session_replication_role (
					setting text);';
		execute 'insert into _slony1_saved_session_replication_role
					select setting from pg_catalog.pg_settings
					where name = ''session_replication_role'';';
		if (v_set_origin <> getLocalNodeId('_schemadoc')) then
			execute 'set session_replication_role to local;';
		end if;
	end if;
	return 1;
end;