cipherstash-pg 1.0.0.beta.1-x86_64-linux → 1.0.0.beta.4-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.appveyor.yml +42 -0
  3. data/.gems +6 -0
  4. data/.gemtest +0 -0
  5. data/.github/workflows/binary-gems.yml +117 -0
  6. data/.github/workflows/source-gem.yml +137 -0
  7. data/.gitignore +19 -0
  8. data/.hgsigs +34 -0
  9. data/.hgtags +41 -0
  10. data/.irbrc +23 -0
  11. data/.pryrc +23 -0
  12. data/.tm_properties +21 -0
  13. data/.travis.yml +49 -0
  14. data/Gemfile +3 -3
  15. data/Gemfile.lock +45 -0
  16. data/{History.rdoc → History.md} +168 -153
  17. data/README.ja.md +266 -0
  18. data/README.md +272 -0
  19. data/Rakefile +65 -104
  20. data/Rakefile.cross +298 -0
  21. data/certs/larskanis-2023.pem +24 -0
  22. data/cipherstash-pg.gemspec +0 -0
  23. data/lib/2.7/pg_ext.so +0 -0
  24. data/lib/3.0/pg_ext.so +0 -0
  25. data/lib/3.1/pg_ext.so +0 -0
  26. data/lib/3.2/pg_ext.so +0 -0
  27. data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
  28. data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
  29. data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
  30. data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
  31. data/lib/cipherstash-pg/binary_decoder.rb +21 -0
  32. data/lib/cipherstash-pg/coder.rb +82 -0
  33. data/lib/cipherstash-pg/connection.rb +467 -0
  34. data/lib/cipherstash-pg/constants.rb +3 -0
  35. data/lib/cipherstash-pg/exceptions.rb +19 -0
  36. data/lib/cipherstash-pg/result.rb +22 -0
  37. data/lib/cipherstash-pg/text_decoder.rb +43 -0
  38. data/lib/cipherstash-pg/text_encoder.rb +67 -0
  39. data/lib/cipherstash-pg/tuple.rb +24 -0
  40. data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
  41. data/lib/cipherstash-pg/version.rb +3 -0
  42. data/lib/cipherstash-pg.rb +56 -11
  43. data/lib/libpq.so.5 +0 -0
  44. data/misc/openssl-pg-segfault.rb +15 -25
  45. data/misc/postgres/Rakefile +13 -20
  46. data/misc/postgres/lib/postgres.rb +10 -14
  47. data/misc/ruby-pg/Rakefile +13 -20
  48. data/misc/ruby-pg/lib/ruby/pg.rb +10 -14
  49. data/rakelib/task_extension.rb +17 -31
  50. data/sample/array_insert.rb +7 -20
  51. data/sample/async_api.rb +54 -96
  52. data/sample/async_copyto.rb +20 -35
  53. data/sample/async_mixed.rb +22 -50
  54. data/sample/check_conn.rb +8 -20
  55. data/sample/copydata.rb +18 -68
  56. data/sample/copyfrom.rb +26 -78
  57. data/sample/copyto.rb +10 -16
  58. data/sample/cursor.rb +9 -19
  59. data/sample/disk_usage_report.rb +89 -174
  60. data/sample/issue-119.rb +45 -93
  61. data/sample/losample.rb +48 -66
  62. data/sample/minimal-testcase.rb +6 -17
  63. data/sample/notify_wait.rb +21 -67
  64. data/sample/pg_statistics.rb +100 -281
  65. data/sample/replication_monitor.rb +119 -218
  66. data/sample/test_binary_values.rb +14 -30
  67. data/sample/wal_shipper.rb +199 -431
  68. data/sample/warehouse_partitions.rb +157 -307
  69. data/translation/.po4a-version +7 -0
  70. data/translation/po/all.pot +875 -0
  71. data/translation/po/ja.po +868 -0
  72. data/translation/po4a.cfg +9 -0
  73. metadata +50 -28
  74. data/README.ja.rdoc +0 -13
  75. data/README.rdoc +0 -233
  76. data/lib/pg/basic_type_map_based_on_result.rb +0 -47
  77. data/lib/pg/basic_type_map_for_queries.rb +0 -193
  78. data/lib/pg/basic_type_map_for_results.rb +0 -81
  79. data/lib/pg/basic_type_registry.rb +0 -301
  80. data/lib/pg/binary_decoder.rb +0 -23
  81. data/lib/pg/coder.rb +0 -104
  82. data/lib/pg/connection.rb +0 -878
  83. data/lib/pg/constants.rb +0 -12
  84. data/lib/pg/exceptions.rb +0 -18
  85. data/lib/pg/result.rb +0 -43
  86. data/lib/pg/text_decoder.rb +0 -46
  87. data/lib/pg/text_encoder.rb +0 -59
  88. data/lib/pg/tuple.rb +0 -30
  89. data/lib/pg/type_map_by_column.rb +0 -16
  90. data/lib/pg/version.rb +0 -4
  91. data/lib/pg.rb +0 -55
