Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6425d69

Browse files
committed
alter_sequences() function
1 parent74fa53c commit6425d69

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎multimaster--1.0.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,40 @@ LANGUAGE C;
8484

8585
CREATETABLEIF NOT EXISTSmtm.local_tables(rel_schematext, rel_nametext,primary key(rel_schema, rel_name));
8686

87+
CREATE OR REPLACEFUNCTIONmtm.alter_sequences() RETURNSbooleanAS
88+
$$
89+
DECLARE
90+
seq_class pg_class%rowtype;
91+
seq_tuple record;
92+
node_idint;
93+
max_nodesint;
94+
new_startint;
95+
alteredboolean := false;
96+
BEGIN
97+
select current_setting('multimaster.max_nodes') into max_nodes;
98+
select id,"allNodes" into node_idfrommtm.get_cluster_state();
99+
FOR seq_classIN
100+
SELECT*FROM pg_classWHEREpg_class.relkind='S'
101+
LOOP
102+
EXECUTE'select * from'||seq_class.relname||';' INTO seq_tuple;
103+
IFseq_tuple.increment_by!= max_nodes THEN
104+
altered := true;
105+
RAISE NOTICE'Altering step for sequence % to %.',seq_tuple.sequence_name, max_nodes;
106+
EXECUTE'ALTER SEQUENCE'||seq_class.relname||' INCREMENT BY'|| max_nodes||';';
107+
END IF;
108+
IF (seq_tuple.last_value % max_nodes)!= node_id THEN
109+
altered := true;
110+
new_start := (seq_tuple.last_value/ max_nodes+1)*max_nodes+ node_id;
111+
RAISE NOTICE'Altering start for sequence % to %.',seq_tuple.sequence_name, new_start;
112+
EXECUTE'ALTER SEQUENCE'||seq_class.relname||' RESTART WITH'|| new_start||';';
113+
END IF;
114+
END LOOP;
115+
IF altered= false THEN
116+
RAISE NOTICE'All found sequnces have proper params.';
117+
END IF;
118+
RETURN true;
119+
END
120+
$$
121+
LANGUAGE plpgsql;
122+
123+
selectmtm.alter_sequences();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp