Addressing autovacuum change in PostgreSQL 8.4
authorChristopher Browne <cbbrowne@ca.afilias.info>
Tue, 21 Jul 2009 21:15:51 +0000 (21:15 +0000)
committerChristopher Browne <cbbrowne@ca.afilias.info>
Tue, 21 Jul 2009 21:15:51 +0000 (21:15 +0000)
1.  Need to have v84.sql files

2.  Need for slonik to install v84.sql files, when apropos

3.  v84.sql functions file implements alternative implementation
    which pulls the attribute from pg_class rather than the former
    pg_autovacuum table

src/backend/Makefile
src/backend/slony1_base.sql
src/backend/slony1_base.v83.sql
src/backend/slony1_base.v84.sql [new file with mode: 0644]
src/backend/slony1_funcs.sql
src/backend/slony1_funcs.v84.sql [new file with mode: 0644]
src/slon/dbutils.c
src/slonik/slonik.c

index 490955aae1d41fa07916a150d264d06ef034c8eb..7d27e189238485bf37970a62be9d07348675c8cd 100644 (file)
@@ -4,7 +4,7 @@
 #      Copyright (c) 2003-2004, PostgreSQL Global Development Group
 #      Author: Jan Wieck, Afilias USA INC.
 #
-#      $Id: Makefile,v 1.26 2007-06-07 13:01:10 wieck Exp $
+#      $Id: Makefile,v 1.26.2.1 2009-07-21 21:15:51 cbbrowne Exp $
 # ----------
 
 slony_subdir = src/backend
@@ -24,12 +24,16 @@ FUNCS_COMMON        = slony1_funcs.sql
 
 BASE_83                        = slony1_base.v83.sql
 FUNCS_83               = slony1_funcs.v83.sql
+BASE_84                        = slony1_base.v84.sql
+FUNCS_84               = slony1_funcs.v84.sql
 
 SQL_NAMES =                            \
        $(BASE_COMMON)          \
        $(FUNCS_COMMON)         \
        $(BASE_83)                      \
-       $(FUNCS_83)
+       $(BASE_84)                      \
+       $(FUNCS_83)                     \
+       $(FUNCS_84)
 
 DISTFILES = Makefile README README.events $(wildcard *.sql) $(wildcard *.in) $(wildcard *.c)
 
index f2c6b0377065f5ffea3011082ea32d41b78e003c..9a4a39d490f633169f3d2bd6e9f8a6f7c4d97d01 100644 (file)
@@ -6,7 +6,7 @@
 --     Copyright (c) 2003-2004, PostgreSQL Global Development Group
 --     Author: Jan Wieck, Afilias USA INC.
 --
--- $Id: slony1_base.sql,v 1.40.2.1 2009-02-23 17:23:55 cbbrowne Exp $
+-- $Id: slony1_base.sql,v 1.40.2.2 2009-07-21 21:15:51 cbbrowne Exp $
 -- ----------------------------------------------------------------------
 
 
@@ -469,6 +469,7 @@ comment on sequence @NAMESPACE@.sl_local_node_id is 'The local node ID is initia
 -- ----------------------------------------------------------------------
 create sequence @NAMESPACE@.sl_event_seq;
 comment on sequence @NAMESPACE@.sl_event_seq is 'The sequence for numbering events originating from this node.';
+select setval('@NAMESPACE@.sl_event_seq', 5000000000);
 
 -- ----------------------------------------------------------------------
 -- SEQUENCE sl_action_seq
@@ -533,10 +534,6 @@ comment on table @NAMESPACE@.sl_config_lock is 'This table exists solely to prev
 ';
 comment on column @NAMESPACE@.sl_config_lock.dummy is 'No data ever goes in this table so the contents never matter.  Indeed, this column does not really need to exist.';
 
-create type @NAMESPACE@.vactables as (nspname name, relname name);
-
-comment on type @NAMESPACE@.vactables is 'used as return type for SRF function TablesToVacuum';
-
 -- ----------------------------------------------------------------------
 -- TABLE sl_archive_counter
 --
index ed3ff4ba467127be0d5290b0cd2ae1791c821223..fa465ea6c7497cb53b67b612c2733a5a1f12b84d 100644 (file)
@@ -6,7 +6,11 @@
 --     Copyright (c) 2007, PostgreSQL Global Development Group
 --     Author: Jan Wieck, Afilias USA INC.
 --
--- $Id: slony1_base.v83.sql,v 1.1 2007-05-31 18:55:28 wieck Exp $
+-- $Id: slony1_base.v83.sql,v 1.1.2.1 2009-07-21 21:15:51 cbbrowne Exp $
 -- ----------------------------------------------------------------------
 
+create type @NAMESPACE@.vactables as (nspname name, relname name);
+
+comment on type @NAMESPACE@.vactables is 'used as return type for SRF function TablesToVacuum';
+
 
