cbbrowne cbbrowne at ca.afilias.info
Thu Dec 4 14:36:16 PST 2008
Mark Stosberg wrote:
> Hello,
>
> I haven't found this answer in the documentation, so I'm hoping someone here
> can point me in the right direction.
>
> What's the best practice for renaming tables managed by slony?  Is it treated
> as removing and re-adding a new table, or is there a shortcut?
>
> I've got a project where I need to rename 30 columns, 2 sequences, 11 tables
> and 7 views...
>
> We are still using Slony 1.2.x.
>
> Thanks for the help!
>   
I have handled this in the past via running a DDL script via "EXECUTE 
SCRIPT" that did an "alter table ... rename to ...".

The ALTER COLUMN requests will be handled perfectly well by Slony-I.

There is a wrinkle for renaming tables in that you need to ensure 
sl_table has the new name when it goes to add the tables back into 
replication.

Your script would need to do something like:

  alter table this...
  alter table that...
   ... and onwards, for the "cast of 11 tables" ...

... then, still as part of the same DDL script being executed by EXECUTE 
SCRIPT...
  update "_my_slony_schema".sl_table
   set tab_relname = (select relname from pg_catalog.pg_class p where 
oid = tab_reloid);
  update "_my_slony_schema".sl_sequence
   set seq_relname = (select relname from pg_catalog.pg_class p where 
oid = seq_reloid);

Note this affects sequences *and* tables.

This approach means not needing to drop those tables out of replication.

That manual alteration to sl_table/sl_sequence makes it look a little 
bit hairy :-(.

I just typed the above in "on the fly" - this should obviously be tested 
before running in production :-).

-- 
select 'cbbrowne' || '@' || 'ca.afilias.info';
<http://dba2.int.libertyrms.com/>
Christopher Browne
(416) 673-4124 (land)



More information about the Slony1-general mailing list