postmodern 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8584fc36609820bec538da1d614c2fa8e51e135a
4
- data.tar.gz: 6e4b0248349daa0c274b06bdfd39120ff3655bb4
3
+ metadata.gz: 330a276a44bee39eeedd67c516efb9302db306a0
4
+ data.tar.gz: b32e4ff5c4a05d922725cfbf387e660c85918b34
5
5
  SHA512:
6
- metadata.gz: d73e87d8fc6f856fe8af0ab931af813f0d0aeb857bd9d4ba161139f7d3768059d6093467fcf5c0bd4bccd5a09ee924620424de58b7734480792245af4b2597ff
7
- data.tar.gz: 878c15c555776ec7fb49ce94e2ea00c7925425852b5bda364c6056439994e94eb4975562418018bcc84542b934645fa307a792e52c26e5a6f54ff3638497be0c
6
+ metadata.gz: ae60db81ea441c8358df814c734be3ef5b9998bdcaa96f0a2936f1a07fdff24f1dff6ca56d4d23937815358f329ae381ac8f03a673c419afb8e3f586f411d752
7
+ data.tar.gz: b9009ef87cd0abfc7b37b65ca960e506c2be47e885333424924ac4604f4b61522ed2882ba248d5568381dd1127bbe8059bb5851e75a1455cc182e296825bbca9
data/README.md CHANGED
@@ -36,6 +36,7 @@ Usage: postmodern (vacuum|freeze) <options>
36
36
  -W, --password PASS
37
37
 
38
38
  -t, --timeout TIMEOUT Halt after timeout minutes -- default 120
39
+ -P, --pause PAUSE Pause (minutes) after each table vacuum -- default 10
39
40
  -d, --database DB Database to vacuum. Required.
40
41
 
41
42
  -B, --tablesize BYTES minimum table size to vacuum -- default 1000000
@@ -65,6 +66,11 @@ database activity. They vacuum or vacuum freeze each table that requires
65
66
  it (based on command line options). Before each operation, the scripts check
66
67
  to make sure they have not gone longer than `--timeout` seconds.
67
68
 
69
+ `--pause` is useful to allow I/O-bound replicas to catch up on replication
70
+ before starting new vacuum events. When vacuuming large tables with many
71
+ dead tuples, a lot of changes need to be sent to replicas. When using replicas
72
+ with spinning disks, this can saturate the I/O of the disk array.
73
+
68
74
  ### WAL archives
69
75
 
70
76
  The wal archiving scripts packaged in this gem are intended to serve as
@@ -42,6 +42,10 @@ module Postmodern
42
42
  self.options[:timeout] = opt
43
43
  end
44
44
 
45
+ opts.on('-P', '--pause PAUSE', 'Pause (minutes) after each table vacuum -- default 10') do |opt|
46
+ self.options[:pause] = opt
47
+ end
48
+
45
49
  opts.on('-d', '--database DB', 'Database to vacuum. Required.') do |opt|
46
50
  self.options[:database] = opt
47
51
  end
@@ -101,13 +105,15 @@ module Postmodern
101
105
  end
102
106
 
103
107
  def vacuum
104
- tables_to_vacuum.each do |table|
108
+ tables_to_vacuum_size = tables_to_vacuum.size
109
+ tables_to_vacuum.each_with_index do |table,index|
105
110
  Postmodern.logger.info "Vacuuming #{table}"
106
111
  adapter.execute(vacuum_statement(table)) unless dryrun?
107
112
  if timedout?
108
113
  Postmodern.logger.warn "Vacuuming timed out"
109
114
  break
110
115
  end
116
+ pause unless index == tables_to_vacuum_size - 1
111
117
  end
112
118
  Postmodern.logger.info "Vacuuming finished"
113
119
  end
@@ -120,6 +126,12 @@ module Postmodern
120
126
  Time.now >= start_time + (options[:timeout].to_i * 60)
121
127
  end
122
128
 
129
+ def pause
130
+ pause_time = options[:pause].to_i * 60
131
+ Postmodern.logger.info "Pausing before next vacuum for #{pause_time} minutes."
132
+ sleep(pause_time) unless dryrun?
133
+ end
134
+
123
135
  def dryrun?
124
136
  !!options[:dryrun]
125
137
  end
@@ -1,3 +1,3 @@
1
1
  module Postmodern
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -10,6 +10,7 @@ Usage: postmodern (vacuum|freeze) <options>
10
10
  -W, --password PASS
11
11
 
12
12
  -t, --timeout TIMEOUT Halt after timeout minutes -- default 120
