pg_logical_replicator 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pg_logical_replicator/cli.rb +42 -36
- data/lib/pg_logical_replicator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96dc848577db239b733e08e9496188feb9804ca9e30de70c1042003d5bee5f21
|
4
|
+
data.tar.gz: bc1b3fae2d8ee523c3b4e179da60a49767d32e51707cd68235ae5cbdb17a373a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14d3f3c07c06524bb5aa8a4ba30d7826bf7c9829c3fc1702074aad5308a96fddbe631afad997f1659980d12e8c6f0878330bd31f0a76ae81061a8c0e14d093cb
|
7
|
+
data.tar.gz: bbc1ff22ae42028874b74d0844cb87bf88c0f4983708fb51966086355f3401d9ec50bd34d8a96ed5f11e5c842aacbcaee8e699ded4c5b47bd19003bc872ae594
|
@@ -19,7 +19,7 @@ module PgLogicalReplicator
|
|
19
19
|
method_option :target_rep_password, type: :string
|
20
20
|
method_option :num_slots, type: :numeric, default: 10
|
21
21
|
method_option :groups, type: :array
|
22
|
-
|
22
|
+
|
23
23
|
def setup
|
24
24
|
source_host = options[:source_host]
|
25
25
|
source_port = options[:source_port]
|
@@ -35,11 +35,11 @@ module PgLogicalReplicator
|
|
35
35
|
target_rep_password = options[:target_rep_password] || target_password
|
36
36
|
num_slots = options[:num_slots]
|
37
37
|
target_groups = options[:groups].map(&:to_i) if options[:groups]
|
38
|
-
|
38
|
+
|
39
39
|
conn = PG.connect(dbname: source_database, user: source_username, password: source_password, host: source_host, port: source_port)
|
40
|
-
|
40
|
+
|
41
41
|
query = "SELECT tablename FROM pg_tables WHERE schemaname = 'public' order by tablename ASC;"
|
42
|
-
|
42
|
+
|
43
43
|
tables = begin
|
44
44
|
result = conn.exec(query)
|
45
45
|
result.map { |row| row['tablename'] }
|
@@ -47,49 +47,55 @@ module PgLogicalReplicator
|
|
47
47
|
conn.close if conn
|
48
48
|
end
|
49
49
|
puts "Total Tables: #{tables.size}"
|
50
|
-
|
50
|
+
|
51
51
|
tables_per_group = tables.size / num_slots
|
52
52
|
puts "Tables per group: #{tables_per_group}"
|
53
|
-
|
54
|
-
|
53
|
+
|
54
|
+
home_directory = Dir.home
|
55
|
+
puts "Home directory: #{home_directory}"
|
56
|
+
|
57
|
+
dump_dir_root = "#{home_directory}/db-dumps"
|
55
58
|
system("mkdir -p #{dump_dir_root}")
|
56
|
-
|
59
|
+
|
57
60
|
puts "Target Groups: #{target_groups}"
|
58
|
-
|
61
|
+
|
59
62
|
tables.each_slice(tables_per_group).with_index do |table_group, group_idx|
|
60
63
|
puts "Processing group #{group_idx + 1} size: #{table_group.size}"
|
61
|
-
|
64
|
+
|
62
65
|
group_number = group_idx + 1
|
63
|
-
|
66
|
+
|
64
67
|
next unless target_groups.nil? || target_groups.include?(group_number)
|
65
|
-
|
68
|
+
|
66
69
|
table_names = table_group.join(',')
|
67
|
-
|
70
|
+
|
68
71
|
dump_dir = "#{dump_dir_root}/#{group_number}"
|
69
|
-
|
72
|
+
|
70
73
|
puts "Removing directory: #{dump_dir}"
|
71
|
-
|
74
|
+
|
72
75
|
FileUtils.rm_rf(dump_dir)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
76
|
+
|
77
|
+
begin
|
78
|
+
puts "Creating directory: #{dump_dir}"
|
79
|
+
FileUtils.mkdir_p(dump_dir)
|
80
|
+
|
81
|
+
LogicalReplicationInitializer.new({
|
82
|
+
slot_name: "logical_sub_grp_#{group_number}",
|
83
|
+
publication_name: "logical_pub_grp_#{group_number}",
|
84
|
+
primary_conn_str: "host=#{source_host} port=#{source_port} dbname=#{source_database} user=#{source_username} password=#{source_password}",
|
85
|
+
target_conn_str: "host=#{target_host} port=#{target_port} dbname=#{target_database} user=#{target_username} password=#{target_password}",
|
86
|
+
target_rep_conn_str: "host=#{target_host} port=#{target_port} dbname=#{target_database} user=#{target_rep_username} password=#{target_rep_password}",
|
87
|
+
table_names: table_names,
|
88
|
+
dump_dir: dump_dir
|
89
|
+
}).start
|
90
|
+
ensure
|
91
|
+
puts "Removing directory: #{dump_dir}"
|
92
|
+
FileUtils.rm_rf(dump_dir)
|
93
|
+
end
|
86
94
|
rescue StandardError => e
|
87
95
|
puts "Error: #{e.message}"
|
88
|
-
ensure
|
89
|
-
FileUtils.rm_rf(dump_dir)
|
90
96
|
end
|
91
97
|
end
|
92
|
-
|
98
|
+
|
93
99
|
desc 'stop_replication', 'Stop all replication'
|
94
100
|
method_option :source_host, type: :string, required: true
|
95
101
|
method_option :source_port, type: :numeric, default: 5432
|
@@ -101,7 +107,7 @@ module PgLogicalReplicator
|
|
101
107
|
method_option :source_password, type: :string, required: true
|
102
108
|
method_option :target_username, type: :string
|
103
109
|
method_option :target_password, type: :string
|
104
|
-
|
110
|
+
|
105
111
|
def stop_replication
|
106
112
|
source_config = {
|
107
113
|
host: options[:source_host],
|
@@ -110,7 +116,7 @@ module PgLogicalReplicator
|
|
110
116
|
user: options[:source_username],
|
111
117
|
password: options[:source_password]
|
112
118
|
}
|
113
|
-
|
119
|
+
|
114
120
|
target_config = {
|
115
121
|
host: options[:target_host],
|
116
122
|
port: options[:target_port],
|
@@ -118,10 +124,10 @@ module PgLogicalReplicator
|
|
118
124
|
user: options[:target_username] || options[:source_username],
|
119
125
|
password: options[:target_password] || options[:source_password]
|
120
126
|
}
|
121
|
-
|
127
|
+
|
122
128
|
ReplicationStopper.new(source_config, target_config).stop_replication
|
123
129
|
end
|
124
|
-
|
130
|
+
|
125
131
|
desc 'transfer_schema', 'Transfer schema from source to target database'
|
126
132
|
method_option :source_host, type: :string, required: true
|
127
133
|
method_option :source_port, type: :numeric, default: 5432
|
@@ -133,7 +139,7 @@ module PgLogicalReplicator
|
|
133
139
|
method_option :source_password, type: :string, required: true
|
134
140
|
method_option :target_username, type: :string, required: true
|
135
141
|
method_option :target_password, type: :string, required: true
|
136
|
-
|
142
|
+
|
137
143
|
def transfer_schema
|
138
144
|
SchemaTransfer.new(
|
139
145
|
source_host: options[:source_host],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_logical_replicator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- eni9889
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
|
-
rubygems_version: 3.
|
121
|
+
rubygems_version: 3.0.3.1
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: PostgreSQL logical replication setup tool
|