@@ -1,285 +1,104 @@
1
- # -*- ruby -*-
2
- # vim: set noet nosta sw=4 ts=4 :
3
- #
4
- # PostgreSQL statistic gatherer.
5
- # Mahlon E. Smith <mahlon@martini.nu>
6
- #
7
- # Based on queries by Kenny Gorman.
8
- # http://www.kennygorman.com/wordpress/?page_id=491
9
- #
10
- # An example gnuplot input script is included in the __END__ block
11
- # of this script. Using it, you can feed the output this script
12
- # generates to gnuplot (after removing header lines) to generate
13
- # some nice performance charts.
14
- #
15
-
16
- require 'ostruct'
17
- require 'optparse'
18
- require 'etc'
19
- require 'pg'
20
-
21
-
22
- ### PostgreSQL Stats. Fetch information from pg_stat_* tables.
23
- ### Optionally run in a continuous loop, displaying deltas.
24
- ###
1
+ require("ostruct")
2
+ require("optparse")
3
+ require("etc")
4
+ require("cipherstash-pg")
25
5
  class Stats
26
- VERSION = %q$Id$
27
-
28
- def initialize( opts )
29
- @opts = opts
30
- @db = PG.connect(
31
- :dbname => opts.database,
32
- :host => opts.host,
33
- :port => opts.port,
34
- :user => opts.user,
35
- :password => opts.pass,
36
- :sslmode => 'prefer'
37
- )
38
- @last = nil
39
- end
40
-
41
- ######
42
- public
43
- ######
44
-
45
- ### Primary loop. Gather statistics and generate deltas.
46
- ###
47
- def run
48
- run_count = 0
49
-
50
- loop do
51
- current_stat = self.get_stats
52
-
53
- # First run, store and continue
54
- #
55
- if @last.nil?
56
- @last = current_stat
57
- sleep @opts.interval
58
- next
59
- end
60
-
61
- # headers
62
- #
63
- if run_count == 0 || run_count % 50 == 0
64
- puts "%-20s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s" % %w[
65
- time commits rollbks blksrd blkshit bkends seqscan
66
- seqtprd idxscn idxtrd ins upd del locks activeq
67
- ]
68
- end
69
-
70
- # calculate deltas
71
- #
72
- delta = current_stat.inject({}) do |h, pair|
73
- stat, val = *pair
74
-
75
- if %w[ activeq locks bkends ].include?( stat )
76
- h[stat] = current_stat[stat].to_i
77
- else
78
- h[stat] = current_stat[stat].to_i - @last[stat].to_i
79
- end
80
-
81
- h
82
- end
83
- delta[ 'time' ] = Time.now.strftime('%F %T')
84
-
85
- # new values
86
- #
87
- puts "%-20s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s" % [
88
- delta['time'], delta['commits'], delta['rollbks'], delta['blksrd'],
89
- delta['blkshit'], delta['bkends'], delta['seqscan'],
90
- delta['seqtprd'], delta['idxscn'], delta['idxtrd'],
91
- delta['ins'], delta['upd'], delta['del'], delta['locks'], delta['activeq']
92
- ]
93
-
94
- @last = current_stat
95
- run_count += 1
96
- sleep @opts.interval
97
- end
98
- end
99
-
100
-
101
- ### Query the database for performance measurements. Returns a hash.
102
- ###
103
- def get_stats
104
- res = @db.exec %Q{
105
- SELECT
106
- MAX(stat_db.xact_commit) AS commits,
107
- MAX(stat_db.xact_rollback) AS rollbks,
108
- MAX(stat_db.blks_read) AS blksrd,
109
- MAX(stat_db.blks_hit) AS blkshit,
110
- MAX(stat_db.numbackends) AS bkends,
111
- SUM(stat_tables.seq_scan) AS seqscan,
112
- SUM(stat_tables.seq_tup_read) AS seqtprd,
113
- SUM(stat_tables.idx_scan) AS idxscn,
114
- SUM(stat_tables.idx_tup_fetch) AS idxtrd,
115
- SUM(stat_tables.n_tup_ins) AS ins,
116
- SUM(stat_tables.n_tup_upd) AS upd,
117
- SUM(stat_tables.n_tup_del) AS del,
118
- MAX(stat_locks.locks) AS locks,
119
- MAX(activity.sess) AS activeq
120
- FROM
121
- pg_stat_database AS stat_db,
122
- pg_stat_user_tables AS stat_tables,
123
- (SELECT COUNT(*) AS locks FROM pg_locks ) AS stat_locks,
124
- (SELECT COUNT(*) AS sess FROM pg_stat_activity WHERE current_query <> '<IDLE>') AS activity
125
- WHERE
126
- stat_db.datname = '%s';
127
- } % [ @opts.database ]
128
-
129
- return res[0]
130
- end
6
+ VERSION = "Id"
7
+
8
+ def initialize(opts)
9
+ @opts = opts
10
+ @db = CipherStashPG.connect(:dbname => opts.database, :host => opts.host, :port => opts.port, :user => opts.user, :password => opts.pass, :sslmode => "prefer")
11
+ @last = nil
12
+ end
13
+
14
+ public
15
+
16
+ def run
17
+ run_count = 0
18
+ loop do
19
+ current_stat = self.get_stats
20
+ if @last.nil? then
21
+ @last = current_stat
22
+ sleep(@opts.interval)
23
+ next
24
+ end
25
+ if ((run_count == 0) or ((run_count % 50) == 0)) then
26
+ puts(("%-20s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s" % ["time", "commits", "rollbks", "blksrd", "blkshit", "bkends", "seqscan", "seqtprd", "idxscn", "idxtrd", "ins", "upd", "del", "locks", "activeq"]))
27
+ end
28
+ delta = current_stat.inject({}) do |h, pair|
29
+ stat, val = *pair
30
+ if ["activeq", "locks", "bkends"].include?(stat) then
31
+ h[stat] = current_stat[stat].to_i
32
+ else
33
+ h[stat] = (current_stat[stat].to_i - @last[stat].to_i)
34
+ end
35
+ h
36
+ end
37
+ delta["time"] = Time.now.strftime("%F %T")
38
+ puts(("%-20s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s" % [delta["time"], delta["commits"], delta["rollbks"], delta["blksrd"], delta["blkshit"], delta["bkends"], delta["seqscan"], delta["seqtprd"], delta["idxscn"], delta["idxtrd"], delta["ins"], delta["upd"], delta["del"], delta["locks"], delta["activeq"]]))
39
+ @last = current_stat
40
+ run_count = (run_count + 1)
41
+ sleep(@opts.interval)
42
+ end
43
+ end
44
+
45
+ def get_stats
46
+ res = @db.exec(("\n\t\t\tSELECT\n\t\t\t\tMAX(stat_db.xact_commit) AS commits,\n\t\t\t\tMAX(stat_db.xact_rollback) AS rollbks,\n\t\t\t\tMAX(stat_db.blks_read) AS blksrd,\n\t\t\t\tMAX(stat_db.blks_hit) AS blkshit,\n\t\t\t\tMAX(stat_db.numbackends) AS bkends,\n\t\t\t\tSUM(stat_tables.seq_scan) AS seqscan,\n\t\t\t\tSUM(stat_tables.seq_tup_read) AS seqtprd,\n\t\t\t\tSUM(stat_tables.idx_scan) AS idxscn,\n\t\t\t\tSUM(stat_tables.idx_tup_fetch) AS idxtrd,\n\t\t\t\tSUM(stat_tables.n_tup_ins) AS ins,\n\t\t\t\tSUM(stat_tables.n_tup_upd) AS upd,\n\t\t\t\tSUM(stat_tables.n_tup_del) AS del,\n\t\t\t\tMAX(stat_locks.locks) AS locks,\n\t\t\t\tMAX(activity.sess) AS activeq\n\t\t\tFROM\n\t\t\t\tpg_stat_database AS stat_db,\n\t\t\t\tpg_stat_user_tables AS stat_tables,\n\t\t\t\t(SELECT COUNT(*) AS locks FROM pg_locks ) AS stat_locks,\n\t\t\t\t(SELECT COUNT(*) AS sess FROM pg_stat_activity WHERE current_query <> '<IDLE>') AS activity\n\t\t\tWHERE\n\t\t\t\tstat_db.datname = '%s';\n\t\t" % [@opts.database]))
47
+ return res[0]
48
+ end
131
49
  end