diff --git a/src/backend/slony1_base.v84.sql b/src/backend/slony1_base.v84.sql
new file mode 100644 (file)
index 0000000..47b46fe
--- /dev/null
@@ -0,0 +1,16 @@
+-- ----------------------------------------------------------------------
+-- slony1_base.v83.sql
+--
+--    Version 8.3 specific parts of the basic replication schema.
+--
+--     Copyright (c) 2007, PostgreSQL Global Development Group
+--     Author: Jan Wieck, Afilias USA INC.
+--
+-- $Id: slony1_base.v84.sql,v 1.1.2.1 2009-07-21 21:15:51 cbbrowne Exp $
+-- ----------------------------------------------------------------------
+
+create type @NAMESPACE@.vactables as (nspname name, relname name);
+
+comment on type @NAMESPACE@.vactables is 'used as return type for SRF function TablesToVacuum';
+
+
index 8d14202ded0842a8cd0184a696b5dc06614b4573..709e7a53e654481f9919063dcb7ff893a753348b 100644 (file)
@@ -6,7 +6,7 @@
 --     Copyright (c) 2003-2007, PostgreSQL Global Development Group
 --     Author: Jan Wieck, Afilias USA INC.
 --
--- $Id: slony1_funcs.sql,v 1.145.2.12 2009-07-14 19:09:00 cbbrowne Exp $
+-- $Id: slony1_funcs.sql,v 1.145.2.13 2009-07-21 21:15:51 cbbrowne Exp $
 -- ----------------------------------------------------------------------
 
 -- **********************************************************************
@@ -5619,56 +5619,6 @@ $$ language plpgsql;
 comment on function @NAMESPACE@.finishTableAfterCopy(int4) is
 'Reenable index maintenance and reindex the table';
 
