[Bucardo-general] newbie questions

Joe Conway mail at joeconway.com
Mon Jun 14 15:41:06 UTC 2010


On 06/14/2010 07:31 AM, Greg Sabino Mullane wrote:
> Welcome to the list, Joe.
> 
> On Sat, Jun 12, 2010 at 02:40:14PM -0700, Joe Conway wrote:
>> If I want to set up a swap sync:
>>
>> 1) Is there a bucardo_ctl function to set "standard_conflict"
>>    or does it need to be done by manually modifying goat?

> Or all at once:
> 
> bucardo_ctl update table '*' standard_conflict=source

Ah, great, thanks. I didn't grok from the docs that I could use a
wildcard like that.

>> 2) What should "standard_conflict" be set to for sequences?
>>
>> 3) How do sequences behave in a multi-master scenario?
> 
> Sequences have additional standard_conflict methods of 
> "highest" and "lowest". However, the recommended method is to 
> offset your sequences so that they never collide. In other words, 
> assuming sequences are initially identical on master1 and master2:
> 
> psql -h master1 -c "SELECT nextval('tab_id_seq')"
> psql -h master1 -c 'ALTER SEQUENCE tab_id_seq INCREMENT BY 2'
> psql -h master2 -c 'ALTER SEQUENCE tab_id_seq INCREMENT BY 2'

Thanks again. I found the documentation page that mentions this after
sending my question. FWIW, this may be overkill, but here is what I did:

(some wrapping forced for readability)
----------------------------------------
CREATE OR REPLACE FUNCTION adjust_seqs(namespace text, starteven bool)
  RETURNS text AS $$
DECLARE
  rec         record;
  startval    bigint;
  sql         text;
  fqname      text;
BEGIN
  FOR rec in EXECUTE 'select relname from pg_class where relkind = ''S''
                      and relnamespace = (select oid from pg_namespace
                      where nspname=''' || namespace || ''')' LOOP
    fqname :=  namespace || '.' ||  rec.relname;
    IF starteven THEN
      EXECUTE 'SELECT ((last_value / 2) * 2) + 2 from ' || fqname
      INTO startval;
    ELSE
      EXECUTE 'SELECT ((last_value / 2) * 2) + 1 from ' || fqname
      INTO startval;
    END If;
    sql := 'ALTER SEQUENCE ' || fqname || ' INCREMENT BY 2
           RESTART WITH ' || startval;
    EXECUTE sql;
    RAISE NOTICE '%', sql;
  END LOOP;
  RETURN 'OK';
END;
$$ LANGUAGE plpgsql STRICT;

SELECT adjust_seqs('public', true);  -- in master1 (even)
SELECT adjust_seqs('public', false); -- in master2 (odd)


> If that is in place, you can set the standard_conflict to 'skip' 
> for the sequences.

Good to know. It sounded like I should not add sequences to the herd at
all though (seen here: http://bucardo.org/wiki/Bucardo/Sequences)

Joe



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature
Url : https://mail.endcrypt.com/pipermail/bucardo-general/attachments/20100614/b043f754/attachment.bin 


More information about the Bucardo-general mailing list