132
-
133
-
134
- ### Parse command line arguments. Return a struct of global options.
135
- ###
136
- def parse_args( args )
137
- options = OpenStruct.new
138
- options.database = Etc.getpwuid( Process.uid ).name
139
- options.host = '127.0.0.1'
140
- options.port = 5432
141
- options.user = Etc.getpwuid( Process.uid ).name
142
- options.sslmode = 'disable'
143
- options.interval = 5
144
-
145
- opts = OptionParser.new do |opts|
146
- opts.banner = "Usage: #{$0} [options]"
147
-
148
- opts.separator ''
149
- opts.separator 'Connection options:'
150
-
151
- opts.on( '-d', '--database DBNAME',
152
- "specify the database to connect to (default: \"#{options.database}\")" ) do |db|
153
- options.database = db
154
- end
155
-
156
- opts.on( '-h', '--host HOSTNAME', 'database server host' ) do |host|
157
- options.host = host
158
- end
159
-
160
- opts.on( '-p', '--port PORT', Integer,
161
- "database server port (default: \"#{options.port}\")" ) do |port|
162
- options.port = port
163
- end
164
-
165
- opts.on( '-U', '--user NAME',
166
- "database user name (default: \"#{options.user}\")" ) do |user|
167
- options.user = user
168
- end
169
-
170
- opts.on( '-W', 'force password prompt' ) do |pw|
171
- print 'Password: '
172
- begin
173
- system 'stty -echo'
174
- options.pass = gets.chomp
175
- ensure
176
- system 'stty echo'
177
- puts
178
- end
179
- end
180
-
181
- opts.separator ''
182
- opts.separator 'Other options:'
183
-
184
- opts.on( '-i', '--interval SECONDS', Integer,
185
- "refresh interval in seconds (default: \"#{options.interval}\")") do |seconds|
186
- options.interval = seconds
187
- end
188
-
189
- opts.on_tail( '--help', 'show this help, then exit' ) do
190
- $stderr.puts opts
191
- exit
192
- end
193
-
194
- opts.on_tail( '--version', 'output version information, then exit' ) do
195
- puts Stats::VERSION
196
- exit
197
- end
198
- end
199
-
200
- opts.parse!( args )
201
- return options
50
+ def parse_args(args)
51
+ options = OpenStruct.new
52
+ options.database = Etc.getpwuid(Process.uid).name
53
+ options.host = "127.0.0.1"
54
+ options.port = 5432
55
+ options.user = Etc.getpwuid(Process.uid).name
56
+ options.sslmode = "disable"
57
+ options.interval = 5
58
+ opts = OptionParser.new do |opts|
59
+ opts.banner = "Usage: #{$0} [options]"
60
+ opts.separator("")
61
+ opts.separator("Connection options:")
62
+ opts.on("-d", "--database DBNAME", "specify the database to connect to (default: \"#{options.database}\")") do |db|
63
+ options.database = db
64
+ end
65
+ opts.on("-h", "--host HOSTNAME", "database server host") do |host|
66
+ options.host = host
67
+ end
68
+ opts.on("-p", "--port PORT", Integer, "database server port (default: \"#{options.port}\")") do |port|
69
+ options.port = port
70
+ end
71
+ opts.on("-U", "--user NAME", "database user name (default: \"#{options.user}\")") do |user|
72
+ options.user = user
73
+ end
74
+ opts.on("-W", "force password prompt") do |pw|
75
+ print("Password: ")
76
+ begin
77
+ (system("stty -echo")
78
+ options.pass = gets.chomp)
79
+ ensure
80
+ (system("stty echo")
81
+ puts)
82
+ end
83
+ end
84
+ opts.separator("")
85
+ opts.separator("Other options:")
86
+ opts.on("-i", "--interval SECONDS", Integer, "refresh interval in seconds (default: \"#{options.interval}\")") do |seconds|
87
+ options.interval = seconds
88
+ end
89
+ opts.on_tail("--help", "show this help, then exit") do
90
+ $stderr.puts(opts)
91
+ exit
92
+ end
93
+ opts.on_tail("--version", "output version information, then exit") do
94
+ puts(Stats::VERSION)
95
+ exit
96
+ end
97
+ end
98
+ opts.parse!(args)
99
+ return options
202
100
  end
