pg 0.18.2 → 1.4.5
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.appveyor.yml +36 -0
- data/.gems +6 -0
- data/.github/workflows/binary-gems.yml +86 -0
- data/.github/workflows/source-gem.yml +131 -0
- data/.gitignore +13 -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/BSDL +2 -2
- data/Gemfile +14 -0
- data/History.rdoc +480 -4
- data/Manifest.txt +8 -21
- data/README-Windows.rdoc +17 -28
- data/README.ja.rdoc +1 -2
- data/README.rdoc +92 -20
- data/Rakefile +33 -133
- data/Rakefile.cross +89 -67
- data/certs/ged.pem +24 -0
- data/certs/larskanis-2022.pem +26 -0
- data/ext/errorcodes.def +113 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +36 -2
- data/ext/extconf.rb +120 -54
- data/ext/gvl_wrappers.c +8 -0
- data/ext/gvl_wrappers.h +44 -33
- data/ext/pg.c +216 -172
- data/ext/pg.h +93 -98
- data/ext/pg_binary_decoder.c +85 -16
- data/ext/pg_binary_encoder.c +25 -22
- data/ext/pg_coder.c +176 -40
- data/ext/pg_connection.c +1735 -1138
- data/ext/pg_copy_coder.c +95 -28
- data/ext/pg_errors.c +1 -1
- data/ext/pg_record_coder.c +521 -0
- data/ext/pg_result.c +642 -221
- data/ext/pg_text_decoder.c +609 -41
- data/ext/pg_text_encoder.c +254 -100
- data/ext/pg_tuple.c +569 -0
- data/ext/pg_type_map.c +62 -22
- data/ext/pg_type_map_all_strings.c +20 -6
- data/ext/pg_type_map_by_class.c +55 -25
- data/ext/pg_type_map_by_column.c +81 -42
- data/ext/pg_type_map_by_mri_type.c +49 -20
- data/ext/pg_type_map_by_oid.c +56 -26
- data/ext/pg_type_map_in_ruby.c +52 -21
- data/ext/{util.c → pg_util.c} +12 -12
- data/ext/{util.h → pg_util.h} +2 -2
- data/lib/pg/basic_type_map_based_on_result.rb +47 -0
- data/lib/pg/basic_type_map_for_queries.rb +193 -0
- data/lib/pg/basic_type_map_for_results.rb +81 -0
- data/lib/pg/basic_type_registry.rb +301 -0
- data/lib/pg/binary_decoder.rb +23 -0
- data/lib/pg/coder.rb +24 -3
- data/lib/pg/connection.rb +711 -64
- data/lib/pg/constants.rb +2 -1
- data/lib/pg/exceptions.rb +9 -2
- data/lib/pg/result.rb +24 -7
- data/lib/pg/text_decoder.rb +27 -23
- data/lib/pg/text_encoder.rb +40 -8
- data/lib/pg/tuple.rb +30 -0
- data/lib/pg/type_map_by_column.rb +3 -2
- data/lib/pg/version.rb +4 -0
- data/lib/pg.rb +61 -36
- data/misc/openssl-pg-segfault.rb +31 -0
- data/misc/postgres/History.txt +9 -0
- data/misc/postgres/Manifest.txt +5 -0
- data/misc/postgres/README.txt +21 -0
- data/misc/postgres/Rakefile +21 -0
- data/misc/postgres/lib/postgres.rb +16 -0
- data/misc/ruby-pg/History.txt +9 -0
- data/misc/ruby-pg/Manifest.txt +5 -0
- data/misc/ruby-pg/README.txt +21 -0
- data/misc/ruby-pg/Rakefile +21 -0
- data/misc/ruby-pg/lib/ruby/pg.rb +16 -0
- data/pg.gemspec +32 -0
- data/rakelib/task_extension.rb +46 -0
- data/sample/array_insert.rb +1 -1
- data/sample/async_api.rb +4 -8
- data/sample/async_copyto.rb +1 -1
- data/sample/async_mixed.rb +1 -1
- data/sample/check_conn.rb +1 -1
- data/sample/copydata.rb +71 -0
- data/sample/copyfrom.rb +1 -1
- data/sample/copyto.rb +1 -1
- data/sample/cursor.rb +1 -1
- data/sample/disk_usage_report.rb +6 -15
- data/sample/issue-119.rb +2 -2
- data/sample/losample.rb +1 -1
- data/sample/minimal-testcase.rb +2 -2
- data/sample/notify_wait.rb +1 -1
- data/sample/pg_statistics.rb +6 -15
- data/sample/replication_monitor.rb +9 -18
- data/sample/test_binary_values.rb +1 -1
- data/sample/wal_shipper.rb +2 -2
- data/sample/warehouse_partitions.rb +8 -17
- data.tar.gz.sig +0 -0
- metadata +74 -216
- metadata.gz.sig +0 -0
- data/ChangeLog +0 -5545
- data/lib/pg/basic_type_mapping.rb +0 -399
- data/spec/data/expected_trace.out +0 -26
- data/spec/data/random_binary_data +0 -0
- data/spec/helpers.rb +0 -355
- data/spec/pg/basic_type_mapping_spec.rb +0 -251
- data/spec/pg/connection_spec.rb +0 -1535
- data/spec/pg/result_spec.rb +0 -449
- data/spec/pg/type_map_by_class_spec.rb +0 -138
- data/spec/pg/type_map_by_column_spec.rb +0 -222
- data/spec/pg/type_map_by_mri_type_spec.rb +0 -136
- data/spec/pg/type_map_by_oid_spec.rb +0 -149
- data/spec/pg/type_map_in_ruby_spec.rb +0 -164
- data/spec/pg/type_map_spec.rb +0 -22
- data/spec/pg/type_spec.rb +0 -688
- data/spec/pg_spec.rb +0 -50
data/sample/async_api.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
|
|
3
3
|
require 'pg'
|
|
4
4
|
|
|
@@ -27,10 +27,6 @@ conn = PG::Connection.connect_start( :dbname => 'test' ) or
|
|
|
27
27
|
abort "Connection failed: %s" % [ conn.error_message ] if
|
|
28
28
|
conn.status == PG::CONNECTION_BAD
|
|
29
29
|
|
|
30
|
-
# Now grab a reference to the underlying socket so we know when the
|
|
31
|
-
# connection is established
|
|
32
|
-
socket = conn.socket_io
|
|
33
|
-
|
|
34
30
|
# Track the progress of the connection, waiting for the socket to become readable/writable
|
|
35
31
|
# before polling it
|
|
36
32
|
poll_status = PG::PGRES_POLLING_WRITING
|
|
@@ -41,13 +37,13 @@ until poll_status == PG::PGRES_POLLING_OK ||
|
|
|
41
37
|
case poll_status
|
|
42
38
|
when PG::PGRES_POLLING_READING
|
|
43
39
|
output_progress " waiting for socket to become readable"
|
|
44
|
-
select( [
|
|
40
|
+
select( [conn.socket_io], nil, nil, TIMEOUT ) or
|
|
45
41
|
raise "Asynchronous connection timed out!"
|
|
46
42
|
|
|
47
43
|
# ...and the same for when the socket needs to write
|
|
48
44
|
when PG::PGRES_POLLING_WRITING
|
|
49
45
|
output_progress " waiting for socket to become writable"
|
|
50
|
-
select( nil, [
|
|
46
|
+
select( nil, [conn.socket_io], nil, TIMEOUT ) or
|
|
51
47
|
raise "Asynchronous connection timed out!"
|
|
52
48
|
end
|
|
53
49
|
|
|
@@ -85,7 +81,7 @@ loop do
|
|
|
85
81
|
# Buffer any incoming data on the socket until a full result is ready.
|
|
86
82
|
conn.consume_input
|
|
87
83
|
while conn.is_busy
|
|
88
|
-
select( [
|
|
84
|
+
select( [conn.socket_io], nil, nil, TIMEOUT ) or
|
|
89
85
|
raise "Timeout waiting for query response."
|
|
90
86
|
conn.consume_input
|
|
91
87
|
end
|
data/sample/async_copyto.rb
CHANGED
data/sample/async_mixed.rb
CHANGED
data/sample/check_conn.rb
CHANGED
data/sample/copydata.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
|
|
3
|
+
require 'pg'
|
|
4
|
+
require 'stringio'
|
|
5
|
+
|
|
6
|
+
$stderr.puts "Opening database connection ..."
|
|
7
|
+
conn = PG.connect( dbname: 'test' )
|
|
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 = ''
|
|
56
|
+
conn.transaction do
|
|
57
|
+
res = conn.copy_data( "COPY logs FROM STDIN WITH csv" ) do
|
|
58
|
+
$stderr.print "Sending lines... "
|
|
59
|
+
csv_io.each_line.with_index do |buf, i|
|
|
60
|
+
$stderr.print "#{i + 1} "
|
|
61
|
+
conn.put_copy_data( buf )
|
|
62
|
+
end
|
|
63
|
+
$stderr.puts "done."
|
|
64
|
+
end
|
|
65
|
+
$stderr.puts "Result of COPY is: %s" % [ res.res_status(res.result_status) ]
|
|
66
|
+
$stderr.puts " tuples copied: %p" % [ res.cmd_tuples ]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
conn.finish
|
|
71
|
+
|
data/sample/copyfrom.rb
CHANGED
data/sample/copyto.rb
CHANGED
data/sample/cursor.rb
CHANGED
data/sample/disk_usage_report.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
|
3
3
|
#
|
|
4
4
|
# Quickly dump size information for a given database.
|
|
@@ -10,21 +10,12 @@
|
|
|
10
10
|
#
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
require 'pg'
|
|
13
|
+
require 'ostruct'
|
|
14
|
+
require 'optparse'
|
|
15
|
+
require 'etc'
|
|
16
|
+
require 'pg'
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
unless Object.const_defined?( :Gem )
|
|
21
|
-
require 'rubygems'
|
|
22
|
-
retry
|
|
23
|
-
end
|
|
24
|
-
raise
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
SCRIPT_VERSION = %q$Id: disk_usage_report.rb,v 76ebae01c937 2013/03/26 17:50:02 ged $
|
|
18
|
+
SCRIPT_VERSION = %q$Id$
|
|
28
19
|
|
|
29
20
|
|
|
30
21
|
### Gather data and output it to $stdout.
|
data/sample/issue-119.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
|
|
3
3
|
require 'pg'
|
|
4
4
|
|
|
@@ -66,7 +66,7 @@ END_DATA
|
|
|
66
66
|
end
|
|
67
67
|
rescue Errno => err
|
|
68
68
|
errmsg = "%s while reading copy data: %s" % [err.class.name, err.message]
|
|
69
|
-
puts "an error
|
|
69
|
+
puts "an error occurred"
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
if errmsg
|
data/sample/losample.rb
CHANGED
data/sample/minimal-testcase.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
|
|
3
3
|
require 'pg'
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ $stderr.puts '---',
|
|
|
7
7
|
RUBY_DESCRIPTION,
|
|
8
8
|
PG.version_string( true ),
|
|
9
9
|
"Server version: #{conn.server_version}",
|
|
10
|
-
"Client version: #{PG.
|
|
10
|
+
"Client version: #{PG.library_version}",
|
|
11
11
|
'---'
|
|
12
12
|
|
|
13
13
|
result = conn.exec( "SELECT * from pg_stat_activity" )
|
data/sample/notify_wait.rb
CHANGED
data/sample/pg_statistics.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
|
3
3
|
#
|
|
4
4
|
# PostgreSQL statistic gatherer.
|
|
@@ -13,26 +13,17 @@
|
|
|
13
13
|
# some nice performance charts.
|
|
14
14
|
#
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
require 'pg'
|
|
21
|
-
|
|
22
|
-
rescue LoadError # 1.8 support
|
|
23
|
-
unless Object.const_defined?( :Gem )
|
|
24
|
-
require 'rubygems'
|
|
25
|
-
retry
|
|
26
|
-
end
|
|
27
|
-
raise
|
|
28
|
-
end
|
|
16
|
+
require 'ostruct'
|
|
17
|
+
require 'optparse'
|
|
18
|
+
require 'etc'
|
|
19
|
+
require 'pg'
|
|
29
20
|
|
|
30
21
|
|
|
31
22
|
### PostgreSQL Stats. Fetch information from pg_stat_* tables.
|
|
32
23
|
### Optionally run in a continuous loop, displaying deltas.
|
|
33
24
|
###
|
|
34
25
|
class Stats
|
|
35
|
-
VERSION = %q$Id
|
|
26
|
+
VERSION = %q$Id$
|
|
36
27
|
|
|
37
28
|
def initialize( opts )
|
|
38
29
|
@opts = opts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
# vim: set noet nosta sw=4 ts=4 :
|
|
3
3
|
#
|
|
4
4
|
# Get the current WAL segment and offset from a master postgresql
|
|
@@ -15,28 +15,19 @@
|
|
|
15
15
|
# db_replication.monitor db-master.example.com ...
|
|
16
16
|
#
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
require 'pp'
|
|
25
|
-
|
|
26
|
-
rescue LoadError # 1.8 support
|
|
27
|
-
unless Object.const_defined?( :Gem )
|
|
28
|
-
require 'rubygems'
|
|
29
|
-
retry
|
|
30
|
-
end
|
|
31
|
-
raise
|
|
32
|
-
end
|
|
18
|
+
require 'ostruct'
|
|
19
|
+
require 'optparse'
|
|
20
|
+
require 'pathname'
|
|
21
|
+
require 'etc'
|
|
22
|
+
require 'pg'
|
|
23
|
+
require 'pp'
|
|
33
24
|
|
|
34
25
|
|
|
35
26
|
### A class to encapsulate the PG handles.
|
|
36
27
|
###
|
|
37
28
|
class PGMonitor
|
|
38
29
|
|
|
39
|
-
VERSION = %q$Id
|
|
30
|
+
VERSION = %q$Id$
|
|
40
31
|
|
|
41
32
|
# When to consider a slave as 'behind', measured in WAL segments.
|
|
42
33
|
# The default WAL segment size is 16, so we'll alert after
|
|
@@ -96,7 +87,7 @@ class PGMonitor
|
|
|
96
87
|
#########
|
|
97
88
|
|
|
98
89
|
### Ask the master for the current xlog information, to compare
|
|
99
|
-
### to slaves. Returns true on
|
|
90
|
+
### to slaves. Returns true on success. On failure, populates
|
|
100
91
|
### the failures array and returns false.
|
|
101
92
|
###
|
|
102
93
|
def get_current_wal
|
data/sample/wal_shipper.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
#
|
|
3
3
|
# A script to wrap ssh and rsync for PostgreSQL WAL files shipping.
|
|
4
4
|
# Mahlon E. Smith <mahlon@martini.nu>
|
|
@@ -350,7 +350,7 @@ module WalShipper
|
|
|
350
350
|
###
|
|
351
351
|
def dispatch_dest( dest )
|
|
352
352
|
if ! dest.enabled.nil? && ! dest.enabled
|
|
353
|
-
self.log "Skipping
|
|
353
|
+
self.log "Skipping explicitly disabled destination %p, WAL is queued." % [ dest.label ]
|
|
354
354
|
return
|
|
355
355
|
end
|
|
356
356
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
|
3
3
|
#
|
|
4
4
|
# Script to automatically move partitioned tables and their indexes
|
|
@@ -36,21 +36,12 @@
|
|
|
36
36
|
#
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
require 'pg'
|
|
46
|
-
|
|
47
|
-
rescue LoadError # 1.8 support
|
|
48
|
-
unless Object.const_defined?( :Gem )
|
|
49
|
-
require 'rubygems'
|
|
50
|
-
retry
|
|
51
|
-
end
|
|
52
|
-
raise
|
|
53
|
-
end
|
|
39
|
+
require 'date'
|
|
40
|
+
require 'ostruct'
|
|
41
|
+
require 'optparse'
|
|
42
|
+
require 'pathname'
|
|
43
|
+
require 'etc'
|
|
44
|
+
require 'pg'
|
|
54
45
|
|
|
55
46
|
|
|
56
47
|
### A tablespace migration class.
|
|
@@ -159,7 +150,7 @@ class PGWarehouse
|
|
|
159
150
|
end
|
|
160
151
|
end
|
|
161
152
|
|
|
162
|
-
# Add table
|
|
153
|
+
# Add table inheritance information.
|
|
163
154
|
#
|
|
164
155
|
db.exec 'SELECT inhrelid AS oid, inhparent AS parent FROM pg_inherits' do |res|
|
|
165
156
|
res.each do |row|
|
data.tar.gz.sig
CHANGED
|
Binary file
|