13
+ -P, --pause PAUSE Pause (minutes) after each table vacuum -- default 10
13
14
  -d, --database DB Database to vacuum. Required.
14
15
 
15
16
  -B, --tablesize BYTES minimum table size to vacuum -- default 1000000
@@ -10,6 +10,7 @@ Usage: postmodern (vacuum|freeze) <options>
10
10
  -W, --password PASS
11
11
 
12
12
  -t, --timeout TIMEOUT Halt after timeout minutes -- default 120
13
+ -P, --pause PAUSE Pause (minutes) after each table vacuum -- default 10
13
14
  -d, --database DB Database to vacuum. Required.
14
15
 
15
16
  -B, --tablesize BYTES minimum table size to vacuum -- default 1000000
@@ -47,6 +47,7 @@ LIMIT 1000;
47
47
  before do
48
48
  allow(Postmodern::DB::Adapter).to receive(:new).and_return(adapter)
49
49
  allow(command).to receive(:tables_to_vacuum).and_return(tables_to_vacuum)
50
+ allow(command).to receive(:pause)
50
51
  end
51
52
 
52
53
  it "vacuums each table" do
@@ -50,13 +50,14 @@ describe Postmodern::Vacuum::Vacuum do
50
50
  let(:args) { %w(--database mydb) }
51
51
 
52
52
  before do
53
- allow(command).to receive(:adapter).and_return(adapter)
53
+ allow(command).to receive(:configure_vacuum_cost)
54
+ allow(command).to receive(:vacuum)
54
55
  end
55
56
 
56
57
  it 'executes vacuum operations in order' do
57
- expect(command).to receive(:configure_vacuum_cost).once
58
- expect(command).to receive(:vacuum).once
59
58
  command.run
59
+ expect(command).to have_received(:configure_vacuum_cost).once
60
+ expect(command).to have_received(:vacuum).once
60
61
  end
61
62
  end
62
63
 
@@ -109,8 +110,8 @@ describe Postmodern::Vacuum::Vacuum do
109
110
 
110
111
  it 'finds list of tables to vacuum' do
111
112
  result = [
112
- { 'full_table_name' => 'table1'},
113
- { 'full_table_name' => 'table2'},
113
+ {'full_table_name' => 'table1'},
114
+ {'full_table_name' => 'table2'},
114
115
  ]
115
116
  allow(command).to receive(:adapter).and_return(adapter)
116
117
  expect(adapter).to receive(:execute).with(%Q{WITH deadrow_tables AS (
@@ -137,6 +138,7 @@ ORDER BY dead_pct DESC, table_bytes DESC;
137
138
  before do
138
139
  allow(Postmodern::DB::Adapter).to receive(:new).and_return(adapter)
139
140
  allow(command).to receive(:tables_to_vacuum).and_return(tables_to_vacuum)
141
+ allow(command).to receive(:pause)
140
142
  end
141
143
 
142
144
  let(:tables_to_vacuum) { %w(table1 table2 table3) }
@@ -163,6 +165,11 @@ ORDER BY dead_pct DESC, table_bytes DESC;
163
165
  expect(adapter).not_to have_received(:execute).with("VACUUM ANALYZE %s" % tables_to_vacuum[1])
164
166
  expect(adapter).not_to have_received(:execute).with("VACUUM ANALYZE %s" % tables_to_vacuum[2])
165
167
  end
168
+
169
+ it 'pauses between each vacuum' do
170
+ command.vacuum
171
+ expect(command).to have_received(:pause).exactly(2).times
172
+ end
166
173
  end
167
174
 
168
175
  describe '#dryrun?' do
@@ -183,6 +190,29 @@ ORDER BY dead_pct DESC, table_bytes DESC;
183
190
  end
184
191
  end
185
192
 
193
+ describe '#pause' do
194
+ let(:time) { Time.now }
195
+ let(:args) { %w(--d db -P 30) }
196
+
197
+ before do
198
+ allow(command).to receive(:sleep)
199
+ end
200
+
201
+ it "Should sleep for specified time" do
202
+ command.pause
203
+ expect(command).to have_received(:sleep).with(30 * 60).once
204
+ end
205
+
206
+ context 'during dry-run' do
207
+ let(:args) { %w(--d db -P 30 --dry-run) }
208
+
209
+ it "Should not sleep during dry-run" do
210
+ command.pause
211
+ expect(command).not_to have_received(:sleep)
212
+ end
213
+ end
214
+ end
215
+
186
216
  describe '#timedout?' do
187
217
  let(:time) { Time.now }
188
218
  let(:args) { %w(--d db -t 15) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmodern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Saxby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-01 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg