pg 1.5.4 → 1.6.1

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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/{History.md → CHANGELOG.md} +106 -4
  4. data/Gemfile +12 -3
  5. data/README-Windows.rdoc +1 -1
  6. data/README.ja.md +4 -4
  7. data/README.md +58 -17
  8. data/Rakefile +95 -14
  9. data/certs/kanis@comcard.de.pem +20 -0
  10. data/certs/larskanis-2024.pem +24 -0
  11. data/ext/errorcodes.def +4 -5
  12. data/ext/errorcodes.txt +2 -5
  13. data/ext/extconf.rb +161 -14
  14. data/ext/gvl_wrappers.c +13 -2
  15. data/ext/gvl_wrappers.h +33 -0
  16. data/ext/pg.c +17 -6
  17. data/ext/pg.h +9 -9
  18. data/ext/pg_binary_decoder.c +152 -0
  19. data/ext/pg_binary_encoder.c +211 -8
  20. data/ext/pg_cancel_connection.c +360 -0
  21. data/ext/pg_coder.c +54 -5
  22. data/ext/pg_connection.c +409 -167
  23. data/ext/pg_copy_coder.c +19 -15
  24. data/ext/pg_record_coder.c +7 -7
  25. data/ext/pg_result.c +11 -13
  26. data/ext/pg_text_decoder.c +4 -1
  27. data/ext/pg_text_encoder.c +37 -18
  28. data/ext/pg_tuple.c +2 -2
  29. data/ext/pg_type_map.c +1 -1
  30. data/ext/pg_type_map_all_strings.c +1 -1
  31. data/ext/pg_type_map_by_class.c +1 -1
  32. data/ext/pg_type_map_by_column.c +2 -1
  33. data/ext/pg_type_map_by_mri_type.c +1 -1
  34. data/ext/pg_type_map_by_oid.c +3 -1
  35. data/ext/pg_type_map_in_ruby.c +1 -1
  36. data/lib/pg/basic_type_map_for_queries.rb +15 -7
  37. data/lib/pg/basic_type_registry.rb +16 -4
  38. data/lib/pg/cancel_connection.rb +53 -0
  39. data/lib/pg/coder.rb +4 -2
  40. data/lib/pg/connection.rb +310 -167
  41. data/lib/pg/exceptions.rb +6 -0
  42. data/lib/pg/text_decoder/date.rb +3 -0
  43. data/lib/pg/text_decoder/json.rb +3 -0
  44. data/lib/pg/text_encoder/date.rb +1 -0
  45. data/lib/pg/text_encoder/inet.rb +3 -0
  46. data/lib/pg/text_encoder/json.rb +3 -0
  47. data/lib/pg/version.rb +1 -1
  48. data/lib/pg.rb +23 -8
  49. data/misc/yugabyte/Dockerfile +9 -0
  50. data/misc/yugabyte/docker-compose.yml +28 -0
  51. data/misc/yugabyte/pg-test.rb +45 -0
  52. data/pg.gemspec +8 -4
  53. data/ports/patches/krb5/1.21.3/0001-Allow-static-linking-krb5-library.patch +30 -0
  54. data/ports/patches/openssl/3.5.1/0001-aarch64-mingw.patch +21 -0
  55. data/ports/patches/postgresql/17.5/0001-Use-workaround-of-__builtin_setjmp-only-on-MINGW-on-.patch +42 -0
  56. data/ports/patches/postgresql/17.5/0001-libpq-Process-buffered-SSL-read-bytes-to-support-rec.patch +52 -0
  57. data/rakelib/pg_gem_helper.rb +64 -0
  58. data.tar.gz.sig +0 -0
  59. metadata +45 -47
  60. metadata.gz.sig +0 -0
  61. data/.appveyor.yml +0 -42
  62. data/.gems +0 -6
  63. data/.gemtest +0 -0
  64. data/.github/workflows/binary-gems.yml +0 -117
  65. data/.github/workflows/source-gem.yml +0 -141
  66. data/.gitignore +0 -22
  67. data/.hgsigs +0 -34
  68. data/.hgtags +0 -41
  69. data/.irbrc +0 -23
  70. data/.pryrc +0 -23
  71. data/.tm_properties +0 -21
  72. data/.travis.yml +0 -49
  73. data/Manifest.txt +0 -72
  74. data/Rakefile.cross +0 -298
  75. data/translation/.po4a-version +0 -7
  76. data/translation/po/all.pot +0 -936
  77. data/translation/po/ja.po +0 -1036
  78. data/translation/po4a.cfg +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e50a6829d4fe134af52d85429a3db06240fb6d228b96ef5b3fade98d38f4d199
