Chris Browne cbbrowne at lists.slony.info
Thu Feb 8 10:01:17 PST 2007
Update of /home/cvsd/slony1/slony1-engine/src/backend
In directory main:/tmp/cvs-serv9746/src/backend

Modified Files:
	Makefile slony1_funcs.sql slony1_funcs.v74.sql 
	slony1_funcs.v80.sql 
Added Files:
	slony1_base.v81.sql slony1_funcs.v81.sql 
Log Message:
- Makefiles and slonik.c now support '.v81.sql' files

- Fix to generate_sync_event(); quoting was wrong

- Add in function to UPDATE FUNCTIONS that makes xxidin() function
  become STRICT, as needed in PostgreSQL 8.2


Index: slony1_funcs.sql
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_funcs.sql,v
retrieving revision 1.103
retrieving revision 1.104
diff -C2 -d -r1.103 -r1.104
*** slony1_funcs.sql	15 Dec 2006 05:34:18 -0000	1.103
--- slony1_funcs.sql	8 Feb 2007 18:01:15 -0000	1.104
***************
*** 5219,5227 ****
  BEGIN
  	select 1 into v_node_row from @NAMESPACE at .sl_event 
!        	  where ev_type = ''SYNC'' and ev_origin = @NAMESPACE at .getLocalNodeId(''@NAMESPACE@'')
            and ev_timestamp > now() - p_interval limit 1;
  	if not found then
  		-- If there has been no SYNC in the last interval, then push one
! 		perform @NAMESPACE at .createEvent(''@NAMESPACE@'', ''SYNC'', NULL);
  		return 1;
  	else
--- 5219,5227 ----
  BEGIN
  	select 1 into v_node_row from @NAMESPACE at .sl_event 
!        	  where ev_type = ''SYNC'' and ev_origin = @NAMESPACE at .getLocalNodeId(''_ at CLUSTERNAME@'')
            and ev_timestamp > now() - p_interval limit 1;
  	if not found then
  		-- If there has been no SYNC in the last interval, then push one
! 		perform @NAMESPACE at .createEvent(''_ at CLUSTERNAME@'', ''SYNC'', NULL);
  		return 1;
  	else
***************
*** 5830,5833 ****
--- 5830,5835 ----
  	end if;
  
+ 	-- In any version, make sure that the xxidin() functions are defined as STRICT
+ 	perform @NAMESPACE at .make_function_strict (''xxidin'', ''(cstring)'');
  	return p_old;
  end;

Index: Makefile
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/backend/Makefile,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** Makefile	2 Aug 2006 15:32:02 -0000	1.22
--- Makefile	8 Feb 2007 18:01:15 -0000	1.23
***************
*** 31,34 ****
--- 31,37 ----
  FUNCS_80		= slony1_funcs.v80.sql
  
+ BASE_81			= slony1_base.v81.sql
+ FUNCS_81		= slony1_funcs.v81.sql
+ 
  SQL_NAMES =				\
  	$(BASE_COMMON)		\
***************
*** 39,43 ****
  	$(FUNCS_74)			\
  	$(BASE_80)			\
! 	$(FUNCS_80)
  
  DISTFILES = Makefile README README.events $(wildcard *.sql) $(wildcard *.in) $(wildcard *.c)
--- 42,48 ----
  	$(FUNCS_74)			\
  	$(BASE_80)			\
! 	$(FUNCS_80)			\
! 	$(BASE_81)			\
! 	$(FUNCS_81)
  
  DISTFILES = Makefile README README.events $(wildcard *.sql) $(wildcard *.in) $(wildcard *.c)

Index: slony1_funcs.v80.sql
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_funcs.v80.sql,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** slony1_funcs.v80.sql	5 Dec 2006 18:07:24 -0000	1.3
--- slony1_funcs.v80.sql	8 Feb 2007 18:01:15 -0000	1.4
***************
*** 115,116 ****
--- 115,125 ----
  'Returns 1/0 based on whether or not the DB is running a
  version earlier than 7.4';
+ 
+ create or replace function @NAMESPACE at .make_function_strict (text, text) returns void as
+ '
+    update "pg_catalog"."pg_proc" set proisstrict = ''t'' where 
+      proname = $1 and pronamespace = (select oid from "pg_catalog"."pg_namespace" where nspname = '@NAMESPACE@') and prolang = (select oid from "pg_catalog"."pg_language" where lanname = ''c'');
+ ' language sql;
+ 
+ comment on function @NAMESPACE at .make_function_strict (text, text) is
+ 'Equivalent to 8.1+ ALTER FUNCTION ... STRICT';
\ No newline at end of file

Index: slony1_funcs.v74.sql
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/src/backend/slony1_funcs.v74.sql,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** slony1_funcs.v74.sql	11 Nov 2005 13:53:24 -0000	1.8
--- slony1_funcs.v74.sql	8 Feb 2007 18:01:15 -0000	1.9
***************
*** 103,104 ****
--- 103,113 ----
  'Returns 1 or 0 based on whether or not the DB is running a
  version earlier than 7.4';
+ 
+ create or replace function @NAMESPACE at .make_function_strict (text, text) returns void as
+ '
+    update "pg_catalog"."pg_proc" set proisstrict = ''t'' where 
+      proname = $1 and pronamespace = (select oid from "pg_catalog"."pg_namespace" where nspname = '@NAMESPACE@') and prolang = (select oid from "pg_catalog"."pg_language" where lanname = ''c'');
+ ' language sql;
+ 
+ comment on function @NAMESPACE at .make_function_strict (text, text) is
+ 'Equivalent to 8.1+ ALTER FUNCTION ... STRICT';
\ No newline at end of file

