pg_logical_replicator 0.1.7 → 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 +26 -23
- 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,34 +47,37 @@ 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
|
-
|
76
|
+
|
74
77
|
begin
|
75
78
|
puts "Creating directory: #{dump_dir}"
|
76
79
|
FileUtils.mkdir_p(dump_dir)
|
77
|
-
|
80
|
+
|
78
81
|
LogicalReplicationInitializer.new({
|
79
82
|
slot_name: "logical_sub_grp_#{group_number}",
|
80
83
|
publication_name: "logical_pub_grp_#{group_number}",
|
@@ -92,7 +95,7 @@ module PgLogicalReplicator
|
|
92
95
|
puts "Error: #{e.message}"
|
93
96
|
end
|
94
97
|
end
|
95
|
-
|
98
|
+
|
96
99
|
desc 'stop_replication', 'Stop all replication'
|
97
100
|
method_option :source_host, type: :string, required: true
|
98
101
|
method_option :source_port, type: :numeric, default: 5432
|
@@ -104,7 +107,7 @@ module PgLogicalReplicator
|
|
104
107
|
method_option :source_password, type: :string, required: true
|
105
108
|
method_option :target_username, type: :string
|
106
109
|
method_option :target_password, type: :string
|
107
|
-
|
110
|
+
|
108
111
|
def stop_replication
|
109
112
|
source_config = {
|
110
113
|
host: options[:source_host],
|
@@ -113,7 +116,7 @@ module PgLogicalReplicator
|
|
113
116
|
user: options[:source_username],
|
114
117
|
password: options[:source_password]
|
115
118
|
}
|
116
|
-
|
119
|
+
|
117
120
|
target_config = {
|
118
121
|
host: options[:target_host],
|
119
122
|
port: options[:target_port],
|
@@ -121,10 +124,10 @@ module PgLogicalReplicator
|
|
121
124
|
user: options[:target_username] || options[:source_username],
|
122
125
|
password: options[:target_password] || options[:source_password]
|
123
126
|
}
|
124
|
-
|
127
|
+
|
125
128
|
ReplicationStopper.new(source_config, target_config).stop_replication
|
126
129
|
end
|
127
|
-
|
130
|
+
|
128
131
|
desc 'transfer_schema', 'Transfer schema from source to target database'
|
129
132
|
method_option :source_host, type: :string, required: true
|
130
133
|
method_option :source_port, type: :numeric, default: 5432
|
@@ -136,7 +139,7 @@ module PgLogicalReplicator
|
|
136
139
|
method_option :source_password, type: :string, required: true
|
137
140
|
method_option :target_username, type: :string, required: true
|
138
141
|
method_option :target_password, type: :string, required: true
|
139
|
-
|
142
|
+
|
140
143
|
def transfer_schema
|
141
144
|
SchemaTransfer.new(
|
142
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
|