203
-
204
-
205
- ### Go!
206
- ###
207
- if __FILE__ == $0
208
- $stdout.sync = true
209
- Stats.new( parse_args( ARGV ) ).run
101
+ if ("(string)" == $0) then
102
+ $stdout.sync = true
103
+ Stats.new(parse_args(ARGV)).run
210
104
  end
211
-
212
-
213
- __END__
214
- ######################################################################
215
- ### T E R M I N A L O P T I O N S
216
- ######################################################################
217
-
218
- #set terminal png nocrop enhanced font arial 8 size '800x600' x000000 xffffff x444444
219
- #set output 'graph.png'
220
-
221
- set terminal pdf linewidth 4 size 11,8
222
- set output 'graph.pdf'
223
-
224
- #set terminal aqua
225
-
226
-
227
- ######################################################################
228
- ### O P T I O N S F O R A L L G R A P H S
229
- ######################################################################
230
-
231
- set multiplot layout 2,1 title "PostgreSQL Statistics\n5 second sample rate (smoothed)"
232
-
233
- set grid x y
234
- set key right vertical outside
235
- set key nobox
236
- set xdata time
237
- set timefmt "%Y-%m-%d.%H:%M:%S"
238
- set format x "%l%p"
239
- set xtic rotate by -45
240
- input_file = "database_stats.txt"
241
-
242
- # edit to taste!
243
- set xrange ["2012-04-16.00:00:00":"2012-04-17.00:00:00"]
244
-
245
-
246
- ######################################################################
247
- ### G R A P H 1
248
- ######################################################################
249
-
250
- set title "Database Operations and Connection Totals"
251
- set yrange [0:200]
252
-
253
- plot \
254
- input_file using 1:2 title "Commits" with lines smooth bezier, \
255
- input_file using 1:3 title "Rollbacks" with lines smooth bezier, \
256
- input_file using 1:11 title "Inserts" with lines smooth bezier, \
257
- input_file using 1:12 title "Updates" with lines smooth bezier, \
258
- input_file using 1:13 title "Deletes" with lines smooth bezier, \
259
- input_file using 1:6 title "Backends (total)" with lines, \
260
- input_file using 1:15 title "Active queries (total)" with lines smooth bezier
261
-
262
-
263
- ######################################################################
264
- ### G R A P H 2
265
- ######################################################################
266
-
267
- set title "Backend Performance"
268
- set yrange [0:10000]
269
-
270
- plot \
271
- input_file using 1:4 title "Block (cache) reads" with lines smooth bezier, \
272
- input_file using 1:5 title "Block (cache) hits" with lines smooth bezier, \
273
- input_file using 1:7 title "Sequence scans" with lines smooth bezier, \
274
- input_file using 1:8 title "Sequence tuple reads" with lines smooth bezier, \
275
- input_file using 1:9 title "Index scans" with lines smooth bezier, \
276
- input_file using 1:10 title "Index tuple reads" with lines smooth bezier
277
-
278
-
279
- ######################################################################
280
- ### C L E A N U P
281
- ######################################################################
282
-
283
- unset multiplot
284
- reset
285
-