--- NEW FILE: slony1_base.v81.sql ---
-- ----------------------------------------------------------------------
-- slony1_base.v81.sql
--
--    Version 8.1 specific parts of the basic replication schema.
--
--	Copyright (c) 2003-2004, PostgreSQL Global Development Group
--	Author: Jan Wieck, Afilias USA INC.
--
-- $Id: slony1_base.v81.sql,v 1.1 2007-02-08 18:01:15 cbbrowne Exp $
-- ----------------------------------------------------------------------



--- NEW FILE: slony1_funcs.v81.sql ---
-- ----------------------------------------------------------------------
-- slony1_funcs.v81.sql
--
--    Version 8.1 specific part of the replication support functions.
--
--	Copyright (c) 2003-2004, PostgreSQL Global Development Group
--	Author: Jan Wieck, Afilias USA INC.
--
-- $Id: slony1_funcs.v81.sql,v 1.1 2007-02-08 18:01:15 cbbrowne Exp $
-- ----------------------------------------------------------------------

-- ----------------------------------------------------------------------
-- FUNCTION prepareTableForCopy(tab_id)
--
--	Remove all content from a table before the subscription
--	content is loaded via COPY and disable index maintenance.
-- ----------------------------------------------------------------------
create or replace function @NAMESPACE at .prepareTableForCopy(int4)
returns int4
as '
declare
	p_tab_id		alias for $1;
	v_tab_oid		oid;
	v_tab_fqname	text;
begin
	-- ----
	-- Get the OID and fully qualified name for the table
	-- ---
	select	PGC.oid,
			@NAMESPACE at .slon_quote_brute(PGN.nspname) || ''.'' ||
			@NAMESPACE at .slon_quote_brute(PGC.relname) as tab_fqname
		into v_tab_oid, v_tab_fqname
			from @NAMESPACE at .sl_table T,   
				"pg_catalog".pg_class PGC, "pg_catalog".pg_namespace PGN
				where T.tab_id = p_tab_id
				and T.tab_reloid = PGC.oid
				and PGC.relnamespace = PGN.oid;
	if not found then
		raise exception ''Table with ID % not found in sl_table'', p_tab_id;
	end if;

	-- ----
	-- Setting pg_class.relhasindex to false will cause copy not to
	-- maintain any indexes. At the end of the copy we will reenable
	-- them and reindex the table. This bulk creating of indexes is
	-- faster.
	-- ----
	update pg_class set relhasindex = ''f'' where oid = v_tab_oid;

	-- ----
	-- Try using truncate to empty the table and fallback to
	-- delete on error.
	-- ----
	execute ''truncate '' || @NAMESPACE at .slon_quote_input(v_tab_fqname);
	raise notice ''truncate of % succeeded'', v_tab_fqname;
	return 1;
	exception when others then
		raise notice ''truncate of % failed - doing delete'', v_tab_fqname;
		update pg_class set relhasindex = ''f'' where oid = v_tab_oid;
		execute ''delete from only '' || @NAMESPACE at .slon_quote_input(v_tab_fqname);
		return 0;
end;
' language plpgsql;

comment on function @NAMESPACE at .prepareTableForCopy(int4) is
'Delete all data and suppress index maintenance';

-- ----------------------------------------------------------------------
-- FUNCTION finishTableAfterCopy(tab_id)
--
--	Reenable index maintenance and reindex the table after COPY.
-- ----------------------------------------------------------------------
create or replace function @NAMESPACE at .finishTableAfterCopy(int4)
returns int4
as '
declare
	p_tab_id		alias for $1;
	v_tab_oid		oid;
	v_tab_fqname	text;
begin
	-- ----
	-- Get the tables OID and fully qualified name
	-- ---
	select	PGC.oid,
			@NAMESPACE at .slon_quote_brute(PGN.nspname) || ''.'' ||
			@NAMESPACE at .slon_quote_brute(PGC.relname) as tab_fqname
		into v_tab_oid, v_tab_fqname
			from @NAMESPACE at .sl_table T,   
				"pg_catalog".pg_class PGC, "pg_catalog".pg_namespace PGN
				where T.tab_id = p_tab_id
				and T.tab_reloid = PGC.oid
				and PGC.relnamespace = PGN.oid;
	if not found then
		raise exception ''Table with ID % not found in sl_table'', p_tab_id;
	end if;

	-- ----
	-- Reenable indexes and reindex the table.
	-- ----
	update pg_class set relhasindex = ''t'' where oid = v_tab_oid;
	execute ''reindex table '' || @NAMESPACE at .slon_quote_input(v_tab_fqname);

	return 1;
end;
' language plpgsql;

comment on function @NAMESPACE at .finishTableAfterCopy(int4) is
'Reenable index maintenance and reindex the table';

create or replace function @NAMESPACE at .pre74()
returns integer
as 'select 0' language sql;

comment on function @NAMESPACE at .pre74() is 
'Returns 1/0 based on whether or not the DB is running a
version earlier than 7.4';

create or replace function @NAMESPACE at .make_function_strict (text, text) returns void as
'
declare
   fun alias for $1;
   parms alias for $2;
   stmt text;
begin
   stmt := ''ALTER FUNCTION "_ at CLUSTERNAME@".'' || fun || '' '' || parms || '' STRICT;'';
   execute stmt;
   return;
end
' language plpgsql;

comment on function @NAMESPACE at .make_function_strict (text, text) is
'Equivalent to 8.1+ ALTER FUNCTION ... STRICT';




More information about the Slony1-commit mailing list