pg 1.1.0.pre20180730171000 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/ChangeLog +6595 -0
  5. data/History.rdoc +3 -8
  6. data/Manifest.txt +70 -2
  7. data/Rakefile +0 -1
  8. data/ext/pg.c +4 -1
  9. data/ext/pg.h +7 -0
  10. data/ext/pg_binary_decoder.c +1 -1
  11. data/ext/pg_binary_encoder.c +1 -1
  12. data/ext/pg_connection.c +8 -8
  13. data/ext/pg_result.c +1 -1
  14. data/ext/pg_text_decoder.c +1 -1
  15. data/ext/pg_text_encoder.c +6 -7
  16. data/ext/pg_tuple.c +4 -3
  17. data/ext/pg_type_map.c +1 -1
  18. data/ext/pg_type_map_all_strings.c +1 -1
  19. data/ext/pg_type_map_by_class.c +1 -1
  20. data/ext/pg_type_map_by_column.c +1 -1
  21. data/ext/pg_type_map_by_mri_type.c +1 -1
  22. data/ext/pg_type_map_by_oid.c +1 -1
  23. data/ext/pg_type_map_in_ruby.c +1 -1
  24. data/ext/util.c +1 -1
  25. data/lib/pg.rb +2 -2
  26. data/spec/pg/basic_type_mapping_spec.rb +4 -4
  27. data/spec/pg/connection_spec.rb +58 -13
  28. data/spec/pg/tuple_spec.rb +16 -2
  29. data/spec/pg/type_spec.rb +6 -0
  30. metadata +35 -69
  31. metadata.gz.sig +0 -0
  32. data/.gems +0 -6
  33. data/.hgignore +0 -21
  34. data/.hgsigs +0 -29
  35. data/.hgtags +0 -36
  36. data/.hoerc +0 -2
  37. data/.irbrc +0 -23
  38. data/.pryrc +0 -23
  39. data/.tm_properties +0 -21
  40. data/.travis.yml +0 -41
  41. data/Gemfile +0 -2
  42. data/appveyor.yml +0 -50
  43. data/certs/ged.pem +0 -26
  44. data/misc/openssl-pg-segfault.rb +0 -31
  45. data/misc/postgres/History.txt +0 -9
  46. data/misc/postgres/Manifest.txt +0 -5
  47. data/misc/postgres/README.txt +0 -21
  48. data/misc/postgres/Rakefile +0 -21
  49. data/misc/postgres/lib/postgres.rb +0 -16
  50. data/misc/ruby-pg/History.txt +0 -9
  51. data/misc/ruby-pg/Manifest.txt +0 -5
  52. data/misc/ruby-pg/README.txt +0 -21
  53. data/misc/ruby-pg/Rakefile +0 -21
  54. data/misc/ruby-pg/lib/ruby/pg.rb +0 -16
  55. data/pg.gemspec +0 -61
  56. data/sample/array_insert.rb +0 -20
  57. data/sample/async_api.rb +0 -106
  58. data/sample/async_copyto.rb +0 -39
  59. data/sample/async_mixed.rb +0 -56
  60. data/sample/check_conn.rb +0 -21
  61. data/sample/copydata.rb +0 -71
  62. data/sample/copyfrom.rb +0 -81
  63. data/sample/copyto.rb +0 -19
  64. data/sample/cursor.rb +0 -21
  65. data/sample/disk_usage_report.rb +0 -177
  66. data/sample/issue-119.rb +0 -94
  67. data/sample/losample.rb +0 -69
  68. data/sample/minimal-testcase.rb +0 -17
  69. data/sample/notify_wait.rb +0 -72
  70. data/sample/pg_statistics.rb +0 -285
  71. data/sample/replication_monitor.rb +0 -222
  72. data/sample/test_binary_values.rb +0 -33
  73. data/sample/wal_shipper.rb +0 -434
  74. data/sample/warehouse_partitions.rb +0 -311
