pg 1.5.9 → 1.7.0
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
- checksums.yaml.gz.sig +0 -0
- data/{History.md → CHANGELOG.md} +126 -0
- data/Gemfile +11 -7
- data/README-Windows.rdoc +1 -1
- data/README.ja.md +83 -32
- data/README.md +79 -29
- data/Rakefile +84 -19
- data/certs/larskanis-2026.pem +24 -0
- data/ext/errorcodes.def +9 -0
- data/ext/errorcodes.rb +1 -1
- data/ext/errorcodes.txt +8 -1
- data/ext/extconf.rb +194 -30
- data/ext/gvl_wrappers.c +13 -2
- data/ext/gvl_wrappers.h +47 -134
- data/ext/pg.c +23 -16
- data/ext/pg.h +23 -24
- data/ext/pg_binary_decoder.c +157 -3
- data/ext/pg_binary_encoder.c +219 -9
- data/ext/pg_cancel_connection.c +360 -0
- data/ext/pg_coder.c +58 -9
- data/ext/pg_connection.c +558 -291
- data/ext/pg_copy_coder.c +36 -23
- data/ext/pg_record_coder.c +11 -7
- data/ext/pg_result.c +144 -76
- data/ext/pg_text_decoder.c +7 -7
- data/ext/pg_text_encoder.c +29 -11
- data/ext/pg_tuple.c +9 -9
- data/ext/pg_type_map.c +45 -3
- data/ext/pg_type_map_all_strings.c +3 -3
- data/ext/pg_type_map_by_class.c +2 -2
- data/ext/pg_type_map_by_column.c +4 -3
- data/ext/pg_type_map_by_mri_type.c +1 -1
- data/ext/pg_type_map_by_oid.c +4 -2
- data/ext/pg_type_map_in_ruby.c +2 -2
- data/ext/pg_util.c +2 -2
- data/ext/pg_util.h +2 -2
- data/lib/pg/basic_type_map_based_on_result.rb +5 -0
- data/lib/pg/basic_type_map_for_queries.rb +16 -5
- data/lib/pg/basic_type_map_for_results.rb +5 -0
- data/lib/pg/basic_type_registry.rb +2 -2
- data/lib/pg/cancel_connection.rb +53 -0
- data/lib/pg/coder.rb +4 -2
- data/lib/pg/connection.rb +393 -180
- data/lib/pg/text_decoder/date.rb +1 -1
- data/lib/pg/text_decoder/json.rb +1 -1
- data/lib/pg/text_encoder/date.rb +7 -1
- data/lib/pg/text_encoder/json.rb +1 -1
- data/lib/pg/version.rb +2 -1
- data/lib/pg.rb +156 -130
- data/misc/glibc/Dockerfile +20 -0
- data/misc/glibc/docker-compose.yml +9 -0
- data/misc/glibc/glibc_spec.rb +5 -0
- data/misc/yugabyte/Dockerfile +9 -0
- data/misc/yugabyte/docker-compose.yml +28 -0
- data/misc/yugabyte/pg-test.rb +45 -0
- data/pg.gemspec +5 -3
- data/ports/patches/krb5/1.22.2/0001-Allow-static-linking-krb5-library.patch +30 -0
- data/ports/patches/krb5/1.22.2/0002-unknown-command-line-option-on-clang.patch +12 -0
- data/ports/patches/postgresql/18.6/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +42 -0
- data/rakelib/pg_gem_helper.rb +64 -0
- data/sample/async_mixed.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +36 -22
- metadata.gz.sig +0 -0
- data/Manifest.txt +0 -72
- data/Rakefile.cross +0 -303
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 01ff8f72c20e6b96364acee8cc436df0d1305861cd3edba88be07c81fc0e2e55
|
|
4
|
+
data.tar.gz: e1dce91f9a03eaf081e11705175902c43471710612d299d626e2bb796c6990f6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1326d36f1ebcd07e755615fa2bdc78c46bcf937f1d085c080816dee7f93790ce3aedcb58ff3be4840e6f1c713c7a81e2879bfa934d4fbcdea3faa891f83fc534
|
|
7
|
+
data.tar.gz: 80b0474f35ffd2ef4339fbb635a375b4de216ef3a0c8f3b9ad5da6b4f5e6767edae9794fe15364ca6f27667867e137cba809b1770c63436102f3389c3c42f27a
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/{History.md → CHANGELOG.md}
RENAMED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
+
## v1.7.0 [2026-10-02] Lars Kanis <lars@greiz-reinsdorf.de>
|
|
2
|
+
|
|
3
|
+
Added:
|
|
4
|
+
|
|
5
|
+
- Add PG::Connection#embed_params and keyword `:typename` for its parameter casting. [#726](https://github.com/ged/ruby-pg/pull/726)
|
|
6
|
+
This allows to generate SQL strings with embedded parameters for easier debugging.
|
|
7
|
+
- Add PG::Connection#full_protocol_version which is new in PostgreSQL-18 [#695](https://github.com/ged/ruby-pg/pull/695)
|
|
8
|
+
- Add PG::Result#each_tuple [#675](https://github.com/ged/ruby-pg/pull/675)
|
|
9
|
+
- Add PG::TypeMap#query_param_encoders to retrieve encoders. [#726](https://github.com/ged/ruby-pg/pull/726)
|
|
10
|
+
- Deduplicate result field name strings for better performance. [#750](https://github.com/ged/ruby-pg/pull/750)
|
|
11
|
+
|
|
12
|
+
Removed:
|
|
13
|
+
|
|
14
|
+
- Remove compatibility to ruby < 3.1 and drops support of ruby-2.7 and ruby-3.0. [#749](https://github.com/ged/ruby-pg/pull/749)
|
|
15
|
+
- Remove GLV unlocking at all functions which process data modifiable in a second thread. [#721](https://github.com/ged/ruby-pg/pull/721)
|
|
16
|
+
This avoids possible premature garbage collection of query parameters and possible VM crash due to concurrent data manipulation.
|
|
17
|
+
- Remove `:static_symbol` result field names. [#691](https://github.com/ged/ruby-pg/pull/691)
|
|
18
|
+
- Remove enforced rpath addition when no rpath is configured in rbconfig. [#699](https://github.com/ged/ruby-pg/pull/699)
|
|
19
|
+
|
|
20
|
+
Fixes:
|
|
21
|
+
|
|
22
|
+
- Limit memory allocation on invalid input into PG::BinaryDecoder::Array. [#743](https://github.com/ged/ruby-pg/pull/743)
|
|
23
|
+
- Free COPY buffers when decoders raise to avoid possible memory leak in get_copy_data. [#742](https://github.com/ged/ruby-pg/pull/742)
|
|
24
|
+
- Prevent SQL injection in set_client_encoding. [#741](https://github.com/ged/ruby-pg/pull/741)
|
|
25
|
+
- Add GC_GUARD to temporary ruby objects for conninfo string to avoid it's GC'ed prematurely. [#739](https://github.com/ged/ruby-pg/pull/739)
|
|
26
|
+
- Remove option "quirks_mode" from JSON en/decoder to fix compat with json-3.0 gem. [#737](https://github.com/ged/ruby-pg/pull/737)
|
|
27
|
+
- Respect calendar type of Ruby and PostgreSQL. [#725](https://github.com/ged/ruby-pg/pull/725)
|
|
28
|
+
- Fix broken set_notice_(receiver|processor) callback after GC.compact. [#734](https://github.com/ged/ruby-pg/pull/734)
|
|
29
|
+
- Disable DNS resolution in ruby when a service file is used, so that the priority of parameters is equal to libpq. [#635](https://github.com/ged/ruby-pg/pull/635)
|
|
30
|
+
- Use RARRAY_LENINT to avoid possible overflow. [#728](https://github.com/ged/ruby-pg/pull/728)
|
|
31
|
+
- Fix possible integer overflow at PG::BinaryEncoder::CopyRow and PG::TextEncoder::CopyRow. [#714](https://github.com/ged/ruby-pg/pull/714), [#715](https://github.com/ged/ruby-pg/pull/715)
|
|
32
|
+
- Avoid possible integer overflow in query parameter encoding. [#719](https://github.com/ged/ruby-pg/pull/719)
|
|
33
|
+
- Ensure conninfo is a valid C string before closing the connection to avoid a double free of PGconn. [#709](https://github.com/ged/ruby-pg/pull/709)
|
|
34
|
+
- Raise on a too large input string to PG::TextEncoder::Bytea. [#717](https://github.com/ged/ruby-pg/pull/717)
|
|
35
|
+
- Check PG::BinaryEncoder::CopyRow array input size instead of producing an invalid output.
|
|
36
|
+
- Remove accidentally copied "static" keyword from Copy and Record encoder. [#711](https://github.com/ged/ruby-pg/pull/711)
|
|
37
|
+
- Avoid possibility to replace typemap while being used in Copy and Record encoders and decoders. [#707](https://github.com/ged/ruby-pg/pull/707)
|
|
38
|
+
- Add GC_GUARD's for encoding converted strings sent to the server. [#705](https://github.com/ged/ruby-pg/pull/705)
|
|
39
|
+
- Fix incomplete transaction commit when thread is shutdown ungracefully. [#704](https://github.com/ged/ruby-pg/pull/704)
|
|
40
|
+
- Assign VALUE after registration per rb_gc_register_address() [#703](https://github.com/ged/ruby-pg/pull/703)
|
|
41
|
+
- Update dependencies for binary gems to PostgreSQL-18.6, OpenSSL-3.6.5, krb5-1.22.2 [#752](https://github.com/ged/ruby-pg/pull/752)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## v1.6.3 [2025-12-29] Lars Kanis <lars@greiz-reinsdorf.de>
|
|
45
|
+
|
|
46
|
+
Added:
|
|
47
|
+
|
|
48
|
+
- Add binary gems for ruby-4.0, now providing ruby-3.0 to 4.0. [#682](https://github.com/ged/ruby-pg/pull/682)
|
|
49
|
+
- Update fat binary gem to OpenSSL-3.6.0 and PostgreSQL-18.1.
|
|
50
|
+
- Improve documentation of PG::Result and README. [#676](https://github.com/ged/ruby-pg/pull/676)
|
|
51
|
+
- Update errorcodes to PostgreSQL-18.
|
|
52
|
+
- Use `rb_hash_new_capa` on Ruby-3.2+ . [#674](https://github.com/ged/ruby-pg/pull/674)
|
|
53
|
+
- Deny any server communication on a frozen PG::Connection . [#677](https://github.com/ged/ruby-pg/pull/677)
|
|
54
|
+
- Fix possible race condition in PG::Result in Ractor context. [#674](https://github.com/ged/ruby-pg/pull/674)
|
|
55
|
+
|
|
56
|
+
Removed:
|
|
57
|
+
|
|
58
|
+
- Drop binary gem support for platform `x86-mingw32`. [#682](https://github.com/ged/ruby-pg/pull/682)
|
|
59
|
+
- Drop binary gems for ruby-2.7.
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## v1.6.2 [2025-09-02] Lars Kanis <lars@greiz-reinsdorf.de>
|
|
63
|
+
|
|
64
|
+
- Remove several absolute paths from native binaries which pointed to build directories. [#668](https://github.com/ged/ruby-pg/pull/668)
|
|
65
|
+
- Fix bad fallback path to `pg_service.conf`. [#666](https://github.com/ged/ruby-pg/pull/666)
|
|
66
|
+
- Use `rbpg_` prefix for `base64_*` functions to avoid name clashes with functions provided by other libraries like Heimdal on Macos. [#667](https://github.com/ged/ruby-pg/pull/667)
|
|
67
|
+
- Raise a more descriptive error message in case of `pg_ext` LoadError. [#664](https://github.com/ged/ruby-pg/pull/664)
|
|
68
|
+
- Freeze some constants to make them available in a Ractor context. [#660](https://github.com/ged/ruby-pg/pull/660)
|
|
69
|
+
- Several documentation improvements.
|
|
70
|
+
- Update native binary gems to OpenSSL-3.5.2, krb5-1.22.1 and PostgreSQL-17.6.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## v1.6.1 [2025-08-03] Lars Kanis <lars@greiz-reinsdorf.de>
|
|
74
|
+
|
|
75
|
+
- Add binary gems for platforms `aarch64-linux-musl` and `x86_64-linux-musl` without the need to install package `gcompat`. [#657](https://github.com/ged/ruby-pg/pull/657).
|
|
76
|
+
- Serialize CompositeCoder#dimensions only when set. [#652](https://github.com/ged/ruby-pg/pull/652)
|
|
77
|
+
This fixes the compatibility to pg-1.5.9, when deserializing Marshal data from pg-1.6, as long as the new attribute isn't used.
|
|
78
|
+
- Remove dependency to MSYS2 package "postgresql" from binary Windows gem [#654](https://github.com/ged/ruby-pg/pull/654)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## v1.6.0 [2025-07-27] Lars Kanis <lars@greiz-reinsdorf.de>
|
|
82
|
+
|
|
83
|
+
Added:
|
|
84
|
+
|
|
85
|
+
- Add binary gems for Ruby 3.4.
|
|
86
|
+
- Add fat binary gem for platform `aarch64-mingw-ucrt` aka Windows on ARM [#626](https://github.com/ged/ruby-pg/pull/626), for platform Macos on Intel and ARM [#643](https://github.com/ged/ruby-pg/pull/643), for platform `aarch64-linux` [#646](https://github.com/ged/ruby-pg/pull/646) and for platform `x86_64-linux` [#551](https://github.com/ged/ruby-pg/pull/551#issuecomment-2504715762).
|
|
87
|
+
- Update fat binary gem to OpenSSL-3.5.1 and PostgreSQL-17.5.
|
|
88
|
+
- Add a patch to libpq to avoid starvation on bigger SSL records, which some database engines other than vanilla PostgreSQL use.
|
|
89
|
+
This patch applies to platform specific binary gems only.
|
|
90
|
+
[#616](https://github.com/ged/ruby-pg/pull/616)
|
|
91
|
+
- Add support for new query cancel functions of PostgreSQL-17.
|
|
92
|
+
This adds the new class `PG::CancelConnection` which provides the ability to cancel a query per blocking or per non-blocking functions.
|
|
93
|
+
If the new functions are available they are used and the older are no longer compiled in.
|
|
94
|
+
This way we can get rid of reading out the internal `PGcancel` struct by `Connection#backend_key`.
|
|
95
|
+
[#614](https://github.com/ged/ruby-pg/pull/614)
|
|
96
|
+
- Add PG::BinaryDecoder::Array and PG::BinaryEncoder::Array to parse and encode PostgreSQL arrays in binary format.
|
|
97
|
+
[#603](https://github.com/ged/ruby-pg/pull/603)
|
|
98
|
+
- Add possibility to define the number of array dimensions to be encoded.
|
|
99
|
+
Setting dimensions is especially useful, when a Record shall be encoded into an Array, since the Array encoder can not distinguish if the array shall be encoded as a higher dimension or as a record otherwise.
|
|
100
|
+
[#622](https://github.com/ged/ruby-pg/pull/622)
|
|
101
|
+
- Add Connection#set_chunked_rows_mode [#610](https://github.com/ged/ruby-pg/pull/610)
|
|
102
|
+
- Add PG::Connection#close_prepared, PG::Connection#close_portal, PG::Connection#send_close_prepared and PG::Connection#send_close_portal which are new in PostgreSQL-17.
|
|
103
|
+
[#611](https://github.com/ged/ruby-pg/pull/611)
|
|
104
|
+
- Add Connection#send_pipeline_sync, async_pipeline_sync and release GVL at PQ(sendP|P)ipelineSync.
|
|
105
|
+
[#612](https://github.com/ged/ruby-pg/pull/612)
|
|
106
|
+
- Add MINGW package dependency which is resolved by RubyInstaller.
|
|
107
|
+
[#617](https://github.com/ged/ruby-pg/pull/617)
|
|
108
|
+
- Change `conn.server_version` and `conn.protocol_version` to raise instead of return 0 on error.
|
|
109
|
+
[#632](https://github.com/ged/ruby-pg/pull/632)
|
|
110
|
+
- Fix connecting to multiple hosts after `connnect_timeout`.
|
|
111
|
+
[#637](https://github.com/ged/ruby-pg/pull/637)
|
|
112
|
+
- Fix making PG::BasicTypeMapForQueries shareable for Ractor in ruby-3.5.
|
|
113
|
+
[#636](https://github.com/ged/ruby-pg/pull/636)
|
|
114
|
+
- Fix missing array input verification in PG::TypeMapByColumn.
|
|
115
|
+
This could cause a segfault.
|
|
116
|
+
[#620](https://github.com/ged/ruby-pg/pull/620)
|
|
117
|
+
- Rename `History.md` to `CHANGELOG.md`, which is more common.
|
|
118
|
+
[#642](https://github.com/ged/ruby-pg/pull/642)
|
|
119
|
+
|
|
120
|
+
Removed:
|
|
121
|
+
|
|
122
|
+
- Drop support of Ruby < 2.7 [#606](https://github.com/ged/ruby-pg/pull/606)
|
|
123
|
+
- Drop support of PostgreSQL < 10 [#606](https://github.com/ged/ruby-pg/pull/606)
|
|
124
|
+
- Remove workaround for Truffleruby < 21.3.0 [#613](https://github.com/ged/ruby-pg/pull/613)
|
|
125
|
+
|
|
126
|
+
|
|
1
127
|
## v1.5.9 [2024-10-24] Lars Kanis <lars@greiz-reinsdorf.de>
|
|
2
128
|
|
|
3
129
|
- Enable thread safety in static OpenSSL build for Windows. [#595](https://github.com/ged/ruby-pg/pull/595)
|
data/Gemfile
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
# -*- ruby -*-
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
gemspec
|
|
3
|
+
# No pg gem, since "bundle package" fails on bundler-2.7+, if the extension isn't built
|
|
4
|
+
# gemspec
|
|
5
5
|
|
|
6
6
|
source "https://rubygems.org/"
|
|
7
7
|
|
|
8
|
-
group :development
|
|
9
|
-
gem "bundler", ">= 1.16", "< 3.0"
|
|
10
|
-
gem "rake-compiler", "~> 1.0"
|
|
11
|
-
gem "rake-compiler-dock", "~> 1.0"
|
|
8
|
+
group :development do
|
|
12
9
|
gem "rdoc", "~> 6.4"
|
|
10
|
+
gem "mini_portile2", "~> 2.1"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
group :test do
|
|
14
|
+
gem "bundler", ">= 1.16", "< 5.0"
|
|
15
|
+
gem "rake-compiler", "~> 1.0"
|
|
16
|
+
gem "rake-compiler-dock", "~> 1.11.0" #, git: "https://github.com/rake-compiler/rake-compiler-dock"
|
|
13
17
|
gem "rspec", "~> 3.5"
|
|
14
|
-
gem "ostruct", "~> 0.5" # for Rakefile.cross
|
|
15
18
|
# "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
|
|
16
19
|
# Specs should succeed without it, but 4 examples are then excluded.
|
|
17
20
|
# With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4.
|
|
18
21
|
# That way we can check both situations in CI.
|
|
19
22
|
# gem "bigdecimal", "~> 3.0"
|
|
23
|
+
gem "drb"
|
|
20
24
|
end
|
data/README-Windows.rdoc
CHANGED
|
@@ -41,7 +41,7 @@ sure it is started. A native Docker installation is best on Linux.
|
|
|
41
41
|
|
|
42
42
|
Then run:
|
|
43
43
|
|
|
44
|
-
rake gem:
|
|
44
|
+
rake gem:native
|
|
45
45
|
|
|
46
46
|
This will download a docker image suited for building windows gems, and it
|
|
47
47
|
will download and build OpenSSL and PostgreSQL. Finally the gem is built
|
data/README.ja.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# pg
|
|
2
2
|
|
|
3
3
|
* ホーム :: https://github.com/ged/ruby-pg
|
|
4
|
-
* ドキュメント :: http://deveiate.org/code/pg (英語)、 https://deveiate.org/code/pg/README_ja_md.html (日本語)
|
|
5
|
-
* 変更履歴 :: link:/
|
|
4
|
+
* ドキュメント :: http://deveiate.org/code/pg/README_md.html (英語)、 https://deveiate.org/code/pg/README_ja_md.html (日本語)
|
|
5
|
+
* 変更履歴 :: link:/CHANGELOG.md
|
|
6
6
|
|
|
7
7
|
[](https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
Pgは[PostgreSQL
|
|
14
14
|
RDBMS](http://www.postgresql.org/)へのRubyのインターフェースです。[PostgreSQL
|
|
15
|
-
|
|
15
|
+
10以降](http://www.postgresql.org/support/versioning/)で動作します。
|
|
16
16
|
|
|
17
17
|
簡単な使用例は次の通りです。
|
|
18
18
|
```ruby
|
|
@@ -31,6 +31,10 @@ RDBMS](http://www.postgresql.org/)へのRubyのインターフェースです。
|
|
|
31
31
|
end
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
問い合わせのメソッドについては PG::Connection クラスを、問い合わせの結果を取り回す際の情報については PG::Result
|
|
35
|
+
クラスを参照してください。
|
|
36
|
+
|
|
37
|
+
|
|
34
38
|
## ビルド状況
|
|
35
39
|
|
|
36
40
|
[の取得です。
|
|
70
|
+
これに対応するには`libldap`が必要でしょうが、沢山の依存関係があります。
|
|
71
|
+
広く使われている機能のようにも対応する価値があるとも思われません。
|
|
72
|
+
必要であれば、ソースgemに強制できます。
|
|
65
73
|
|
|
66
|
-
|
|
74
|
+
### ソースgem
|
|
75
|
+
|
|
76
|
+
ソースgemは次のように強制できます。
|
|
77
|
+
|
|
78
|
+
gem uninstall pg --all
|
|
79
|
+
gem install pg --platform ruby
|
|
67
80
|
|
|
68
81
|
Postgresと一緒にインストールされた'pg_config'プログラムへのパスを指定する必要があるかもしれません。
|
|
69
82
|
|
|
@@ -73,6 +86,29 @@ Bundlerを介してインストールした場合は次のようにコンパイ
|
|
|
73
86
|
|
|
74
87
|
bundle config build.pg --with-pg-config=<path to pg_config>
|
|
75
88
|
|
|
89
|
+
### Bundler
|
|
90
|
+
|
|
91
|
+
必要なプラットフォームとソースgemがbundlerにより取得されることを確実にするためには、次のように加えられます。
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
bundle lock --add-platform x86_64-linux
|
|
95
|
+
bundle lock --add-platform arm64-darwin
|
|
96
|
+
bundle lock --add-platform x64-mingw-ucrt
|
|
97
|
+
bundle lock --add-platform ruby
|
|
98
|
+
bundle package --all-platforms
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`bundle package`の再実行は`bundle
|
|
102
|
+
update`後にも必須であり、これはすべてのプラットフォームの新しい特定のgemを取得するためです。
|
|
103
|
+
|
|
104
|
+
バイナリgemが何らかの理由で動作しないなら、Gemfileでソースgemの利用を簡単に強制できます。
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
gem "pg", force_ruby_platform: true
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### その他
|
|
111
|
+
|
|
76
112
|
MacOS Xへインストールする詳しい情報については README-OS_X.rdoc を、Windows用のビルドやインストールの説明については
|
|
77
113
|
README-Windows.rdoc を参照してください。
|
|
78
114
|
|
|
@@ -81,9 +117,22 @@ README-Windows.rdoc を参照してください。
|
|
|
81
117
|
署名されたgemとしてインストールしたい場合は、リポジトリの[`certs`ディレクトリ](https://github.com/ged/ruby-pg/tree/master/certs)にgemの署名をする公開証明書があります。
|
|
82
118
|
|
|
83
119
|
|
|
120
|
+
## バージョン管理
|
|
121
|
+
|
|
122
|
+
[セマンティックバージョニング](http://semver.org/)の原則にしたがってgemをタグ付けしてリリースしています。
|
|
123
|
+
|
|
124
|
+
この方針の結果として、2つの数字を指定する[悲観的バージョン制約](http://guides.rubygems.org/patterns/#pessimistic-version-constraint)を使ってこのgemへの依存関係を指定することができます(またそうすべきです)。
|
|
125
|
+
|
|
126
|
+
例えば次の通りです。
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
spec.add_dependency 'pg', '~> 1.0'
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
|
|
84
133
|
## 型変換
|
|
85
134
|
|
|
86
|
-
Pgでは任意でRubyと素のC
|
|
135
|
+
Pgでは任意でRubyと素のCコードにある結果の値や問い合わせ引数の型変換ができます。
|
|
87
136
|
こうすることでデータベースとのデータの往来を加速させられます。
|
|
88
137
|
なぜなら文字列のアロケーションが減り、(比較的遅い)Rubyのコードでの変換部分が省かれるからです。
|
|
89
138
|
|
|
@@ -102,10 +151,10 @@ Pgでは任意でRubyと素のCコードにある結果の値やクエリ引数
|
|
|
102
151
|
|
|
103
152
|
しかしPgの型変換はかなり調整が効きます。2層に分かれているのがその理由です。
|
|
104
153
|
|
|
105
|
-
### エンコーダーとデコーダー (ext/pg_
|
|
154
|
+
### エンコーダーとデコーダー (ext/pg_\*coder.c, lib/pg/\*coder.rb)
|
|
106
155
|
|
|
107
156
|
こちらはより低層で、DBMSへ転送するためにRubyのオブジェクトを変換するエンコーディングクラスと、取得してきたデータをRubyのオブジェクトに変換し戻すデコーディングクラスが含まれています。
|
|
108
|
-
クラスはそれぞれの形式によって名前空間 PG::TextEncoder, PG::TextDecoder, PG::BinaryEncoder,
|
|
157
|
+
クラスはそれぞれの形式によって名前空間 PG::TextEncoder, PG::TextDecoder, PG::BinaryEncoder,
|
|
109
158
|
PG::BinaryDecoder に分かれています。
|
|
110
159
|
|
|
111
160
|
エンコーダーないしデコーダーオブジェクトにOIDデータ型や形式コード(テキストないしバイナリ)や任意で名前を割り当てることができます。
|
|
@@ -145,13 +194,14 @@ Binary Encoder、BD = Binary Decoder)。
|
|
|
145
194
|
[現地時間](rdoc-ref:PG::BinaryEncoder::TimestampLocal)、[UTC](rdoc-ref:PG::BinaryEncoder::TimestampUtc)
|
|
146
195
|
* BD:
|
|
147
196
|
[現地時間](rdoc-ref:PG::BinaryDecoder::TimestampLocal)、[UTC](rdoc-ref:PG::BinaryDecoder::TimestampUtc)、[UTCから現地時間へ](rdoc-ref:PG::BinaryDecoder::TimestampUtcToLocal)
|
|
148
|
-
*
|
|
197
|
+
* Date:
|
|
198
|
+
[TE](rdoc-ref:PG::TextEncoder::Date)、[TD](rdoc-ref:PG::TextDecoder::Date)、[BE](rdoc-ref:PG::BinaryEncoder::Date)、[BD](rdoc-ref:PG::BinaryDecoder::Date)
|
|
149
199
|
* JSONとJSONB:
|
|
150
200
|
[TE](rdoc-ref:PG::TextEncoder::JSON)、[TD](rdoc-ref:PG::TextDecoder::JSON)
|
|
151
201
|
* Inet:
|
|
152
202
|
[TE](rdoc-ref:PG::TextEncoder::Inet)、[TD](rdoc-ref:PG::TextDecoder::Inet)
|
|
153
203
|
* Array:
|
|
154
|
-
[TE](rdoc-ref:PG::TextEncoder::Array)、[TD](rdoc-ref:PG::TextDecoder::Array)
|
|
204
|
+
[TE](rdoc-ref:PG::TextEncoder::Array)、[TD](rdoc-ref:PG::TextDecoder::Array)、[BE](rdoc-ref:PG::BinaryEncoder::Array)、[BD](rdoc-ref:PG::BinaryDecoder::Array)
|
|
155
205
|
* 複合型(「行」や「レコード」などとも言います):[TE](rdoc-ref:PG::TextEncoder::Record)、[TD](rdoc-ref:PG::TextDecoder::Record)
|
|
156
206
|
|
|
157
207
|
カラム型として使われていませんが、以下のテキスト形式とバイナリ形式もエンコードできます。
|
|
@@ -163,14 +213,14 @@ Binary Encoder、BD = Binary Decoder)。
|
|
|
163
213
|
* SQLの識別子:
|
|
164
214
|
[TE](rdoc-ref:PG::TextEncoder::Identifier)、[TD](rdoc-ref:PG::TextDecoder::Identifier)
|
|
165
215
|
|
|
166
|
-
###
|
|
216
|
+
### TypeMap とその派生 (ext/pg_type_map\*.c, lib/pg/type_map\*.rb)
|
|
167
217
|
|
|
168
|
-
TypeMap
|
|
169
|
-
|
|
170
|
-
|
|
218
|
+
PG::TypeMap はどのエンコーダーないしデコーダーによってどの値が変換されるかを定義します。
|
|
219
|
+
様々な型の対応付けの戦略があり、このクラスの複数の派生により実装されています。
|
|
220
|
+
型変換の特有の需要に合わせてそれらから選んで構成できます。
|
|
171
221
|
既定の型の対応付けは PG::TypeMapAllStrings です。
|
|
172
222
|
|
|
173
|
-
|
|
223
|
+
型の対応付けは、結果の集合それぞれに対し、接続毎ないし問い合わせ毎に割り当てることができます。
|
|
174
224
|
型の対応付けはCOPYの入出力データストリーミングでも使うことができます。
|
|
175
225
|
PG::Connection#copy_data を参照してください。
|
|
176
226
|
|
|
@@ -191,12 +241,14 @@ PG::Connection#copy_data を参照してください。
|
|
|
191
241
|
* PG::BasicTypeMapForQueries - PG::TypeMapByClass
|
|
192
242
|
によくあるRubyの値クラス用にエンコーダーが入った状態になっています
|
|
193
243
|
|
|
244
|
+
PG::TypeMap::DefaultTypeMappable#default_type_map
|
|
245
|
+
を設定することで複数の型の対応付けを連鎖させられます。
|
|
194
246
|
|
|
195
247
|
## スレッド対応
|
|
196
248
|
|
|
197
|
-
PG
|
|
198
|
-
|
|
199
|
-
|
|
249
|
+
PG には個々のスレッドないしファイバが個々の PG::Connection オブジェクトを並行に使えるという点でスレッド安全です。
|
|
250
|
+
しかしながら1つ以上のスレッドないしファイバから同時に何らかの PG のオブジェクトにアクセスするのは安全ではありません。
|
|
251
|
+
そのため必ず、新しいスレッドないしファイバの一つ一つに対して新しいデータベースサーバー接続を開くか、スレッド安全な方法で接続を管理するActiveRecordのようなラッパーライブラリを使ってください。
|
|
200
252
|
|
|
201
253
|
以下のようなメッセージが標準エラー出力に表示された場合、恐らく複数のスレッドが1つの接続を使っています。
|
|
202
254
|
|
|
@@ -210,13 +262,12 @@ PGには個々のスレッドが別々の PG::Connection オブジェクトを
|
|
|
210
262
|
## Fiber IOスケジューラー対応
|
|
211
263
|
|
|
212
264
|
pg-1.3.0以降で、PgはRuby-3.0で導入された`Fiber.scheduler`に完全に対応しています。
|
|
213
|
-
Windowsでは、`Fiber.scheduler`対応はRuby-3.1以降で使えます。
|
|
214
265
|
`Fiber.scheduler`が走らせているスレッドに登録されている場合、起こりうる全てのブロッキングIO操作はそのスケジューラーを経由します。
|
|
215
266
|
同期的であったりブロックしたりするメソッド呼び出しについてもpgが内部的に非同期のlibpqインターフェースを使っているのはそれが理由です。
|
|
216
267
|
またlibpqの組み込み関数に代えてRubyのDNS解決を使っています。
|
|
217
268
|
|
|
218
|
-
内部的にPgは常にlibpqのノンブロッキング接続モードを使います。
|
|
219
|
-
|
|
269
|
+
内部的に Pg は常にlibpqのノンブロッキング接続モードを使います。
|
|
270
|
+
それからブロッキングモードで走っているように振舞いますが、すべてのブロッキングIOが、可能であれば登録された`Fiber.schedular`を通じて、確実にRubyで制御されます。
|
|
220
271
|
`PG::Connection.setnonblocking(true)`が呼ばれたらノンブロッキング状態が有効になったままになりますが、それ以降のブロッキング状態の制御が無効になるので、呼び出しているプログラムはブロッキング状態を自力で制御しなければなりません。
|
|
221
272
|
|
|
222
273
|
この規則の1つの例外には、`PG::Connection#lo_create`や外部ライブラリを使う認証メソッド(GSSAPI認証など)のような、大きめのオブジェクト用のメソッドがあります。これらは`Fiber.scheduler`と互換性がないため、ブロッキング状態は登録されたIOスケジューラに渡されません。つまり操作は適切に実行されますが、IO待ち状態に別のIOを扱うFiberから使用を切り替えてくることができなくなります。
|
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# pg
|
|
2
2
|
|
|
3
3
|
* home :: https://github.com/ged/ruby-pg
|
|
4
|
-
* docs :: http://deveiate.org/code/pg (English) ,
|
|
4
|
+
* docs :: http://deveiate.org/code/pg/README_md.html (English) ,
|
|
5
5
|
https://deveiate.org/code/pg/README_ja_md.html (Japanese)
|
|
6
|
-
* clog :: link:/
|
|
6
|
+
* clog :: link:/CHANGELOG.md
|
|
7
7
|
|
|
8
8
|
[](https://gitter.im/ged/ruby-pg?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
## Description
|
|
12
12
|
|
|
13
13
|
Pg is the Ruby interface to the [PostgreSQL RDBMS](http://www.postgresql.org/).
|
|
14
|
-
It works with [PostgreSQL
|
|
14
|
+
It works with [PostgreSQL 10 and later](http://www.postgresql.org/support/versioning/).
|
|
15
15
|
|
|
16
16
|
A small example usage:
|
|
17
17
|
```ruby
|
|
@@ -30,6 +30,9 @@ A small example usage:
|
|
|
30
30
|
end
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
See the PG::Connection class for query methods and the PG::Result class for information on working with the results of a query.
|
|
34
|
+
|
|
35
|
+
|
|
33
36
|
## Build Status
|
|
34
37
|
|
|
35
38
|
[](https://github.com/ged/ruby-pg/actions/workflows/source-gem.yml)
|
|
@@ -39,30 +42,34 @@ A small example usage:
|
|
|
39
42
|
|
|
40
43
|
## Requirements
|
|
41
44
|
|
|
42
|
-
* Ruby
|
|
43
|
-
* PostgreSQL
|
|
45
|
+
* Ruby 3.1 or newer
|
|
46
|
+
* PostgreSQL 10.x or later
|
|
47
|
+
* When installing the source gem: libpq with headers, -dev packages, etc.
|
|
44
48
|
|
|
45
|
-
It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
|
|
46
|
-
not regularly tested.
|
|
47
49
|
|
|
50
|
+
## How To Install
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
Install via RubyGems:
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
gem install pg
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
This installs the binary gem, specific to the running platform by default.
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
### Binary gem
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
+
The binary gems don't depend on the libpq package on the running system.
|
|
61
|
+
They have libpq builtin.
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
The gems for platform `x86_64-linux` and `aarch64-linux` run on Alpine Linux, but require the package `gcompat`, while the native gems for platform `*-linux-musl` work without that dependency.
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
There is one use case the binary gems don't support: Retrieval of connection [options from LDAP](https://www.postgresql.org/docs/current/libpq-ldap.html). To support this `libldap` would be necessary, but it has a lot of dependencies. It doesn't seem to be a widely used feature and that it's worth to support it. If it's necessary, the source gem can be forced.
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
### Source gem
|
|
68
|
+
|
|
69
|
+
The source gem can be forced by:
|
|
70
|
+
|
|
71
|
+
gem uninstall pg --all
|
|
72
|
+
gem install pg --platform ruby
|
|
66
73
|
|
|
67
74
|
You may need to specify the path to the 'pg_config' program installed with
|
|
68
75
|
Postgres:
|
|
@@ -73,6 +80,28 @@ If you're installing via Bundler, you can provide compile hints like so:
|
|
|
73
80
|
|
|
74
81
|
bundle config build.pg --with-pg-config=<path to pg_config>
|
|
75
82
|
|
|
83
|
+
### Bundler
|
|
84
|
+
|
|
85
|
+
To make sure, the necessary platforms and the source gem are fetched by bundler, they can be added like so
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
bundle lock --add-platform x86_64-linux
|
|
89
|
+
bundle lock --add-platform arm64-darwin
|
|
90
|
+
bundle lock --add-platform x64-mingw-ucrt
|
|
91
|
+
bundle lock --add-platform ruby
|
|
92
|
+
bundle package --all-platforms
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
A re-run of `bundle package` is also necessary after `bundle update`, in order to retrieve the new specific gems of all platforms.
|
|
96
|
+
|
|
97
|
+
If the binary gems don't work for some reason, it's easy to force the usage of the source gem in the Gemfile:
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
gem "pg", force_ruby_platform: true
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### More
|
|
104
|
+
|
|
76
105
|
See README-OS_X.rdoc for more information about installing under MacOS X, and
|
|
77
106
|
README-Windows.rdoc for Windows build/installation instructions.
|
|
78
107
|
|
|
@@ -85,6 +114,19 @@ can be found in [the `certs` directory](https://github.com/ged/ruby-pg/tree/mast
|
|
|
85
114
|
of the repository.
|
|
86
115
|
|
|
87
116
|
|
|
117
|
+
## Versioning
|
|
118
|
+
|
|
119
|
+
We tag and release gems according to the [Semantic Versioning](http://semver.org/) principle.
|
|
120
|
+
|
|
121
|
+
As a result of this policy, you can (and should) specify a dependency on this gem using the [Pessimistic Version Constraint](http://guides.rubygems.org/patterns/#pessimistic-version-constraint) with two digits of precision.
|
|
122
|
+
|
|
123
|
+
For example:
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
spec.add_dependency 'pg', '~> 1.0'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
|
|
88
130
|
## Type Casts
|
|
89
131
|
|
|
90
132
|
Pg can optionally type cast result values and query parameters in Ruby or
|
|
@@ -108,7 +150,7 @@ Very basic type casting can be enabled by:
|
|
|
108
150
|
But Pg's type casting is highly customizable. That's why it's divided into
|
|
109
151
|
2 layers:
|
|
110
152
|
|
|
111
|
-
### Encoders / Decoders (ext/pg_
|
|
153
|
+
### Encoders / Decoders (ext/pg_\*coder.c, lib/pg/\*coder.rb)
|
|
112
154
|
|
|
113
155
|
This is the lower layer, containing encoding classes that convert Ruby
|
|
114
156
|
objects for transmission to the DBMS and decoding classes to convert
|
|
@@ -141,7 +183,7 @@ The following PostgreSQL column types are supported by ruby-pg (TE = Text Encode
|
|
|
141
183
|
* Date: [TE](rdoc-ref:PG::TextEncoder::Date), [TD](rdoc-ref:PG::TextDecoder::Date), [BE](rdoc-ref:PG::BinaryEncoder::Date), [BD](rdoc-ref:PG::BinaryDecoder::Date)
|
|
142
184
|
* JSON and JSONB: [TE](rdoc-ref:PG::TextEncoder::JSON), [TD](rdoc-ref:PG::TextDecoder::JSON)
|
|
143
185
|
* Inet: [TE](rdoc-ref:PG::TextEncoder::Inet), [TD](rdoc-ref:PG::TextDecoder::Inet)
|
|
144
|
-
* Array: [TE](rdoc-ref:PG::TextEncoder::Array), [TD](rdoc-ref:PG::TextDecoder::Array)
|
|
186
|
+
* Array: [TE](rdoc-ref:PG::TextEncoder::Array), [TD](rdoc-ref:PG::TextDecoder::Array), [BE](rdoc-ref:PG::BinaryEncoder::Array), [BD](rdoc-ref:PG::BinaryDecoder::Array)
|
|
145
187
|
* Composite Type (also called "Row" or "Record"): [TE](rdoc-ref:PG::TextEncoder::Record), [TD](rdoc-ref:PG::TextDecoder::Record)
|
|
146
188
|
|
|
147
189
|
The following text and binary formats can also be encoded although they are not used as column type:
|
|
@@ -150,9 +192,9 @@ The following text and binary formats can also be encoded although they are not
|
|
|
150
192
|
* Literal for insertion into SQL string: [TE](rdoc-ref:PG::TextEncoder::QuotedLiteral)
|
|
151
193
|
* SQL-Identifier: [TE](rdoc-ref:PG::TextEncoder::Identifier), [TD](rdoc-ref:PG::TextDecoder::Identifier)
|
|
152
194
|
|
|
153
|
-
###
|
|
195
|
+
### TypeMap and derivations (ext/pg_type_map\*.c, lib/pg/type_map\*.rb)
|
|
154
196
|
|
|
155
|
-
A TypeMap defines which value will be converted by which encoder/decoder.
|
|
197
|
+
A PG::TypeMap defines which value will be converted by which encoder/decoder.
|
|
156
198
|
There are different type map strategies, implemented by several derivations
|
|
157
199
|
of this class. They can be chosen and configured according to the particular
|
|
158
200
|
needs for type casting. The default type map is PG::TypeMapAllStrings.
|
|
@@ -175,11 +217,12 @@ The following type maps are prefilled with type mappings from the PG::BasicTypeR
|
|
|
175
217
|
* PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
|
|
176
218
|
* PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
|
|
177
219
|
|
|
220
|
+
Several type maps can be chained by setting PG::TypeMap::DefaultTypeMappable#default_type_map .
|
|
178
221
|
|
|
179
222
|
## Thread support
|
|
180
223
|
|
|
181
|
-
PG is thread safe in such a way that different threads can use different PG::Connection objects concurrently.
|
|
182
|
-
However it is not safe to access any
|
|
224
|
+
PG is thread safe in such a way that different threads or fibers can use different PG::Connection objects concurrently.
|
|
225
|
+
However it is not safe to access any PG object simultaneously from more than one thread or fiber unless the object is frozen.
|
|
183
226
|
So make sure to open a new database server connection for every new thread or use a wrapper library like ActiveRecord that manages connections in a thread safe way.
|
|
184
227
|
|
|
185
228
|
If messages like the following are printed to stderr, you're probably using one connection from several threads:
|
|
@@ -194,18 +237,25 @@ If messages like the following are printed to stderr, you're probably using one
|
|
|
194
237
|
## Fiber IO scheduler support
|
|
195
238
|
|
|
196
239
|
Pg is fully compatible with `Fiber.scheduler` introduced in Ruby-3.0 since pg-1.3.0.
|
|
197
|
-
On Windows support for `Fiber.scheduler` is available on Ruby-3.1 or newer.
|
|
198
240
|
All possibly blocking IO operations are routed through the `Fiber.scheduler` if one is registered for the running thread.
|
|
199
241
|
That is why pg internally uses the asynchronous libpq interface even for synchronous/blocking method calls.
|
|
200
242
|
It also uses Ruby's DNS resolution instead of libpq's builtin functions.
|
|
201
243
|
|
|
202
244
|
Internally Pg always uses the nonblocking connection mode of libpq.
|
|
203
245
|
It then behaves like running in blocking mode but ensures, that all blocking IO is handled in Ruby through a possibly registered `Fiber.scheduler`.
|
|
204
|
-
When `PG::Connection
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
246
|
+
When `PG::Connection#setnonblocking(true)` is called then the nonblocking state stays enabled, but the additional handling of blocking states is disabled, so that the calling program has to handle blocking states on its own.
|
|
247
|
+
|
|
248
|
+
There are some exceptions to the `Fiber.scheduler` compatibility, so that blocking states are not passed to the registered IO scheduler.
|
|
249
|
+
That means the operation will work properly, but IO waiting states can not be used to switch to another Fiber doing IO:
|
|
250
|
+
|
|
251
|
+
* Methods for large objects like `PG::Connection#lo_create`
|
|
252
|
+
* Authentication methods using external libraries (like GSSAPI or LDAP authentication)
|
|
253
|
+
* LDAP lookup of connection parameters: https://www.postgresql.org/docs/current/libpq-ldap.html
|
|
254
|
+
* A connection string/hash with the `service` parameter set but not `host` and `port`.
|
|
255
|
+
`Thread.scheduler` compatible alternatives are:
|
|
256
|
+
* Set the service via `PGSERVICE`environment variable
|
|
257
|
+
* Set the `host` and `port` parameters explicit in the connection string/hash.
|
|
258
|
+
* Set the `hostaddr` in the service file.
|
|
209
259
|
|
|
210
260
|
|
|
211
261
|
## Ractor support
|