@@ -87,7 +87,7 @@ CREATE TABLE IF NOT EXISTS mtm.local_tables(rel_schema text, rel_name text, prim
87
87
CREATE OR REPLACE FUNCTION mtm .alter_sequences() RETURNS boolean AS
88
88
$$
89
89
DECLARE
90
- seq_class pg_class%rowtype ;
90
+ seq_class record ;
91
91
seq_tuple record;
92
92
node_id int ;
93
93
max_nodes int ;
@@ -97,25 +97,20 @@ BEGIN
97
97
select current_setting(' multimaster.max_nodes' ) into max_nodes;
98
98
select id, " allNodes" into node_id from mtm .get_cluster_state ();
99
99
FOR seq_class IN
100
- SELECT * FROM pg_class WHERE pg_class .relkind = ' S'
100
+ SELECT ' " ' || ns . nspname || ' "." ' || seq . relname || ' " ' as seqname FROM pg_namespace ns, pg_class seq WHERE seq .relkind = ' S' and seq . relnamespace = ns . oid
101
101
LOOP
102
- BEGIN
103
- EXECUTE ' select * from ' || seq_class .relname || ' ;' INTO seq_tuple;
102
+ EXECUTE ' select * from ' || seq_class .seqname INTO seq_tuple;
104
103
IF seq_tuple .increment_by != max_nodes THEN
105
104
altered := true;
106
105
RAISE NOTICE ' Altering step for sequence % to %.' , seq_tuple .sequence_name , max_nodes;
107
- EXECUTE ' ALTER SEQUENCE ' || seq_class .relname || ' INCREMENT BY ' || max_nodes || ' ;' ;
106
+ EXECUTE ' ALTER SEQUENCE ' || seq_class .seqname || ' INCREMENT BY ' || max_nodes || ' ;' ;
108
107
END IF;
109
108
IF (seq_tuple .last_value % max_nodes) != node_id THEN
110
109
altered := true;
111
110
new_start := (seq_tuple .last_value / max_nodes + 1 )* max_nodes + node_id;
112
111
RAISE NOTICE ' Altering start for sequence % to %.' , seq_tuple .sequence_name , new_start;
113
- EXECUTE ' ALTER SEQUENCE ' || seq_class .relname || ' RESTART WITH ' || new_start || ' ;' ;
112
+ EXECUTE ' ALTER SEQUENCE ' || seq_class .seqname || ' RESTART WITH ' || new_start || ' ;' ;
114
113
END IF;
115
- EXCEPTION
116
- WHEN OTHERS THEN
117
- RAISE NOTICE ' Failed to alter sequence %s' , seq_class .relname ;
118
- END;
119
114
END LOOP;
120
115
IF altered = false THEN
121
116
RAISE NOTICE ' All found sequnces have proper params.' ;
0 commit comments