cipherstash-pg 1.0.0.beta.1-x86_64-linux → 1.0.0.beta.4-x86_64-linux
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/.appveyor.yml +42 -0
- data/.gems +6 -0
- data/.gemtest +0 -0
- data/.github/workflows/binary-gems.yml +117 -0
- data/.github/workflows/source-gem.yml +137 -0
- data/.gitignore +19 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +45 -0
- data/{History.rdoc → History.md} +168 -153
- data/README.ja.md +266 -0
- data/README.md +272 -0
- data/Rakefile +65 -104
- data/Rakefile.cross +298 -0
- data/certs/larskanis-2023.pem +24 -0
- data/cipherstash-pg.gemspec +0 -0
- data/lib/2.7/pg_ext.so +0 -0
- data/lib/3.0/pg_ext.so +0 -0
- data/lib/3.1/pg_ext.so +0 -0
- data/lib/3.2/pg_ext.so +0 -0
- data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
- data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
- data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
- data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
- data/lib/cipherstash-pg/binary_decoder.rb +21 -0
- data/lib/cipherstash-pg/coder.rb +82 -0
- data/lib/cipherstash-pg/connection.rb +467 -0
- data/lib/cipherstash-pg/constants.rb +3 -0
- data/lib/cipherstash-pg/exceptions.rb +19 -0
- data/lib/cipherstash-pg/result.rb +22 -0
- data/lib/cipherstash-pg/text_decoder.rb +43 -0
- data/lib/cipherstash-pg/text_encoder.rb +67 -0
- data/lib/cipherstash-pg/tuple.rb +24 -0
- data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
- data/lib/cipherstash-pg/version.rb +3 -0
- data/lib/cipherstash-pg.rb +56 -11
- data/lib/libpq.so.5 +0 -0
- data/misc/openssl-pg-segfault.rb +15 -25
- data/misc/postgres/Rakefile +13 -20
- data/misc/postgres/lib/postgres.rb +10 -14
- data/misc/ruby-pg/Rakefile +13 -20
- data/misc/ruby-pg/lib/ruby/pg.rb +10 -14
- data/rakelib/task_extension.rb +17 -31
- data/sample/array_insert.rb +7 -20
- data/sample/async_api.rb +54 -96
- data/sample/async_copyto.rb +20 -35
- data/sample/async_mixed.rb +22 -50
- data/sample/check_conn.rb +8 -20
- data/sample/copydata.rb +18 -68
- data/sample/copyfrom.rb +26 -78
- data/sample/copyto.rb +10 -16
- data/sample/cursor.rb +9 -19
- data/sample/disk_usage_report.rb +89 -174
- data/sample/issue-119.rb +45 -93
- data/sample/losample.rb +48 -66
- data/sample/minimal-testcase.rb +6 -17
- data/sample/notify_wait.rb +21 -67
- data/sample/pg_statistics.rb +100 -281
- data/sample/replication_monitor.rb +119 -218
- data/sample/test_binary_values.rb +14 -30
- data/sample/wal_shipper.rb +199 -431
- data/sample/warehouse_partitions.rb +157 -307
- data/translation/.po4a-version +7 -0
- data/translation/po/all.pot +875 -0
- data/translation/po/ja.po +868 -0
- data/translation/po4a.cfg +9 -0
- metadata +50 -28
- data/README.ja.rdoc +0 -13
- data/README.rdoc +0 -233
- data/lib/pg/basic_type_map_based_on_result.rb +0 -47
- data/lib/pg/basic_type_map_for_queries.rb +0 -193
- data/lib/pg/basic_type_map_for_results.rb +0 -81
- data/lib/pg/basic_type_registry.rb +0 -301
- data/lib/pg/binary_decoder.rb +0 -23
- data/lib/pg/coder.rb +0 -104
- data/lib/pg/connection.rb +0 -878
- data/lib/pg/constants.rb +0 -12
- data/lib/pg/exceptions.rb +0 -18
- data/lib/pg/result.rb +0 -43
- data/lib/pg/text_decoder.rb +0 -46
- data/lib/pg/text_encoder.rb +0 -59
- data/lib/pg/tuple.rb +0 -30
- data/lib/pg/type_map_by_column.rb +0 -16
- data/lib/pg/version.rb +0 -4
- data/lib/pg.rb +0 -55
data/sample/check_conn.rb
CHANGED
@@ -1,21 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# This is a minimal example of a function that can test an existing PG::Connection and
|
8
|
-
# reset it if necessary.
|
9
|
-
|
10
|
-
def check_connection( conn )
|
11
|
-
begin
|
12
|
-
conn.exec( "SELECT 1" )
|
13
|
-
rescue PG::Error => err
|
14
|
-
$stderr.puts "%p while testing connection: %s" % [ err.class, err.message ]
|
15
|
-
conn.reset
|
16
|
-
end
|
1
|
+
require("cipherstash-pg")
|
2
|
+
def check_connection(conn)
|
3
|
+
conn.exec("SELECT 1")
|
4
|
+
rescue CipherStashPG::Error => err
|
5
|
+
$stderr.puts(("%p while testing connection: %s" % [err.class, err.message]))
|
6
|
+
conn.reset
|
17
7
|
end
|
18
|
-
|
19
|
-
conn
|
20
|
-
check_connection( conn )
|
21
|
-
|
8
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
9
|
+
check_connection(conn)
|
data/sample/copydata.rb
CHANGED
@@ -1,71 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
conn.exec( <<END_SQL )
|
10
|
-
DROP TABLE IF EXISTS logs;
|
11
|
-
CREATE TABLE logs (
|
12
|
-
client_ip inet,
|
13
|
-
username text,
|
14
|
-
ts timestamp,
|
15
|
-
request text,
|
16
|
-
status smallint,
|
17
|
-
bytes int
|
18
|
-
);
|
19
|
-
END_SQL
|
20
|
-
|
21
|
-
csv_io = StringIO.new( <<"END_DATA" )
|
22
|
-
"127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /manual/ HTTP/1.1",404,205
|
23
|
-
"127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /favicon.ico HTTP/1.1",404,209
|
24
|
-
"127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /favicon.ico HTTP/1.1",404,209
|
25
|
-
"127.0.0.1","","30/Aug/2010:08:22:29 -0700","GET /manual/ HTTP/1.1",200,11094
|
26
|
-
"127.0.0.1","","30/Aug/2010:08:22:38 -0700","GET /manual/index.html HTTP/1.1",200,725
|
27
|
-
"127.0.0.1","","30/Aug/2010:08:27:56 -0700","GET /manual/ HTTP/1.1",200,11094
|
28
|
-
"127.0.0.1","","30/Aug/2010:08:27:57 -0700","GET /manual/ HTTP/1.1",200,11094
|
29
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/index.html HTTP/1.1",200,7709
|
30
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/feather.gif HTTP/1.1",200,6471
|
31
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/left.gif HTTP/1.1",200,60
|
32
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual.css HTTP/1.1",200,18674
|
33
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual-print.css HTTP/1.1",200,13200
|
34
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/favicon.ico HTTP/1.1",200,1078
|
35
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual-loose-100pc.css HTTP/1.1",200,3065
|
36
|
-
"127.0.0.1","","30/Aug/2010:08:28:14 -0700","OPTIONS * HTTP/1.0",200,0
|
37
|
-
"127.0.0.1","","30/Aug/2010:08:28:15 -0700","OPTIONS * HTTP/1.0",200,0
|
38
|
-
"127.0.0.1","","30/Aug/2010:08:28:47 -0700","GET /manual/mod/directives.html HTTP/1.1",200,33561
|
39
|
-
"127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/mod/mpm_common.html HTTP/1.1",200,67683
|
40
|
-
"127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/images/down.gif HTTP/1.1",200,56
|
41
|
-
"127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/images/up.gif HTTP/1.1",200,57
|
42
|
-
"127.0.0.1","","30/Aug/2010:09:19:58 -0700","GET /manual/mod/mod_log_config.html HTTP/1.1",200,28307
|
43
|
-
"127.0.0.1","","30/Aug/2010:09:20:19 -0700","GET /manual/mod/core.html HTTP/1.1",200,194144
|
44
|
-
"127.0.0.1","","30/Aug/2010:16:02:56 -0700","GET /manual/ HTTP/1.1",200,11094
|
45
|
-
"127.0.0.1","","30/Aug/2010:16:03:00 -0700","GET /manual/ HTTP/1.1",200,11094
|
46
|
-
"127.0.0.1","","30/Aug/2010:16:06:16 -0700","GET /manual/mod/mod_dir.html HTTP/1.1",200,10583
|
47
|
-
"127.0.0.1","","30/Aug/2010:16:06:44 -0700","GET /manual/ HTTP/1.1",200,7709
|
48
|
-
END_DATA
|
49
|
-
|
50
|
-
### You can test the error case from the database side easily by
|
51
|
-
### changing one of the numbers at the end of one of the above rows to
|
52
|
-
### something non-numeric like "-".
|
53
|
-
|
54
|
-
$stderr.puts "Running COPY command with data ..."
|
55
|
-
buf = ''
|
1
|
+
require("cipherstash-pg")
|
2
|
+
require("stringio")
|
3
|
+
$stderr.puts("Opening database connection ...")
|
4
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
5
|
+
conn.exec("DROP TABLE IF EXISTS logs;\nCREATE TABLE logs (\n\tclient_ip inet,\n\tusername text,\n\tts timestamp,\n\trequest text,\n\tstatus smallint,\n\tbytes int\n);\n")
|
6
|
+
csv_io = StringIO.new("\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /manual/ HTTP/1.1\",404,205\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /favicon.ico HTTP/1.1\",404,209\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /favicon.ico HTTP/1.1\",404,209\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:22:29 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:22:38 -0700\",\"GET /manual/index.html HTTP/1.1\",200,725\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:27:56 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:27:57 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/index.html HTTP/1.1\",200,7709\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/feather.gif HTTP/1.1\",200,6471\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/left.gif HTTP/1.1\",200,60\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual.css HTTP/1.1\",200,18674\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual-print.css HTTP/1.1\",200,13200\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/favicon.ico HTTP/1.1\",200,1078\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual-loose-100pc.css HTTP/1.1\",200,3065\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:14 -0700\",\"OPTIONS * HTTP/1.0\",200,0\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:15 -0700\",\"OPTIONS * HTTP/1.0\",200,0\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:47 -0700\",\"GET /manual/mod/directives.html HTTP/1.1\",200,33561\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/mod/mpm_common.html HTTP/1.1\",200,67683\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/images/down.gif HTTP/1.1\",200,56\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/images/up.gif HTTP/1.1\",200,57\n\"127.0.0.1\",\"\",\"30/Aug/2010:09:19:58 -0700\",\"GET /manual/mod/mod_log_config.html HTTP/1.1\",200,28307\n\"127.0.0.1\",\"\",\"30/Aug/2010:09:20:19 -0700\",\"GET /manual/mod/core.html HTTP/1.1\",200,194144\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:02:56 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:03:00 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:06:16 -0700\",\"GET /manual/mod/mod_dir.html HTTP/1.1\",200,10583\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:06:44 -0700\",\"GET /manual/ HTTP/1.1\",200,7709\n")
|
7
|
+
$stderr.puts("Running COPY command with data ...")
|
8
|
+
buf = ""
|
56
9
|
conn.transaction do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
10
|
+
res = conn.copy_data("COPY logs FROM STDIN WITH csv") do
|
11
|
+
$stderr.print("Sending lines... ")
|
12
|
+
csv_io.each_line.with_index do |buf, i|
|
13
|
+
$stderr.print("#{(i + 1)} ")
|
14
|
+
conn.put_copy_data(buf)
|
15
|
+
end
|
16
|
+
$stderr.puts("done.")
|
17
|
+
end
|
18
|
+
$stderr.puts(("Result of COPY is: %s" % [res.res_status(res.result_status)]))
|
19
|
+
$stderr.puts((" tuples copied: %p" % [res.cmd_tuples]))
|
67
20
|
end
|
68
|
-
|
69
|
-
|
70
21
|
conn.finish
|
71
|
-
|
data/sample/copyfrom.rb
CHANGED
@@ -1,81 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
conn.exec( <<END_SQL )
|
10
|
-
DROP TABLE IF EXISTS logs;
|
11
|
-
CREATE TABLE logs (
|
12
|
-
client_ip inet,
|
13
|
-
username text,
|
14
|
-
ts timestamp,
|
15
|
-
request text,
|
16
|
-
status smallint,
|
17
|
-
bytes int
|
18
|
-
);
|
19
|
-
END_SQL
|
20
|
-
|
21
|
-
copy_data = StringIO.new( <<"END_DATA" )
|
22
|
-
"127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /manual/ HTTP/1.1",404,205
|
23
|
-
"127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /favicon.ico HTTP/1.1",404,209
|
24
|
-
"127.0.0.1","","30/Aug/2010:08:21:24 -0700","GET /favicon.ico HTTP/1.1",404,209
|
25
|
-
"127.0.0.1","","30/Aug/2010:08:22:29 -0700","GET /manual/ HTTP/1.1",200,11094
|
26
|
-
"127.0.0.1","","30/Aug/2010:08:22:38 -0700","GET /manual/index.html HTTP/1.1",200,725
|
27
|
-
"127.0.0.1","","30/Aug/2010:08:27:56 -0700","GET /manual/ HTTP/1.1",200,11094
|
28
|
-
"127.0.0.1","","30/Aug/2010:08:27:57 -0700","GET /manual/ HTTP/1.1",200,11094
|
29
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/index.html HTTP/1.1",200,7709
|
30
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/feather.gif HTTP/1.1",200,6471
|
31
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/left.gif HTTP/1.1",200,60
|
32
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual.css HTTP/1.1",200,18674
|
33
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual-print.css HTTP/1.1",200,13200
|
34
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/images/favicon.ico HTTP/1.1",200,1078
|
35
|
-
"127.0.0.1","","30/Aug/2010:08:28:06 -0700","GET /manual/style/css/manual-loose-100pc.css HTTP/1.1",200,3065
|
36
|
-
"127.0.0.1","","30/Aug/2010:08:28:14 -0700","OPTIONS * HTTP/1.0",200,0
|
37
|
-
"127.0.0.1","","30/Aug/2010:08:28:15 -0700","OPTIONS * HTTP/1.0",200,0
|
38
|
-
"127.0.0.1","","30/Aug/2010:08:28:47 -0700","GET /manual/mod/directives.html HTTP/1.1",200,33561
|
39
|
-
"127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/mod/mpm_common.html HTTP/1.1",200,67683
|
40
|
-
"127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/images/down.gif HTTP/1.1",200,56
|
41
|
-
"127.0.0.1","","30/Aug/2010:08:28:53 -0700","GET /manual/images/up.gif HTTP/1.1",200,57
|
42
|
-
"127.0.0.1","","30/Aug/2010:09:19:58 -0700","GET /manual/mod/mod_log_config.html HTTP/1.1",200,28307
|
43
|
-
"127.0.0.1","","30/Aug/2010:09:20:19 -0700","GET /manual/mod/core.html HTTP/1.1",200,194144
|
44
|
-
"127.0.0.1","","30/Aug/2010:16:02:56 -0700","GET /manual/ HTTP/1.1",200,11094
|
45
|
-
"127.0.0.1","","30/Aug/2010:16:03:00 -0700","GET /manual/ HTTP/1.1",200,11094
|
46
|
-
"127.0.0.1","","30/Aug/2010:16:06:16 -0700","GET /manual/mod/mod_dir.html HTTP/1.1",200,10583
|
47
|
-
"127.0.0.1","","30/Aug/2010:16:06:44 -0700","GET /manual/ HTTP/1.1",200,7709
|
48
|
-
END_DATA
|
49
|
-
|
50
|
-
### You can test the error case from the database side easily by
|
51
|
-
### changing one of the numbers at the end of one of the above rows to
|
52
|
-
### something non-numeric like "-".
|
53
|
-
|
54
|
-
$stderr.puts "Running COPY command with data ..."
|
55
|
-
buf = ''
|
1
|
+
require("cipherstash-pg")
|
2
|
+
require("stringio")
|
3
|
+
$stderr.puts("Opening database connection ...")
|
4
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
5
|
+
conn.exec("DROP TABLE IF EXISTS logs;\nCREATE TABLE logs (\n\tclient_ip inet,\n\tusername text,\n\tts timestamp,\n\trequest text,\n\tstatus smallint,\n\tbytes int\n);\n")
|
6
|
+
copy_data = StringIO.new("\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /manual/ HTTP/1.1\",404,205\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /favicon.ico HTTP/1.1\",404,209\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /favicon.ico HTTP/1.1\",404,209\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:22:29 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:22:38 -0700\",\"GET /manual/index.html HTTP/1.1\",200,725\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:27:56 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:27:57 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/index.html HTTP/1.1\",200,7709\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/feather.gif HTTP/1.1\",200,6471\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/left.gif HTTP/1.1\",200,60\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual.css HTTP/1.1\",200,18674\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual-print.css HTTP/1.1\",200,13200\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/favicon.ico HTTP/1.1\",200,1078\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual-loose-100pc.css HTTP/1.1\",200,3065\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:14 -0700\",\"OPTIONS * HTTP/1.0\",200,0\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:15 -0700\",\"OPTIONS * HTTP/1.0\",200,0\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:47 -0700\",\"GET /manual/mod/directives.html HTTP/1.1\",200,33561\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/mod/mpm_common.html HTTP/1.1\",200,67683\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/images/down.gif HTTP/1.1\",200,56\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/images/up.gif HTTP/1.1\",200,57\n\"127.0.0.1\",\"\",\"30/Aug/2010:09:19:58 -0700\",\"GET /manual/mod/mod_log_config.html HTTP/1.1\",200,28307\n\"127.0.0.1\",\"\",\"30/Aug/2010:09:20:19 -0700\",\"GET /manual/mod/core.html HTTP/1.1\",200,194144\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:02:56 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:03:00 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:06:16 -0700\",\"GET /manual/mod/mod_dir.html HTTP/1.1\",200,10583\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:06:44 -0700\",\"GET /manual/ HTTP/1.1\",200,7709\n")
|
7
|
+
$stderr.puts("Running COPY command with data ...")
|
8
|
+
buf = ""
|
56
9
|
conn.transaction do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
10
|
+
conn.exec("COPY logs FROM STDIN WITH csv")
|
11
|
+
begin
|
12
|
+
while copy_data.read(256, buf) do
|
13
|
+
$stderr.puts(("\tsending %d bytes of data..." % [buf.length]))
|
14
|
+
until conn.put_copy_data(buf) do
|
15
|
+
($stderr.puts("\twaiting for connection to be writable...")
|
16
|
+
sleep(0.1))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
rescue Errno => err
|
20
|
+
errmsg = ("%s while reading copy data: %s" % [err.class.name, err.message])
|
21
|
+
conn.put_copy_end(errmsg)
|
22
|
+
else
|
23
|
+
(conn.put_copy_end
|
24
|
+
while res = conn.get_result do
|
25
|
+
$stderr.puts(("Result of COPY is: %s" % [res.res_status(res.result_status)]))
|
26
|
+
end)
|
27
|
+
end
|
77
28
|
end
|
78
|
-
|
79
|
-
|
80
29
|
conn.finish
|
81
|
-
|
data/sample/copyto.rb
CHANGED
@@ -1,19 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
$stderr.puts "Opening database connection ..."
|
9
|
-
conn = PG.connect( :dbname => 'test' )
|
10
|
-
|
11
|
-
$stderr.puts "Running COPY command ..."
|
12
|
-
buf = ''
|
1
|
+
require("cipherstash-pg")
|
2
|
+
require("stringio")
|
3
|
+
$stderr.puts("Opening database connection ...")
|
4
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
5
|
+
$stderr.puts("Running COPY command ...")
|
6
|
+
buf = ""
|
13
7
|
conn.transaction do
|
14
|
-
|
15
|
-
|
8
|
+
conn.exec("COPY logs TO STDOUT WITH csv")
|
9
|
+
while buf = conn.get_copy_data do
|
10
|
+
$stdout.puts(buf)
|
11
|
+
end
|
16
12
|
end
|
17
|
-
|
18
13
|
conn.finish
|
19
|
-
|
data/sample/cursor.rb
CHANGED
@@ -1,21 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# An example of how to use SQL cursors. This is mostly a straight port of
|
6
|
-
# the cursor portion of testlibpq.c from src/test/examples.
|
7
|
-
|
8
|
-
$stderr.puts "Opening database connection ..."
|
9
|
-
conn = PG.connect( :dbname => 'test' )
|
10
|
-
|
11
|
-
#
|
1
|
+
require("cipherstash-pg")
|
2
|
+
$stderr.puts("Opening database connection ...")
|
3
|
+
conn = CipherStashPG.connect(:dbname => "test")
|
12
4
|
conn.transaction do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
5
|
+
conn.exec("DECLARE myportal CURSOR FOR select * from pg_database")
|
6
|
+
res = conn.exec("FETCH ALL IN myportal")
|
7
|
+
puts(res.fields.collect { |fname| ("%-15s" % [fname]) }.join(""))
|
8
|
+
res.values.collect do |row|
|
9
|
+
puts(row.collect { |col| ("%-15s" % [col]) }.join(""))
|
10
|
+
end
|
20
11
|
end
|
21
|
-
|
data/sample/disk_usage_report.rb
CHANGED
@@ -1,177 +1,92 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
pg_class
|
41
|
-
}
|
42
|
-
|
43
|
-
puts '=' * 70
|
44
|
-
puts "Disk usage information for %s: (%d relations, %s total)" % [
|
45
|
-
opts.database,
|
46
|
-
db_info[0]['num_relations'],
|
47
|
-
db_info[0]['dbsize']
|
48
|
-
]
|
49
|
-
puts '=' * 70
|
50
|
-
|
51
|
-
# -----------------------------------------
|
52
|
-
|
53
|
-
top_twenty = db.exec %q{
|
54
|
-
SELECT
|
55
|
-
relname AS name,
|
56
|
-
relkind AS kind,
|
57
|
-
pg_size_pretty(pg_relation_size(pg_class.oid)) AS size
|
58
|
-
FROM
|
59
|
-
pg_class
|
60
|
-
ORDER BY
|
61
|
-
pg_relation_size(pg_class.oid) DESC
|
62
|
-
LIMIT 20
|
63
|
-
}
|
64
|
-
|
65
|
-
puts 'Top twenty objects by size:'
|
66
|
-
puts '-' * 70
|
67
|
-
top_twenty.each do |row|
|
68
|
-
type = case row['kind']
|
69
|
-
when 'i'; 'index'
|
70
|
-
when 't'; 'toast'
|
71
|
-
when 'r'; 'table'
|
72
|
-
when 'S'; 'sequence'
|
73
|
-
else; '???'
|
74
|
-
end
|
75
|
-
|
76
|
-
puts "%40s %10s (%s)" % [ row['name'], row['size'], type ]
|
77
|
-
end
|
78
|
-
puts '-' * 70
|
79
|
-
|
80
|
-
# -----------------------------------------
|
81
|
-
|
82
|
-
schema_sizes = db.exec %q{
|
83
|
-
SELECT
|
84
|
-
table_schema,
|
85
|
-
pg_size_pretty( CAST( SUM(pg_total_relation_size(table_schema || '.' || table_name)) AS bigint)) AS size
|
86
|
-
FROM
|
87
|
-
information_schema.tables
|
88
|
-
GROUP BY
|
89
|
-
table_schema
|
90
|
-
ORDER BY
|
91
|
-
CAST( SUM(pg_total_relation_size(table_schema || '.' || table_name)) AS bigint ) DESC
|
92
|
-
}
|
93
|
-
|
94
|
-
|
95
|
-
puts 'Size per schema:'
|
96
|
-
puts '-' * 70
|
97
|
-
schema_sizes.each do |row|
|
98
|
-
puts "%20s %10s" % [ row['table_schema'], row['size'] ]
|
99
|
-
end
|
100
|
-
puts '-' * 70
|
101
|
-
puts
|
102
|
-
|
103
|
-
db.finish
|
1
|
+
require("ostruct")
|
2
|
+
require("optparse")
|
3
|
+
require("etc")
|
4
|
+
require("cipherstash-pg")
|
5
|
+
SCRIPT_VERSION = "Id"
|
6
|
+
def report(opts)
|
7
|
+
db = CipherStashPG.connect(:dbname => opts.database, :host => opts.host, :port => opts.port, :user => opts.user, :password => opts.pass, :sslmode => "prefer")
|
8
|
+
db_info = db.exec("\n\t\tSELECT\n\t\t\tcount(oid) AS num_relations,\n\t\t\tpg_size_pretty(pg_database_size('#{opts.database}')) AS dbsize\n\t\tFROM\n\t\t\tpg_class\n\t")
|
9
|
+
puts(("=" * 70))
|
10
|
+
puts(("Disk usage information for %s: (%d relations, %s total)" % [opts.database, db_info[0]["num_relations"], db_info[0]["dbsize"]]))
|
11
|
+
puts(("=" * 70))
|
12
|
+
top_twenty = db.exec("\n\t\tSELECT\n\t\t\trelname AS name,\n\t\t\trelkind AS kind,\n\t\t\tpg_size_pretty(pg_relation_size(pg_class.oid)) AS size\n\t\tFROM\n\t\t\tpg_class\n\t\tORDER BY\n\t\t\tpg_relation_size(pg_class.oid) DESC\n\t\tLIMIT 20\n\t")
|
13
|
+
puts("Top twenty objects by size:")
|
14
|
+
puts(("-" * 70))
|
15
|
+
top_twenty.each do |row|
|
16
|
+
type = case row["kind"]
|
17
|
+
when "i" then
|
18
|
+
"index"
|
19
|
+
when "t" then
|
20
|
+
"toast"
|
21
|
+
when "r" then
|
22
|
+
"table"
|
23
|
+
when "S" then
|
24
|
+
"sequence"
|
25
|
+
else
|
26
|
+
"???"
|
27
|
+
end
|
28
|
+
puts(("%40s %10s (%s)" % [row["name"], row["size"], type]))
|
29
|
+
end
|
30
|
+
puts(("-" * 70))
|
31
|
+
schema_sizes = db.exec("\n\t\tSELECT\n\t\t\ttable_schema,\n\t\t\tpg_size_pretty( CAST( SUM(pg_total_relation_size(table_schema || '.' || table_name)) AS bigint)) AS size\n\t\tFROM\n\t\t\tinformation_schema.tables\n\t\tGROUP BY\n\t\t\ttable_schema\n\t\tORDER BY\n\t\t\tCAST( SUM(pg_total_relation_size(table_schema || '.' || table_name)) AS bigint ) DESC\n\t")
|
32
|
+
puts("Size per schema:")
|
33
|
+
puts(("-" * 70))
|
34
|
+
schema_sizes.each do |row|
|
35
|
+
puts(("%20s %10s" % [row["table_schema"], row["size"]]))
|
36
|
+
end
|
37
|
+
puts(("-" * 70))
|
38
|
+
puts
|
39
|
+
db.finish
|
104
40
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
opts.separator ''
|
155
|
-
opts.separator 'Other options:'
|
156
|
-
|
157
|
-
opts.on_tail( '--help', 'show this help, then exit' ) do
|
158
|
-
$stderr.puts opts
|
159
|
-
exit
|
160
|
-
end
|
161
|
-
|
162
|
-
opts.on_tail( '--version', 'output version information, then exit' ) do
|
163
|
-
puts SCRIPT_VERSION
|
164
|
-
exit
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
opts.parse!( args )
|
169
|
-
return options
|
41
|
+
def parse_args(args)
|
42
|
+
options = OpenStruct.new
|
43
|
+
options.database = Etc.getpwuid(Process.uid).name
|
44
|
+
options.host = "127.0.0.1"
|
45
|
+
options.port = 5432
|
46
|
+
options.user = Etc.getpwuid(Process.uid).name
|
47
|
+
options.sslmode = "prefer"
|
48
|
+
options.interval = 5
|
49
|
+
opts = OptionParser.new do |opts|
|
50
|
+
opts.banner = "Usage: #{$0} [options]"
|
51
|
+
opts.separator("")
|
52
|
+
opts.separator("Connection options:")
|
53
|
+
opts.on("-d", "--database DBNAME", "specify the database to connect to (default: \"#{options.database}\")") do |db|
|
54
|
+
options.database = db
|
55
|
+
end
|
56
|
+
opts.on("-h", "--host HOSTNAME", "database server host") do |host|
|
57
|
+
options.host = host
|
58
|
+
end
|
59
|
+
opts.on("-p", "--port PORT", Integer, "database server port (default: \"#{options.port}\")") do |port|
|
60
|
+
options.port = port
|
61
|
+
end
|
62
|
+
opts.on("-U", "--user NAME", "database user name (default: \"#{options.user}\")") do |user|
|
63
|
+
options.user = user
|
64
|
+
end
|
65
|
+
opts.on("-W", "force password prompt") do |pw|
|
66
|
+
print("Password: ")
|
67
|
+
begin
|
68
|
+
(system("stty -echo")
|
69
|
+
options.pass = gets.chomp)
|
70
|
+
ensure
|
71
|
+
(system("stty echo")
|
72
|
+
puts)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
opts.separator("")
|
76
|
+
opts.separator("Other options:")
|
77
|
+
opts.on_tail("--help", "show this help, then exit") do
|
78
|
+
$stderr.puts(opts)
|
79
|
+
exit
|
80
|
+
end
|
81
|
+
opts.on_tail("--version", "output version information, then exit") do
|
82
|
+
puts(SCRIPT_VERSION)
|
83
|
+
exit
|
84
|
+
end
|
85
|
+
end
|
86
|
+
opts.parse!(args)
|
87
|
+
return options
|
170
88
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
opts = parse_args( ARGV )
|
175
|
-
report( opts )
|
89
|
+
if ("(string)" == $0) then
|
90
|
+
opts = parse_args(ARGV)
|
91
|
+
report(opts)
|
176
92
|
end
|
177
|
-
|