@@ -1,311 +0,0 @@
1
- # -*- ruby -*-
2
- # vim: set nosta noet ts=4 sw=4:
3
- #
4
- # Script to automatically move partitioned tables and their indexes
5
- # to a separate area on disk.
6
- #
7
- # Mahlon E. Smith <mahlon@martini.nu>
8
- #
9
- # Example use case:
10
- #
11
- # - You've got a heavy insert table, such as syslog data.
12
- # - This table has a partitioning trigger (or is manually partitioned)
13
- # by date, to separate incoming stuff from archival/report stuff.
14
- # - You have a tablespace on cheap or slower disk (maybe even
15
- # ZFS compressed, or some such!)
16
- #
17
- # The only assumption this script makes is that your tables are dated, and
18
- # the tablespace they're moving into already exists.
19
- #
20
- # A full example, using the syslog idea from above, where each child
21
- # table is date partitioned by a convention of "syslog_YEAR-WEEKOFYEAR":
22
- #
23
- # syslog # <--- parent
24
- # syslog_2012_06 # <--- inherited
25
- # syslog_2012_07 # <--- inherited
26
- # syslog_2012_08 # <--- inherited
27
- # ...
28
- #
29
- # You'd run this script like so:
30
- #
31
- # ./warehouse_partitions.rb -F syslog_%Y_%U
32
- #
33
- # Assuming this was week 12 of the year, tables syslog_2012_06 through
34
- # syslog_2012_11 would start sequentially migrating into the tablespace
35
- # called 'warehouse'.
36
- #
37
-
38
-
39
- require 'date'
40
- require 'ostruct'
41
- require 'optparse'
42
- require 'pathname'
43
- require 'etc'
44
- require 'pg'
45
-
46
-
47
- ### A tablespace migration class.
48
- ###
49
- class PGWarehouse
50
-
51
- def initialize( opts )
52
- @opts = opts
53
- @db = PG.connect(
54
- :dbname => opts.database,
55
- :host => opts.host,
56
- :port => opts.port,
57
- :user => opts.user,
58
- :password => opts.pass,
59
- :sslmode => 'prefer'
60
- )
61
- @db.exec "SET search_path TO %s" % [ opts.schema ] if opts.schema
62
-
63
- @relations = self.relations
64
- end
65
-
66
- attr_reader :db
67
-
68
- ######
69
- public
70
- ######
71
-
72
- ### Perform the tablespace moves.
73
- ###
74
- def migrate
75
- if @relations.empty?
76
- $stderr.puts 'No tables were found for warehousing.'
77
- return
78
- end
79
-
80
- $stderr.puts "Found %d relation%s to move." % [ relations.length, relations.length == 1 ? '' : 's' ]
81
- @relations.sort_by{|_,v| v[:name] }.each do |_, val|
82
- $stderr.print " - Moving table '%s' to '%s'... " % [
83
- val[:name], @opts.tablespace
84
- ]
85
-
86
- if @opts.dryrun
87
- $stderr.puts '(not really)'
88
-
89
- else
90
- age = self.timer do
91
- db.exec "ALTER TABLE %s SET TABLESPACE %s;" % [
92
- val[:name], @opts.tablespace
93
- ]
94
- end
95
- puts age
96
- end
97
-
98
- val[ :indexes ].each do |idx|
99
- $stderr.print " - Moving index '%s' to '%s'... " % [
100
- idx, @opts.tablespace
101
- ]
102
- if @opts.dryrun
103
- $stderr.puts '(not really)'
104
-
105
- else
106
- age = self.timer do
107
- db.exec "ALTER INDEX %s SET TABLESPACE %s;" % [
108
- idx, @opts.tablespace
109
- ]
110
- end
111
- puts age
112
- end
113
- end
114
- end
115
- end
116
-
117
-
118
- #########
119
- protected
120
- #########
121
-
122
- ### Get OIDs and current tablespaces for everything under the
123
- ### specified schema.
124
- ###
125
- def relations
126
- return @relations if @relations
127
- relations = {}
128
-
129
- query = %q{
130
- SELECT c.oid AS oid,
131
- c.relname AS name,
132
- c.relkind AS kind,
133
- t.spcname AS tspace
134
- FROM pg_class AS c
135
- LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
136
- LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
137
- WHERE c.relkind = 'r' }
138
- query << "AND n.nspname='#{@opts.schema}'" if @opts.schema
139
-
140
- # Get the relations list, along with each element's current tablespace.
141
- #
142
- self.db.exec( query ) do |res|
143
- res.each do |row|
144
- relations[ row['oid'] ] = {
145
- :name => row['name'],
146
- :tablespace => row['tspace'],
147
- :indexes => [],
148
- :parent => nil
149
- }
150
- end
151
- end
152
-
153
- # Add table inheritence information.
154
- #
155
- db.exec 'SELECT inhrelid AS oid, inhparent AS parent FROM pg_inherits' do |res|
156
- res.each do |row|
157
- relations[ row['oid'] ][ :parent ] = row['parent']
158
- end
159
- end
160
-
161
- # Remove tables that don't qualify for warehousing.
162
- #
163
- # - Tables that are not children of a parent
164
- # - Tables that are already in the warehouse tablespace
165
- # - The currently active child (it's likely being written to!)
166
- # - Any table that can't be parsed into the specified format
167
- #
168
- relations.reject! do |oid, val|
169
- begin
170
- val[:parent].nil? ||
171
- val[:tablespace] == @opts.tablespace ||
172
- val[:name] == Time.now.strftime( @opts.format ) ||
173
- ! DateTime.strptime( val[:name], @opts.format )
174
- rescue ArgumentError
175
- true
176
- end
177
- end
178
-
179
- query = %q{
180
- SELECT c.oid AS oid,
181
- i.indexname AS name
182
- FROM pg_class AS c
183
- INNER JOIN pg_indexes AS i
184
- ON i.tablename = c.relname }
185
- query << "AND i.schemaname='#{@opts.schema}'" if @opts.schema
186
-
187
- # Attach index names to tables.
188
- #
189
- db.exec( query ) do |res|
190
- res.each do |row|
191
- relations[ row['oid'] ][ :indexes ] << row['name'] if relations[ row['oid'] ]
192
- end
193
- end
194
-
195
- return relations
196
- end
197
-
198
-
199
- ### Wrap arbitrary commands in a human readable timer.
200
- ###
201
- def timer
202
- start = Time.now
203
- yield
204
- age = Time.now - start
205
-
206
- diff = age
207
- secs = diff % 60
208
- diff = ( diff - secs ) / 60
209
- mins = diff % 60
210
- diff = ( diff - mins ) / 60
211
- hour = diff % 24
212
-
213
- return "%02d:%02d:%02d" % [ hour, mins, secs ]
214
- end
215
- end
216
-
217
-
218
- ### Parse command line arguments. Return a struct of global options.
219
- ###
220
- def parse_args( args )
221
- options = OpenStruct.new
222
- options.database = Etc.getpwuid( Process.uid ).name
223
- options.host = '127.0.0.1'
224
- options.port = 5432
225
- options.user = Etc.getpwuid( Process.uid ).name
226
- options.sslmode = 'prefer'
227
- options.tablespace = 'warehouse'
228
-
229
- opts = OptionParser.new do |opts|
230
- opts.banner = "Usage: #{$0} [options]"
231
-
232
- opts.separator ''
233
- opts.separator 'Connection options:'
234
-
235
- opts.on( '-d', '--database DBNAME',
236
- "specify the database to connect to (default: \"#{options.database}\")" ) do |db|
237
- options.database = db
238
- end
239
-
240
- opts.on( '-h', '--host HOSTNAME', 'database server host' ) do |host|
241
- options.host = host
242
- end
243
-
244
- opts.on( '-p', '--port PORT', Integer,
245
- "database server port (default: \"#{options.port}\")" ) do |port|
246
- options.port = port
247
- end
248
-
249
- opts.on( '-n', '--schema SCHEMA', String,
250
- "operate on the named schema only (default: none)" ) do |schema|
251
- options.schema = schema
252
- end
253
-
254
- opts.on( '-T', '--tablespace SPACE', String,
255
- "move old tables to this tablespace (default: \"#{options.tablespace}\")" ) do |tb|
256
- options.tablespace = tb
257
- end
258
-
259
- opts.on( '-F', '--tableformat FORMAT', String,
260
- "The naming format (strftime) for the inherited tables (default: none)" ) do |format|
261
- options.format = format
262
- end
263
-
264
- opts.on( '-U', '--user NAME',
265
- "database user name (default: \"#{options.user}\")" ) do |user|
266
- options.user = user
267
- end
268
-
269
- opts.on( '-W', 'force password prompt' ) do |pw|
270
- print 'Password: '
271
- begin
272
- system 'stty -echo'
273
- options.pass = gets.chomp
274
- ensure
275
- system 'stty echo'
276
- puts
277
- end
278
- end
279
-
280
- opts.separator ''
281
- opts.separator 'Other options:'
282
-
283
- opts.on_tail( '--dry-run', "don't actually do anything" ) do
284
- options.dryrun = true
285
- end
286
-
287
- opts.on_tail( '--help', 'show this help, then exit' ) do
288
- $stderr.puts opts
289
- exit
290
- end
291
-
292
- opts.on_tail( '--version', 'output version information, then exit' ) do
293
- puts Stats::VERSION
294
- exit
295
- end
296
- end
297
-
298
- opts.parse!( args )
299
- return options
300
- end
301
-
302
-
303
- if __FILE__ == $0
304
- opts = parse_args( ARGV )
305
- raise ArgumentError, "A naming format (-F) is required." unless opts.format
306
-
307
- $stdout.sync = true
308
- PGWarehouse.new( opts ).migrate
309
- end
310
-
311
-