log_truncate()

Slony-I 2.2.10 Documentation
Prev | Fast Backward | Chapter 8. Schema schemadoc | Fast Forward | Next

# 8.74. log_truncate()

Function Properties

Language: PLPGSQL

Return Type: trigger

trigger function run when a replicated table receives a TRUNCATE request

    	declare
    		r_role text;
    		c_nspname text;
    		c_relname text;
    		c_log integer;
    		c_node integer;
    		c_tabid integer;
    	begin
    		-- Ignore this call if session_replication_role = 'local'
    		select into r_role setting
    			from pg_catalog.pg_settings where name = 'session_replication_role';
    		if r_role = 'local' then
    			return NULL;
    		end if;

            c_tabid := tg_argv[0];
    	    c_node := getLocalNodeId('_schemadoc');
    		select tab_nspname, tab_relname into c_nspname, c_relname
    				  from sl_table where tab_id = c_tabid;
    		select last_value into c_log from sl_log_status;
    		if c_log in (0, 2) then
    			insert into sl_log_1 (
    					log_origin, log_txid, log_tableid,
    					log_actionseq, log_tablenspname,
    					log_tablerelname, log_cmdtype,
    					log_cmdupdncols, log_cmdargs
    				) values (
    					c_node, pg_catalog.txid_current(), c_tabid,
    					nextval('sl_action_seq'), c_nspname,
    					c_relname, 'T', 0, '{}'::text[]);
    		else   -- (1, 3)
    			insert into sl_log_2 (
    					log_origin, log_txid, log_tableid,
    					log_actionseq, log_tablenspname,
    					log_tablerelname, log_cmdtype,
    					log_cmdupdncols, log_cmdargs
    				) values (
    					c_node, pg_catalog.txid_current(), c_tabid,
    					nextval('sl_action_seq'), c_nspname,
    					c_relname, 'T', 0, '{}'::text[]);
    		end if;
    		return NULL;
        end

Prev | Home | Next
lockset(p_set_id integer) | Up | logswitch_finish()