4
- data.tar.gz: 281f5700e856a64a4a7c3157bbef4398345ac16698dbcdce54ed0408c0448457
3
+ metadata.gz: c220f1cc5cfd8e07690949fcf30a96abd8f710bc64f0c358eb6452288966a5b4
4
+ data.tar.gz: cd5f28d3098e2537e04dc218c8809b83308cb541e6b17891220559d33e2ada82
5
5
  SHA512:
6
- metadata.gz: 4ca887b068f003b077c17fca5e8297368f5236ed74ae16888a64312fed269110c455e2cd58105b5a23fbb53a1841b081ae215d3a4c3473815914642fcdde75cc
7
- data.tar.gz: 86599add8d622097727be30a1a05259c69d8c83fa73e1dad0f46125e95685a752a5df24f235158ff0d62dbfe99034aa8512e89bc39f26edf81a2540c466a6541
6
+ metadata.gz: f5de3fb30c6da95937d6c8913c9e172a348fa376edc6f06cc9333669c908a25cb2af85853aafbdc6839407f6b4aea93ca97e3b5b53f7182732664ecd6cd81e33
7
+ data.tar.gz: 00f5c6e8c359e81bf7c9145b7322583e511d440f681d32192430d9ce96772f1d71f8abce35e12ccf126d96a552205e799efee2533c54a84c623fa0aeee5c1c3c
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,9 +1,111 @@
1
+ ## v1.6.1 [2025-08-03] Lars Kanis <lars@greiz-reinsdorf.de>
2
+
3
+ - 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).
4
+ - Serialize CompositeCoder#dimensions only when set. [#652](https://github.com/ged/ruby-pg/pull/652)
5
+ 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.
6
+ - Remove dependency to MSYS2 package "postgresql" from binary Windows gem [#654](https://github.com/ged/ruby-pg/pull/654)
7
+
8
+
9
+ ## v1.6.0 [2025-07-27] Lars Kanis <lars@greiz-reinsdorf.de>
10
+
11
+ Added:
12
+
13
+ - Add binary gems for Ruby 3.4.
14
+ - 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).
15
+ - Update fat binary gem to OpenSSL-3.5.1 and PostgreSQL-17.5.
16
+ - Add a patch to libpq to avoid starvation on bigger SSL records, which some database engines other than vanilla PostgreSQL use.
17
+ This patch applies to platform specific binary gems only.
18
+ [#616](https://github.com/ged/ruby-pg/pull/616)
19
+ - Add support for new query cancel functions of PostgreSQL-17.
20
+ This adds the new class `PG::CancelConnection` which provides the ability to cancel a query per blocking or per non-blocking functions.
21
+ If the new functions are available they are used and the older are no longer compiled in.
22
+ This way we can get rid of reading out the internal `PGcancel` struct by `Connection#backend_key`.
23
+ [#614](https://github.com/ged/ruby-pg/pull/614)
24
+ - Add PG::BinaryDecoder::Array and PG::BinaryEncoder::Array to parse and encode PostgreSQL arrays in binary format.
25
+ [#603](https://github.com/ged/ruby-pg/pull/603)
26
+ - Add possibility to define the number of array dimensions to be encoded.
27
+ 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.
28
+ [#622](https://github.com/ged/ruby-pg/pull/622)
29
+ - Add Connection#set_chunked_rows_mode [#610](https://github.com/ged/ruby-pg/pull/610)
30
+ - 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.
31
+ [#611](https://github.com/ged/ruby-pg/pull/611)
32
+ - Add Connection#send_pipeline_sync, async_pipeline_sync and release GVL at PQ(sendP|P)ipelineSync.
33
+ [#612](https://github.com/ged/ruby-pg/pull/612)
34
+ - Add MINGW package dependency which is resolved by RubyInstaller.
35
+ [#617](https://github.com/ged/ruby-pg/pull/617)
36
+ - Change `conn.server_version` and `conn.protocol_version` to raise instead of return 0 on error.
37
+ [#632](https://github.com/ged/ruby-pg/pull/632)
38
+ - Fix connecting to multiple hosts after `connnect_timeout`.
39
+ [#637](https://github.com/ged/ruby-pg/pull/637)
40
+ - Fix making PG::BasicTypeMapForQueries shareable for Ractor in ruby-3.5.
41
+ [#636](https://github.com/ged/ruby-pg/pull/636)
42
+ - Fix missing array input verification in PG::TypeMapByColumn.
43
+ This could cause a segfault.
44
+ [#620](https://github.com/ged/ruby-pg/pull/620)
45
+ - Rename `History.md` to `CHANGELOG.md`, which is more common.
46
+ [#642](https://github.com/ged/ruby-pg/pull/642)
47
+
48
+ Removed:
49
+
50
+ - Drop support of Ruby < 2.7 [#606](https://github.com/ged/ruby-pg/pull/606)
51
+ - Drop support of PostgreSQL < 10 [#606](https://github.com/ged/ruby-pg/pull/606)
52
+ - Remove workaround for Truffleruby < 21.3.0 [#613](https://github.com/ged/ruby-pg/pull/613)
53
+
54
+
55
+ ## v1.5.9 [2024-10-24] Lars Kanis <lars@greiz-reinsdorf.de>
56
+
57
+ - Enable thread safety in static OpenSSL build for Windows. [#595](https://github.com/ged/ruby-pg/pull/595)
58
+ - Remove raising `conect_timeout` from 1 to 2 seconds. [#590](https://github.com/ged/ruby-pg/pull/590)
59
+ - Fix binary copy_data in Ractor context. [#594](https://github.com/ged/ruby-pg/pull/594)
60
+ - Exclude CI files and hidden files from built gem. [#591](https://github.com/ged/ruby-pg/pull/591)
61
+ This is to simplify security inspection.
62
+ - Update error classes to PostgreSQL-17.
63
+ - Update Windows fat binary gem to OpenSSL-3.4.0 and PostgreSQL-17.0.
64
+
65
+
66
+ ## v1.5.8 [2024-09-06] Lars Kanis <lars@greiz-reinsdorf.de>
67
+
68
+ - Fix host list duplication every time conn.reset is used. [#586](https://github.com/ged/ruby-pg/pull/586)
69
+ - Add default decoder for anonymous record types to BasicTypeRegistry [#579](https://github.com/ged/ruby-pg/pull/579)
70
+ - Update Windows fat binary gem to OpenSSL-3.3.2 and PostgreSQL-16.4.
71
+
72
+
73
+ ## v1.5.7 [2024-07-28] Lars Kanis <lars@greiz-reinsdorf.de>
74
+
75
+ - Remove deprecated use of fptr->fd.[#562](https://github.com/ged/ruby-pg/pull/562)
76
+ Direct access is disallowed since ruby-3.4.
77
+ - Make `pgconn_connect_poll` close the socket prior to calling `PQconnectPoll`. [#564](https://github.com/ged/ruby-pg/pull/564)
78
+ This could result in an exception while connecting when used multi threaded.
79
+ - Fix several typos and improve spelling in documentation and code. [#566](https://github.com/ged/ruby-pg/pull/566)
80
+ - Add missing PG::RollbackTransaction as an option to exit conn.transaction. [#560](https://github.com/ged/ruby-pg/pull/560)
81
+ Usage like in rails: https://api.rubyonrails.org/classes/ActiveRecord/Rollback.html
82
+ - Don't print a warning when bigdecimal is required on ruby-3.4+ [#574](https://github.com/ged/ruby-pg/pull/574)
83
+ - Update Windows fat binary gem to OpenSSL-3.3.1 and PostgreSQL-16.3.
84
+
85
+
86
+ ## v1.5.6 [2024-03-01] Lars Kanis <lars@greiz-reinsdorf.de>
87
+
88
+ - Renew address resolution (DNS) in conn.reset. [#558](https://github.com/ged/ruby-pg/pull/558)
89
+ This is important, if DNS is used for load balancing, etc.
90
+ - Make bigdecimal an optional dependency. [#556](https://github.com/ged/ruby-pg/pull/556)
91
+ It's a gem in ruby-3.4+, so that users shouldn't be forced to use it.
92
+
93
+
94
+ ## v1.5.5 [2024-02-15] Lars Kanis <lars@greiz-reinsdorf.de>
95
+
96
+ - Explicitly retype timespec fields to int64_t to fix compatibility with 32bit arches. [#547](https://github.com/ged/ruby-pg/pull/547)
97
+ - Fix possible buffer overflows in PG::BinaryDecoder::CopyRow on 32 bit systems. [#548](https://github.com/ged/ruby-pg/pull/548)
98
+ - Add binary Windows gems for Ruby 3.3.
99
+ - Update Windows fat binary gem to OpenSSL-3.2.1 and PostgreSQL-16.2.
100
+
101
+
1
102
  ## v1.5.4 [2023-09-01] Lars Kanis <lars@greiz-reinsdorf.de>
2
103
 
3
104
  - Fix compiling the pg extension with MSVC 2022. [#535](https://github.com/ged/ruby-pg/pull/535)
4
105
  - Set PG::Connection's encoding even if setting client_encoding on connection startup fails. [#541](https://github.com/ged/ruby-pg/pull/541)
5
106
  - Don't set the server's client_encoding if it's unnecessary. [#542](https://github.com/ged/ruby-pg/pull/542)
6
107
  This is important for connection proxies, who disallow configuration settings.
108
+ - Update Windows fat binary gem to OpenSSL-3.1.2 and PostgreSQL-15.4.
7
109
 
8
110
 
9
111
  ## v1.5.3 [2023-04-28] Lars Kanis <lars@greiz-reinsdorf.de>
@@ -75,7 +177,7 @@ Removed:
75
177
  Repository:
76
178
 
77
179
  - `rake test` tries to find PostgreSQL server commands by pg_config [#503](https://github.com/ged/ruby-pg/pull/503)
78
- So there's no need to set the PATH manuelly any longer.
180
+ So there's no need to set the PATH manually any longer.
79
181
 
80
182
 
81
183
  ## v1.4.6 [2023-02-26] Lars Kanis <lars@greiz-reinsdorf.de>
@@ -144,7 +246,7 @@ Added:
144
246
  Bugfixes:
145
247
 
146
248
  - Try IPv6 and IPv4 addresses, if DNS resolves to both. [#452](https://github.com/ged/ruby-pg/pull/452)
147
- - Re-add block-call semantics to PG::Connection.new accidently removed in pg-1.3.0. [#454](https://github.com/ged/ruby-pg/pull/454)
249
+ - Re-add block-call semantics to PG::Connection.new accidentally removed in pg-1.3.0. [#454](https://github.com/ged/ruby-pg/pull/454)
148
250
  - Handle client error after all data consumed in #copy_data for output. [#455](https://github.com/ged/ruby-pg/pull/455)
149
251
  - Avoid spurious keyword argument warning on Ruby 2.7. [#456](https://github.com/ged/ruby-pg/pull/456)
150
252
  - Change connection setup to respect connect_timeout parameter. [#459](https://github.com/ged/ruby-pg/pull/459)
@@ -183,7 +285,7 @@ Bugfixes:
183
285
 
184
286
  - Don't leak IO in case of connection errors. [#439](https://github.com/ged/ruby-pg/pull/439)
185
287
  Previously it was kept open until the PG::Connection was garbage collected.
186
- - Fix a performance regession in conn.get_result noticed in single row mode. [#442](https://github.com/ged/ruby-pg/pull/442)
288
+ - Fix a performance regression in conn.get_result noticed in single row mode. [#442](https://github.com/ged/ruby-pg/pull/442)
187
289
  - Fix occasional error Errno::EBADF (Bad file descriptor) while connecting. [#444](https://github.com/ged/ruby-pg/pull/444)
188
290
  - Fix compatibility of res.stream_each* methods with Fiber.scheduler. [#446](https://github.com/ged/ruby-pg/pull/446)
189
291
  - Remove FL_TEST and FL_SET, which are MRI-internal. [#437](https://github.com/ged/ruby-pg/pull/437)
@@ -269,7 +371,7 @@ Type cast enhancements:
269
371
  - Add PG::BasicTypeMapForQueries::BinaryData for encoding of bytea columns. [#348](https://github.com/ged/ruby-pg/pull/348)
270
372
  - Reduce time to build coder maps and permit to reuse them for several type maps per PG::BasicTypeRegistry::CoderMapsBundle.new(conn) . [#376](https://github.com/ged/ruby-pg/pull/376)
271
373
  - Make BasicTypeRegistry a class and use a global default instance of it.
272
- Now a local type registry can be instanciated and given to the type map, to avoid changing shared global states.
374
+ Now a local type registry can be instantiated and given to the type map, to avoid changing shared global states.
273
375
  - Allow PG::BasicTypeMapForQueries to take a Proc as callback for undefined types.
274
376
 
275
377
  Other Enhancements:
data/Gemfile CHANGED
@@ -5,10 +5,19 @@ gemspec
5
5
 
6
6
  source "https://rubygems.org/"
7
7
 
8
- group :development, :test do
8
+ group :development do
9
+ gem "rdoc", "~> 6.4"
10
+ gem "mini_portile2", "~> 2.1"
11
+ end
12
+
13
+ group :test do
9
14
  gem "bundler", ">= 1.16", "< 3.0"
10
15
  gem "rake-compiler", "~> 1.0"
11
- gem "rake-compiler-dock", "~> 1.0"
12
- gem "rdoc", "~> 6.4"
16
+ gem "rake-compiler-dock", "~> 1.9.1"
13
17
  gem "rspec", "~> 3.5"
18
+ # "bigdecimal" is a gem on ruby-3.4+ and it's optional for ruby-pg.
19
+ # Specs should succeed without it, but 4 examples are then excluded.
20
+ # With bigdecimal commented out here, corresponding tests are omitted on ruby-3.4+ but are executed on ruby < 3.4.
21
+ # That way we can check both situations in CI.
22
+ # gem "bigdecimal", "~> 3.0"
14
23
  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:windows
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  * ホーム :: https://github.com/ged/ruby-pg
4
4
  * ドキュメント :: http://deveiate.org/code/pg (英語)、 https://deveiate.org/code/pg/README_ja_md.html (日本語)
5
- * 変更履歴 :: link:/History.md
5
+ * 変更履歴 :: link:/CHANGELOG.md
6
6
 
7
7
  [![https://gitter.im/ged/ruby-pg
8
8
  でチャットに参加](https://badges.gitter.im/Join%20Chat.svg)](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
- 9.3以降](http://www.postgresql.org/support/versioning/)で動作します。
15
+ 10以降](http://www.postgresql.org/support/versioning/)で動作します。
16
16
 
17
17
  簡単な使用例は次の通りです。
18
18
  ```ruby
@@ -41,8 +41,8 @@ Actionsのビルド状況](https://github.com/ged/ruby-pg/actions/workflows/sour
41
41
 
42
42
  ## 要件
43
43
 
44
- * Ruby 2.5かそれより新しいバージョン
45
- * PostgreSQL 9.3.xかそれ以降のバージョン(ヘッダー付属のもの、例えば-devの名前のパッケージ)。
44
+ * Ruby 2.7かそれより新しいバージョン
45
+ * PostgreSQL 10.xかそれ以降のバージョン(ヘッダー付属のもの、例えば-devの名前のパッケージ)。
46
46
 
47
47
  それより前のバージョンのRubyやPostgreSQLでも通常は同様に動作しますが、定期的なテストはされていません。
48
48
 
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  * home :: https://github.com/ged/ruby-pg
4
4
  * docs :: http://deveiate.org/code/pg (English) ,
5
5
  https://deveiate.org/code/pg/README_ja_md.html (Japanese)
6
- * clog :: link:/History.md
6
+ * clog :: link:/CHANGELOG.md
7
7
 
8
8
  [![Join the chat at https://gitter.im/ged/ruby-pg](https://badges.gitter.im/Join%20Chat.svg)](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 9.3 and later](http://www.postgresql.org/support/versioning/).
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
@@ -39,30 +39,35 @@ A small example usage:
39
39
 
40
40
  ## Requirements
41
41
 
42
- * Ruby 2.5 or newer
43
- * PostgreSQL 9.3.x or later (with headers, -dev packages, etc).
42
+ * Ruby 2.7 or newer
43
+ * PostgreSQL 10.x or later
44
+ * When installing the source gem: libpq with headers, -dev packages, etc.
44
45
 
45
- It usually works with earlier versions of Ruby/PostgreSQL as well, but those are
46
- not regularly tested.
47
46
 
47
+ ## How To Install
48
48
 
49
- ## Versioning
49
+ Install via RubyGems:
50
50
 
51
- We tag and release gems according to the [Semantic Versioning](http://semver.org/) principle.
51
+ gem install pg
52
52
 
53
- 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.
53
+ This installs the binary gem, specific to the running platform by default.
54
54
 
55
- For example:
55
+ ### Binary gem
56
56
 
57
- ```ruby
58
- spec.add_dependency 'pg', '~> 1.0'
59
- ```
57
+ The binary gems don't depend on the libpq package on the running system.
58
+ They have libpq builtin.
60
59
 
61
- ## How To Install
60
+ The gems for platform `x86_64-linux` and `aarch64-linux` run on Alpine Linux, but require the package `gcompat` there as long as we don't provide a native gem for platform `x86_64-linux-musl`. Install this package like so:
62
61
 
63
- Install via RubyGems:
62
+ apk add gcompat
64
63
 
65
- gem install pg
64
+ 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.
65
+
66
+ ### Source gem
67
+
68
+ The source gem can be forced by:
69
+
70
+ gem install pg --platform ruby
66
71
 
67
72
  You may need to specify the path to the 'pg_config' program installed with
68
73
  Postgres:
@@ -73,6 +78,28 @@ If you're installing via Bundler, you can provide compile hints like so:
73
78
 
74
79
  bundle config build.pg --with-pg-config=<path to pg_config>
75
80
 
81
+ ### Bundler
82
+
83
+ To make sure, the necessary platforms and the source gem are fetched by bundler, they can be added like so
84
+
85
+ ```
86
+ bundle lock --add-platform x86_64-linux
87
+ bundle lock --add-platform arm64-darwin
88
+ bundle lock --add-platform x64-mingw-ucrt
89
+ bundle lock --add-platform ruby
90
+ bundle package --all-platforms
91
+ ```
92
+
93
+ A re-run of `bundle package` is also necessary after `bundle update`, in order to retrieve the new specific gems of all platforms.
94
+
95
+ If the binary gems don't work for some reason, it's easy to force the usage of the source gem in the Gemfile:
96
+
97
+ ```
98
+ gem "pg", force_ruby_platform: true
99
+ ```
100
+
101
+ ### More
102
+
76
103
  See README-OS_X.rdoc for more information about installing under MacOS X, and
77
104
  README-Windows.rdoc for Windows build/installation instructions.
78
105
 
@@ -85,6 +112,19 @@ can be found in [the `certs` directory](https://github.com/ged/ruby-pg/tree/mast
85
112
  of the repository.
86
113
 
87
114
 
115
+ ## Versioning
116
+
117
+ We tag and release gems according to the [Semantic Versioning](http://semver.org/) principle.
118
+
119
+ 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.
120
+
121
+ For example:
122
+
123
+ ```ruby
124
+ spec.add_dependency 'pg', '~> 1.0'
125
+ ```
126
+
127
+
88
128
  ## Type Casts
89
129
 
90
130
  Pg can optionally type cast result values and query parameters in Ruby or
@@ -141,7 +181,7 @@ The following PostgreSQL column types are supported by ruby-pg (TE = Text Encode
141
181
  * 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
182
  * JSON and JSONB: [TE](rdoc-ref:PG::TextEncoder::JSON), [TD](rdoc-ref:PG::TextDecoder::JSON)
143
183
  * 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)
184
+ * 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
185
  * Composite Type (also called "Row" or "Record"): [TE](rdoc-ref:PG::TextEncoder::Record), [TD](rdoc-ref:PG::TextDecoder::Record)
146
186
 
147
187
  The following text and binary formats can also be encoded although they are not used as column type:
@@ -175,6 +215,7 @@ The following type maps are prefilled with type mappings from the PG::BasicTypeR
175
215
  * PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
176
216
  * PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes
177
217
 
218
+ Several type maps can be chained by setting PG::TypeMap::DefaultTypeMappable#default_type_map .
178
219
 
179
220
  ## Thread support
180
221
 
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
1
  # -*- rake -*-
2
2
 
3
+ # Enable english error messages, as some specs depend on them
4
+ ENV["LANG"] = "C"
5
+
3
6
  require 'rbconfig'
4
7
  require 'pathname'
5
8
  require 'tmpdir'
@@ -8,6 +11,7 @@ require 'rake/clean'
8
11
  require 'rspec/core/rake_task'
9
12
  require 'bundler'
10
13
  require 'bundler/gem_helper'
14
+ require_relative "rakelib/pg_gem_helper"
11
15
 
12
16
  # Build directory constants
13
17
  BASEDIR = Pathname( __FILE__ ).dirname
@@ -28,10 +32,10 @@ CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
28
32
  CLEAN.include "lib/*/libpq.dll"
29
33
  CLEAN.include "lib/pg_ext.*"
30
34
  CLEAN.include "lib/pg/postgresql_lib_path.rb"
35
+ CLEAN.include "ports/*.installed"
36
+ CLEAN.include "ports/*mingw*", "ports/*linux*", "ports/*darwin*"
31
37
 
32
- load 'Rakefile.cross'
33
-
34
- Bundler::GemHelper.install_tasks
38
+ PgGemHelper.install_tasks
35
39
  $gem_spec = Bundler.load_gemspec(GEMSPEC)
36
40
 
37
41
  desc "Turn on warnings and debugging in the build."
@@ -39,6 +43,25 @@ task :maint do
39
43
  ENV['MAINTAINER_MODE'] = 'yes'
40
44
  end
41
45
 
46
+ CrossLibrary = Struct.new :platform, :openssl_config, :toolchain
47
+ CrossLibraries = [
48
+ ['aarch64-mingw-ucrt', 'mingwarm64', 'aarch64-w64-mingw32'],
49
+ ['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
50
+ ['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
51
+ ['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
52
+ ['x86_64-linux', 'linux-x86_64', 'x86_64-linux-gnu'],
53
+ ['x86_64-linux-musl', 'linux-x86_64', 'x86_64-unknown-linux-musl'],
54
+ ['aarch64-linux', 'linux-aarch64', 'aarch64-linux-gnu'],
55
+ ['aarch64-linux-musl', 'linux-aarch64', 'aarch64-linux-musl'],
56
+ ['x86_64-darwin', 'darwin64-x86_64', 'x86_64-apple-darwin'],
57
+ ['arm64-darwin', 'darwin64-arm64', 'arm64-apple-darwin'],
58
+ ].map do |platform, openssl_config, toolchain|
59
+ CrossLibrary.new platform, openssl_config, toolchain
60
+ end
61
+
62
+ # Register binary gems to be pushed to rubygems.org
63
+ Bundler::GemHelper.instance.cross_platforms = CrossLibraries.map(&:platform)
64
+
42
65
  # Rake-compiler task
43
66
  Rake::ExtensionTask.new do |ext|
44
67
  ext.name = 'pg_ext'
@@ -47,24 +70,82 @@ Rake::ExtensionTask.new do |ext|
47
70
  ext.lib_dir = 'lib'
48
71
  ext.source_pattern = "*.{c,h}"
49
72
  ext.cross_compile = true
50
- ext.cross_platform = CrossLibraries.map(&:for_platform)
51
73
 
52
- ext.cross_config_options += CrossLibraries.map do |lib|
74
+ # Activate current cross compiled platform only.
75
+ # This is to work around the issue that `linux` platform is selected in `linux-musl` image.
76
+ ext.cross_platform = CrossLibraries.map(&:platform).select do |pl|
77
+ m = ENV["RCD_IMAGE"]&.match(/:(?<ruby_ver>[\d\.]+)-mri-(?<platform>[-\w]+)$/)
78
+ m && m[:platform] == pl
79
+ end
80
+
81
+ ext.cross_config_options += CrossLibraries.map do |xlib|
53
82
  {
54
- lib.for_platform => [
55
- "--enable-windows-cross",
56
- "--with-pg-include=#{lib.static_postgresql_incdir}",
57
- "--with-pg-lib=#{lib.static_postgresql_libdir}",
58
- # libpq-fe.h resides in src/interfaces/libpq/ before make install
59
- "--with-opt-include=#{lib.static_postgresql_libdir}",
83
+ xlib.platform => [
84
+ "--with-cross-build=#{xlib.platform}",
85
+ "--with-openssl-platform=#{xlib.openssl_config}",
86
+ "--with-toolchain=#{xlib.toolchain}",
60
87
  ]
61
88
  }
62
89
  end
63
90
 
64
- # Add libpq.dll to windows binary gemspec
91
+ # Add libpq.dll/.so to fat binary gemspecs
65
92
  ext.cross_compiling do |spec|
66
- spec.files << "lib/#{spec.platform}/libpq.dll"
93
+ spec.files << "ports/#{spec.platform.to_s}/lib/libpq-ruby-pg.so.1" if spec.platform.to_s =~ /linux/
94
+ spec.files << "ports/#{spec.platform.to_s}/lib/libpq-ruby-pg.1.dylib" if spec.platform.to_s =~ /darwin/
95
+ spec.files << "ports/#{spec.platform.to_s}/lib/libpq.dll" if spec.platform.to_s =~ /mingw|mswin/
96
+
97
+ # Binary gems don't postgresql header+lib files
98
+ spec.metadata.delete("msys2_mingw_dependencies")
99
+ end
100
+ end
101
+
102
+ task 'gem:native:prepare' do
103
+ require 'io/console'
104
+ require 'rake_compiler_dock'
105
+
106
+ # Copy gem signing key and certs to be accessible from the docker container
107
+ mkdir_p 'build/gem'
108
+ sh "cp ~/.gem/gem-*.pem build/gem/ || true"
109
+ sh "bundle package"
110
+ begin
111
+ OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
112
+ rescue OpenSSL::PKey::PKeyError
113
+ ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
114
+ retry
115
+ end
116
+ end
117
+
118
+ task 'install_darwin_mig', [:arch] do |t, args|
119
+ sh <<~EOT
120
+ rm -rf bootstrap_cmds &&
121
+ git clone --branch=cross_platform https://github.com/markmentovai/bootstrap_cmds &&
122
+ cd bootstrap_cmds &&
123
+ autoreconf --install &&
124
+ sh configure &&
125
+ make &&
126
+ sed -E -i 's/^cppflags=(.*)/cppflags=(\\1 "-D#{args[:arch]}" "-I\\/opt\\/osxcross\\/target\\/SDK\\/MacOSX11.1.sdk\\/usr\\/include")/' migcom.tproj/mig.sh &&
127
+ sudo make install
128
+ EOT
129
+ end
130
+
131
+ CrossLibraries.each do |xlib|
132
+ platform = xlib.platform
133
+ desc "Build fat binary gem for platform #{platform}"
134
+ task "gem:native:#{platform}" => ['gem:native:prepare'] do
135
+ RakeCompilerDock.sh <<-EOT, platform: platform
136
+ #{ "sudo apt-get update && sudo apt-get install -y bison flex &&" if platform =~ /darwin/ }
137
+ #{ # remove nm on Linux to suppress PostgreSQL's check for exit which raises thread_exit as a false positive:
138
+ "sudo mv `which nm` `which nm`.bak &&" if platform =~ /linux/ }
139
+ sudo apt-get update && sudo apt-get install -y bison flex &&
140
+ (cp build/gem/gem-*.pem ~/.gem/ || true) &&
141
+ bundle install --local &&
142
+ #{ "rake install_darwin_mig[__arm64__]" if platform =~ /arm64-darwin/ }
143
+ #{ "rake install_darwin_mig[__x86_64__]" if platform =~ /x86_64-darwin/ }
144
+ rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKEOPTS=-j`nproc` RUBY_CC_VERSION=#{RakeCompilerDock.ruby_cc_version("~>2.7", "~>3.0")}
145
+ EOT
67
146
  end
147
+ desc "Build the native binary gems"
148
+ multitask 'gem:native' => "gem:native:#{platform}"
68
149
  end
69
150
 
70
151
  RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
@@ -91,7 +172,7 @@ end
91
172
 
92
173
  desc "Update list of server error codes"
93
174
  task :update_error_codes do
94
- URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_15_0"
175
+ URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_17_0"
95
176
 
96
177
  ERRORCODES_TXT = "ext/errorcodes.txt"
97
178
  sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDLjCCAhagAwIBAgIBCzANBgkqhkiG9w0BAQsFADA9MQ4wDAYDVQQDDAVrYW5p
3
+ czEXMBUGCgmSJomT8ixkARkWB2NvbWNhcmQxEjAQBgoJkiaJk/IsZAEZFgJkZTAe
4
+ Fw0yMzA0MjgwOTI0NDhaFw0yNDA0MjcwOTI0NDhaMD0xDjAMBgNVBAMMBWthbmlz
5
+ MRcwFQYKCZImiZPyLGQBGRYHY29tY2FyZDESMBAGCgmSJomT8ixkARkWAmRlMIIB
6
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApop+rNmg35bzRugZ21VMGqI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
20
+ x+LU7feIH7lZ//3buiyD03gLAEtHXai0Y+/VfuWIpwYJAl2BO/tU7FS/dtbJq9oc
21
+ dI36Yyzy+BrCM0WT4oCsagePNb97FaNhl4F6sM5JEPT0ZPxRx0i3G4TNNIYziVos
22
+ 5wFER6XhvvLDFAMh/jMg+s7Wd5SbSHgHNSUaUGVtdWkVPOer6oF0aLdZUR3CETkn
23
+ 5nWXZma/BUd3YgYA/Xumc6QQqIS4p7mr
24
+ -----END CERTIFICATE-----
data/ext/errorcodes.def CHANGED
@@ -453,6 +453,10 @@
453
453
  VALUE klass = define_error_class( "IdleInTransactionSessionTimeout", "25" );
454
454
  register_error_class( "25P03", klass );
455
455
  }
456
+ {
457
+ VALUE klass = define_error_class( "TransactionTimeout", "25" );
458
+ register_error_class( "25P04", klass );
459
+ }
456
460
  {
457
461
  VALUE klass = define_error_class( "InvalidSqlStatementName", NULL );
458
462
  register_error_class( "26000", klass );
@@ -885,11 +889,6 @@
885
889
  VALUE klass = define_error_class( "DuplicateFile", "58" );
886
890
  register_error_class( "58P02", klass );
887
891
  }
888
- {
889
- VALUE klass = define_error_class( "SnapshotTooOld", NULL );
890
- register_error_class( "72000", klass );
891
- register_error_class( "72", klass );
892
- }
893
892
  {
894
893
  VALUE klass = define_error_class( "ConfigFileError", NULL );
895
894
  register_error_class( "F0000", klass );
data/ext/errorcodes.txt CHANGED
@@ -2,7 +2,7 @@
2
2
  # errcodes.txt
3
3
  # PostgreSQL error codes
4
4
  #
5
- # Copyright (c) 2003-2022, PostgreSQL Global Development Group
5
+ # Copyright (c) 2003-2024, PostgreSQL Global Development Group
6
6
  #
7
7
  # This list serves as the basis for generating source files containing error
8
8
  # codes. It is kept in a common format to make sure all these source files have
@@ -252,6 +252,7 @@ Section: Class 25 - Invalid Transaction State
252
252
  25P01 E ERRCODE_NO_ACTIVE_SQL_TRANSACTION no_active_sql_transaction
253
253
  25P02 E ERRCODE_IN_FAILED_SQL_TRANSACTION in_failed_sql_transaction
254
254
  25P03 E ERRCODE_IDLE_IN_TRANSACTION_SESSION_TIMEOUT idle_in_transaction_session_timeout
255
+ 25P04 E ERRCODE_TRANSACTION_TIMEOUT transaction_timeout
255
256
 
256
257
  Section: Class 26 - Invalid SQL Statement Name
257
258
 
@@ -439,10 +440,6 @@ Section: Class 58 - System Error (errors external to PostgreSQL itself)
439
440
  58P01 E ERRCODE_UNDEFINED_FILE undefined_file
440
441
  58P02 E ERRCODE_DUPLICATE_FILE duplicate_file
441
442
 
442
- Section: Class 72 - Snapshot Failure
443
- # (class borrowed from Oracle)
444
- 72000 E ERRCODE_SNAPSHOT_TOO_OLD snapshot_too_old
445
-
446
443
  Section: Class F0 - Configuration File Error
447
444
 
448
445
  # (PostgreSQL-specific error class)