repair_log_triggers(only_locked boolean)

6.92. repair_log_triggers(only_locked boolean)

Function Properties

Language: PLPGSQL

Return Type: integer

repair the log triggers as required. If only_locked is true then only tables that are already exclusivly locked by the current transaction are repaired. Otherwise all replicated tables with outdated trigger arguments are recreated.

declare
	retval integer;
	table_row record;
begin
	retval=0;
	for table_row in	
		select  tab_nspname,tab_relname,
				tab_idxname, tab_id, mode,
				determineAttKindUnique(tab_nspname||
					'.'||tab_relname,tab_idxname) as attkind
		from
				sl_table
				left join 
				pg_locks on (relation=tab_reloid and pid=pg_backend_pid()
				and mode='AccessExclusiveLock')				
				,pg_trigger
		where tab_reloid=tgrelid and 
		determineAttKindUnique(tab_nspname||'.'
						||tab_relname,tab_idxname)
			!=(decode_tgargs(tgargs))[2]
			and tgname =  '_schemadoc'
			|| '_logtrigger'
		LOOP
				if (only_locked=false) or table_row.mode='AccessExclusiveLock' then
					 perform recreate_log_trigger
					 		 (table_row.tab_nspname||'.'||table_row.tab_relname,
							 table_row.tab_id,table_row.attkind);
					retval=retval+1;
				else 
					 raise notice '%.% has an invalid configuration on the log trigger. This was not corrected because only_lock is true and the table is not locked.',
					 table_row.tab_nspname,table_row.tab_relname;
			
				end if;
		end loop;
	return retval;
end