-
--- ----------------------------------------------------------------------
--- FUNCTION ShouldSlonyVacuumTable (nspname, tabname)
---
---     Returns 't' if the table needs to be vacuumed by Slony-I
---      Returns 'f' if autovac handles the table, so Slony-I should not
---                  or if the table is not needful altogether
--- ----------------------------------------------------------------------
-create or replace function @NAMESPACE@.ShouldSlonyVacuumTable (name, name) returns boolean as
-$$
-declare
-       i_nspname alias for $1;
-       i_tblname alias for $2;
-       c_table oid;
-       c_namespace oid;
-       c_enabled boolean;
-       v_dummy int4;
-begin
-       select 1 into v_dummy from "pg_catalog".pg_settings where name = 'autovacuum' and setting = 'on';
-       if not found then
-               return 't'::boolean;       -- If autovac is turned off, then we gotta vacuum
-       end if;
-       
-       select into c_namespace oid from "pg_catalog".pg_namespace where nspname = i_nspname;
-       if not found then
-               raise exception 'Slony-I: namespace % does not exist', i_nspname;
-       end if;
-       select into c_table oid from "pg_catalog".pg_class where relname = i_tblname and relnamespace = c_namespace;
-       if not found then
-               raise warning 'Slony-I: table % does not exist in namespace %/%', tblname, c_namespace, i_nspname;
-               return 'f'::boolean;
-       end if;
-       
-       -- So, the table is legit; try to look it up for autovacuum policy
-       select enabled into c_enabled from "pg_catalog".pg_autovacuum where vacrelid = c_table;
-
-       if not found then
-               return 'f'::boolean;   -- Autovac is turned on, and this table has no overriding handling
-       end if;
-
-       if c_enabled then
-               return 'f'::boolean;   -- Autovac is expressly turned on for this table
-       end if;
-
-       return 't'::boolean;
-end;$$ language plpgsql;
-
-comment on function @NAMESPACE@.ShouldSlonyVacuumTable (name, name) is 
-'returns false if autovacuum handles vacuuming of the table, or if the table does not exist; returns true if Slony-I should manage it';
-
 create or replace function @NAMESPACE@.setup_vactables_type () returns integer as $$
 begin
        if not exists (select 1 from pg_catalog.pg_type t, pg_catalog.pg_namespace n
diff --git a/src/backend/slony1_funcs.v84.sql b/src/backend/slony1_funcs.v84.sql
new file mode 100644 (file)
index 0000000..b6957ab
--- /dev/null
@@ -0,0 +1,55 @@
+-- ----------------------------------------------------------------------
+-- slony1_funcs.v83.sql
+--
+--    Version 8.3 specific part of the replication support functions.
+--
+--     Copyright (c) 2007, PostgreSQL Global Development Group
+--     Author: Jan Wieck, Afilias USA INC.
+--
+-- $Id: slony1_funcs.v84.sql,v 1.1.2.1 2009-07-21 21:15:51 cbbrowne Exp $
+-- ----------------------------------------------------------------------
+
+-- ----------------------------------------------------------------------
+-- FUNCTION ShouldSlonyVacuumTable (nspname, tabname)
+--
+--     Returns 't' if the table needs to be vacuumed by Slony-I
+--      Returns 'f' if autovac handles the table, so Slony-I should not
+--                  or if the table is not needful altogether
+-- ----------------------------------------------------------------------
+create or replace function @NAMESPACE@.ShouldSlonyVacuumTable (name, name) returns boolean as
+$$
+declare
+       i_nspname alias for $1;
+       i_tblname alias for $2;
+       c_table oid;
+       c_namespace oid;
+       c_enabled boolean;
+       v_dummy int4;
+begin
+       select 1 into v_dummy from "pg_catalog".pg_settings where name = 'autovacuum' and setting = 'on';
+       if not found then
+               return 't'::boolean;       -- If autovac is turned off, then we gotta vacuum
+       end if;
+       
+       select into c_namespace oid from "pg_catalog".pg_namespace where nspname = i_nspname;
+       if not found then
+               raise exception 'Slony-I: namespace % does not exist', i_nspname;
+       end if;
+       select into c_table oid from "pg_catalog".pg_class where relname = i_tblname and relnamespace = c_namespace;
+       if not found then
+               raise warning 'Slony-I: table % does not exist in namespace %/%', tblname, c_namespace, i_nspname;
+               return 'f'::boolean;
+       end if;
+       
+       -- So, the table is legit; try to look it up for autovacuum policy
+       if exists (select 1 from pg_class where 'autovacuum_enabled=off' = any (reloptions) and oid = c_table) then
+               return 't'::boolean;   -- Autovac is turned on, but this table is disabled
+       end if;
+
+       return 'f'::boolean;
+
+end;$$ language plpgsql;
+
+comment on function @NAMESPACE@.ShouldSlonyVacuumTable (name, name) is 
+'returns false if autovacuum handles vacuuming of the table, or if the table does not exist; returns true if Slony-I should manage it';
+
index 6f358017ed4ed6760896101ee6a1bc0a581f2b48..4d0b401561bb28fd3a81f9c8c1040179be0bde0b 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2004, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     $Id: dbutils.c,v 1.30.2.1 2009-07-20 22:30:10 cbbrowne Exp $
+ *     $Id: dbutils.c,v 1.30.2.2 2009-07-21 21:15:51 cbbrowne Exp $
  * ----------------------------------------------------------------------
  */
 
@@ -126,7 +126,7 @@ slon_connectdb(char *conninfo, char *symname)
        slon_log(SLON_CONFIG,
                         "version for \"%s\" is %d\n", conninfo, conn->pg_version);
 
-       if (conn->pg_version >= 80100)
+       if (conn->pg_version >= 80300)
        {
                slon_mkquery(&query, "set escape_string_warning to 'off'");
                res = PQexec(dbconn, dstring_data(&query));
@@ -135,9 +135,7 @@ slon_connectdb(char *conninfo, char *symname)
                        slon_log(SLON_ERROR, "Unable to set escape_string_warning to off\n");
                }
                PQclear(res);
-       }
-       if (conn->pg_version >= 80200)
-       {
+
                slon_mkquery(&query, "set standard_conforming_strings to 'off'");
                res = PQexec(dbconn, dstring_data(&query));
                if (!(PQresultStatus(res) == PGRES_COMMAND_OK))
index 5dfa8b581f3305253b35ed2d73cca55bb1751630..b662cda60c222d481da5a779b1e16fed5afd3d45 100644 (file)
@@ -6,7 +6,7 @@
  *     Copyright (c) 2003-2004, PostgreSQL Global Development Group
  *     Author: Jan Wieck, Afilias USA INC.
  *
- *     $Id: slonik.c,v 1.91.2.3 2009-07-14 19:09:00 cbbrowne Exp $
+ *     $Id: slonik.c,v 1.91.2.4 2009-07-21 21:15:51 cbbrowne Exp $
  *-------------------------------------------------------------------------
  */
 
@@ -1802,14 +1802,14 @@ load_slony_base(SlonikStmt * stmt, int no_id)
        else if ((adminfo->pg_version >= 80400) && (adminfo->pg_version < 80500)) /* 8.4 */
        {
                use_major = 8;
-               use_minor = 3;   /* at this point, there's nothing specifically different in 8.4 from 8.3 */
+               use_minor = 4;   /* at this point, there's nothing specifically different in 8.4 from 8.3 */
        }
        else    /* above 8.4 ??? */
        {
                use_major = 8;
-               use_minor = 3;
+               use_minor = 4;
                printf("%s:%d: Possible unsupported PostgreSQL "
-                       "version (%d) %d.%d, defaulting to 8.3 support\n",
+                       "version (%d) %d.%d, defaulting to 8.4 support\n",
                         stmt->stmt_filename, stmt->stmt_lno, adminfo->pg_version,
                        (adminfo->pg_version/10000), ((adminfo->pg_version%10000)/100));
        }