Skip to content

Add support for new query cancel functions of PostgreSQL-17#614

Merged
larskanis merged 5 commits into
ged:masterfrom
larskanis:cancon
Nov 26, 2024
Merged

Add support for new query cancel functions of PostgreSQL-17#614
larskanis merged 5 commits into
ged:masterfrom
larskanis:cancon

Conversation

@larskanis

Copy link
Copy Markdown
Collaborator

This adds the new class PG::CancelConnection which provides the ability to cancel a query per blocking or per non-blocking functions. If the new functions are available they are used and the older no longer compiled in.

This way we can get rid of reading out the internal PGcancel struct by Connection#backend_key .

@larskanis larskanis force-pushed the cancon branch 4 times, most recently from 2f50f96 to dac71cd Compare November 26, 2024 12:42
This adds the new class `PG::CancelConnection` which provides the ability to cancel a query per blocking or per non-blocking functions.
If the new functions are available they are used and the older no longer compiled in.

This way we can get rid of reading out the internal `PGcancel` struct by `Connection#backend_key` .
used in PG::Connection and PG::CancelConnection
@larskanis larskanis merged commit 36a7b1a into ged:master Nov 26, 2024
@larskanis larskanis deleted the cancon branch November 26, 2024 17:11
yahonda added a commit to yahonda/rails that referenced this pull request Jul 1, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
the format of the cancel request key, which causes the following test to fail on Rails main.

This change was introduced in PostgreSQL core via
postgres/postgres@a460251

The issue is already addressed in ged/ruby-pg#614
and the fix is included in the upcoming pg gem version v1.6.0 (currently released as v1.6.0.rc1).

The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via
ged/ruby-pg#606

Rails main currently claims support for PostgreSQL 9.3+, which is incompatible with PostgreSQL 18
unless we raise the minimum supported version to 10.

I propose updating Rails main to require PostgreSQL 10 or newer, to ensure compatibility with PostgreSQL 18 and future releases.

- PostgreSQL 18 Beta 1

```
$ psql -d postgres
psql (18beta1)
Type "help" for help.

postgres=# select version();
                              version
--------------------------------------------------------------------
 PostgreSQL 18beta1 on x86_64-linux, compiled by gcc-15.1.1, 64-bit
(1 row)

postgres=#
```

- With pg 1.5.9 ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt fails
```
$ bundle info pg
  * pg (1.5.9)
    Summary: Pg is the Ruby interface to the PostgreSQL RDBMS
    Homepage: https://github.com/ged/ruby-pg
    Documentation: http://deveiate.org/code/pg
    Source Code: https://github.com/ged/ruby-pg
    Changelog: https://github.com/ged/ruby-pg/blob/master/History.md
    Path: /home/yahonda/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9
    Reverse Dependencies:
        queue_classic (4.0.0) depends on pg (>= 1.1, < 2.0)
$
$ ARCONN=postgresql bin/test test/cases/adapters/postgresql/transaction_test.rb -n test_raises_Interrupt_when_canceling_statement_via_interrupt
Using postgresql
Run options: -n test_raises_Interrupt_when_canceling_statement_via_interrupt --seed 17678

F

Failure:
ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt [test/cases/adapters/postgresql/transaction_test.rb:199]:
Expected 10.014372003 to be < 5.

bin/test test/cases/adapters/postgresql/transaction_test.rb:183

Finished in 10.067954s, 0.0993 runs/s, 0.1987 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
```

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Jul 1, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
the format of the cancel request key, which causes the following test to fail on Rails main.

This change was introduced in PostgreSQL core via
postgres/postgres@a460251

The issue is already addressed in ged/ruby-pg#614
and the fix is included in the upcoming pg gem version v1.6.0 (currently released as v1.6.0.rc1).

The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via
ged/ruby-pg#606

Rails main currently claims support for PostgreSQL 9.3+, which is incompatible with PostgreSQL 18
unless we raise the minimum supported version to 10.

I propose updating Rails main to require PostgreSQL 10 or newer, to ensure compatibility with PostgreSQL 18 and future releases.

- PostgreSQL 18 Beta 1

```
$ psql -d postgres
psql (18beta1)
Type "help" for help.

postgres=# select version();
                              version
--------------------------------------------------------------------
 PostgreSQL 18beta1 on x86_64-linux, compiled by gcc-15.1.1, 64-bit
(1 row)

postgres=#
```

- With pg 1.5.9 ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt fails
```
$ bundle info pg
  * pg (1.5.9)
    Summary: Pg is the Ruby interface to the PostgreSQL RDBMS
    Homepage: https://github.com/ged/ruby-pg
    Documentation: http://deveiate.org/code/pg
    Source Code: https://github.com/ged/ruby-pg
    Changelog: https://github.com/ged/ruby-pg/blob/master/History.md
    Path: /home/yahonda/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9
    Reverse Dependencies:
        queue_classic (4.0.0) depends on pg (>= 1.1, < 2.0)
$
$ ARCONN=postgresql bin/test test/cases/adapters/postgresql/transaction_test.rb -n test_raises_Interrupt_when_canceling_statement_via_interrupt
Using postgresql
Run options: -n test_raises_Interrupt_when_canceling_statement_via_interrupt --seed 17678

F

Failure:
ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt [test/cases/adapters/postgresql/transaction_test.rb:199]:
Expected 10.014372003 to be < 5.

bin/test test/cases/adapters/postgresql/transaction_test.rb:183

Finished in 10.067954s, 0.0993 runs/s, 0.1987 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
```

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Jul 1, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
the format of the cancel request key, which causes the following test to fail on Rails main.

This change was introduced in PostgreSQL core via
postgres/postgres@a460251

The issue is already addressed in ged/ruby-pg#614
and the fix is included in the upcoming pg gem version v1.6.0 (currently released as v1.6.0.rc1).

The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via
ged/ruby-pg#606

Rails main currently claims support for PostgreSQL 9.3+, which is incompatible with PostgreSQL 18
unless we raise the minimum supported version to 10.

I propose updating Rails main to require PostgreSQL 10 or newer, to ensure compatibility with PostgreSQL 18 and future releases.

- PostgreSQL 18 Beta 1

```
$ psql -d postgres
psql (18beta1)
Type "help" for help.

postgres=# select version();
                              version
--------------------------------------------------------------------
 PostgreSQL 18beta1 on x86_64-linux, compiled by gcc-15.1.1, 64-bit
(1 row)

postgres=#
```

- With pg 1.5.9 ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt fails
```
$ bundle info pg
  * pg (1.5.9)
    Summary: Pg is the Ruby interface to the PostgreSQL RDBMS
    Homepage: https://github.com/ged/ruby-pg
    Documentation: http://deveiate.org/code/pg
    Source Code: https://github.com/ged/ruby-pg
    Changelog: https://github.com/ged/ruby-pg/blob/master/History.md
    Path: /home/yahonda/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9
    Reverse Dependencies:
        queue_classic (4.0.0) depends on pg (>= 1.1, < 2.0)
$
$ ARCONN=postgresql bin/test test/cases/adapters/postgresql/transaction_test.rb -n test_raises_Interrupt_when_canceling_statement_via_interrupt
Using postgresql
Run options: -n test_raises_Interrupt_when_canceling_statement_via_interrupt --seed 17678

F

Failure:
ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt [test/cases/adapters/postgresql/transaction_test.rb:199]:
Expected 10.014372003 to be < 5.

bin/test test/cases/adapters/postgresql/transaction_test.rb:183

Finished in 10.067954s, 0.0993 runs/s, 0.1987 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
```

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Jul 6, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
the format of the cancel request key, which causes the following test to fail on Rails main.

This change was introduced in PostgreSQL core via
postgres/postgres@a460251

The issue is already addressed in ged/ruby-pg#614
and the fix is included in the upcoming pg gem version v1.6.0 (currently released as v1.6.0.rc1).

The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via
ged/ruby-pg#606

Rails main currently claims support for PostgreSQL 9.3+, which is incompatible with PostgreSQL 18
unless we raise the minimum supported version to 10.

I propose updating Rails main to require PostgreSQL 10 or newer, to ensure compatibility with PostgreSQL 18 and future releases.

- PostgreSQL 18 Beta 1

```
$ psql -d postgres
psql (18beta1)
Type "help" for help.

postgres=# select version();
                              version
--------------------------------------------------------------------
 PostgreSQL 18beta1 on x86_64-linux, compiled by gcc-15.1.1, 64-bit
(1 row)

postgres=#
```

- With pg 1.5.9 ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt fails
```
$ bundle info pg
  * pg (1.5.9)
    Summary: Pg is the Ruby interface to the PostgreSQL RDBMS
    Homepage: https://github.com/ged/ruby-pg
    Documentation: http://deveiate.org/code/pg
    Source Code: https://github.com/ged/ruby-pg
    Changelog: https://github.com/ged/ruby-pg/blob/master/History.md
    Path: /home/yahonda/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9
    Reverse Dependencies:
        queue_classic (4.0.0) depends on pg (>= 1.1, < 2.0)
$
$ ARCONN=postgresql bin/test test/cases/adapters/postgresql/transaction_test.rb -n test_raises_Interrupt_when_canceling_statement_via_interrupt
Using postgresql
Run options: -n test_raises_Interrupt_when_canceling_statement_via_interrupt --seed 17678

F

Failure:
ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt [test/cases/adapters/postgresql/transaction_test.rb:199]:
Expected 10.014372003 to be < 5.

bin/test test/cases/adapters/postgresql/transaction_test.rb:183

Finished in 10.067954s, 0.0993 runs/s, 0.1987 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
```

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Jul 19, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
 the format of the cancel request key, which causes compatibility issues with older versions of the pg gem.

This change was introduced in PostgreSQL core via postgres/postgres@a460251,
and the issue is addressed in ged/ruby-pg#614 with a fix included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Rails main currently claims support for PostgreSQL 9.3+.
However, to ensure forward compatibility with PostgreSQL 18 and future releases, we need to establish a more sustainable baseline.

* Changes in this commit:
- Bump minimum required PostgreSQL version from 9.3 to 10.0
- Deprecate `supports_pgcrypto_uuid?` (no longer needed since PostgreSQL 10+ includes pgcrypto by default)

* Reasons for choosing PostgreSQL 10.0 baseline:
- The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via ged/ruby-pg#606
- PostgreSQL 9.3 reached end-of-life in November 2018, and PostgreSQL 9.6 reached end-of-life in November 2021
- While Ruby on Rails has not historically dropped database support solely based on EOL status,
PostgreSQL 9.3 (released in 2013) is now over a decade old and maintaining compatibility becomes increasingly challenging

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Jul 19, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
 the format of the cancel request key, which causes compatibility issues with older versions of the pg gem.

This change was introduced in PostgreSQL core via postgres/postgres@a460251,
and the issue is addressed in ged/ruby-pg#614 with a fix included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Rails main currently claims support for PostgreSQL 9.3+.
However, to ensure forward compatibility with PostgreSQL 18 and future releases, we need to establish a more sustainable baseline.

* Changes in this commit:
- Bump minimum required PostgreSQL version from 9.3 to 10.0
- Deprecate `supports_pgcrypto_uuid?` (no longer needed since PostgreSQL 10+ includes pgcrypto by default)

* Reasons for choosing PostgreSQL 10.0 baseline:
- The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via ged/ruby-pg#606
- PostgreSQL 9.3 reached end-of-life in November 2018, and PostgreSQL 9.6 reached end-of-life in November 2021
- While Ruby on Rails has not historically dropped database support solely based on EOL status,
PostgreSQL 9.3 (released in 2013) is now over a decade old and maintaining compatibility becomes increasingly challenging

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Jul 19, 2025
Split from rails#55282

This commit emits a warning when `pg` gem < 1.6.0 is used with PostgreSQL 18+
to prevent compatibility issues of PG::Connection#cancel.

PostgreSQL 18 (scheduled for release around September/October 2025) changes the format of the cancel request key
, which causes PG::Connection#cancel to fail with pg gem 1.5.9 and below.
This issue is already addressed in ged/ruby-pg#614 and the fix is included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Instead of requiring pg gem 1.6+ for all users when raising minimum supported PostgreSQL version to 10 discussed at rails#55282 ,
warnings are only shown to PostgreSQL 18+ + pg gem ≤ 1.5.9 users actually affected by the PG::Connection#cancel behavior.

Also skip the failing test if pg gem version < 1.6.0 and PostgreSQL version is 18+.

```
$ bundle info pg
  * pg (1.5.9)
    Summary: Pg is the Ruby interface to the PostgreSQL RDBMS
    Homepage: https://github.com/ged/ruby-pg
    Documentation: http://deveiate.org/code/pg
    Source Code: https://github.com/ged/ruby-pg
    Changelog: https://github.com/ged/ruby-pg/blob/master/History.md
    Path: /home/yahonda/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9
    Reverse Dependencies:
        queue_classic (4.0.0) depends on pg (>= 1.1, < 2.0)
$
$ ARCONN=postgresql bin/test test/cases/adapters/postgresql/transaction_test.rb -n test_raises_Interrupt_when_canceling_statement_via_interrupt
Using postgresql
Run options: -n test_raises_Interrupt_when_canceling_statement_via_interrupt --seed 17678

F

Failure:
ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt [test/cases/adapters/postgresql/transaction_test.rb:199]:
Expected 10.014372003 to be < 5.

bin/test test/cases/adapters/postgresql/transaction_test.rb:183

Finished in 10.067954s, 0.0993 runs/s, 0.1987 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
```
yahonda added a commit to yahonda/rails that referenced this pull request Jul 19, 2025
Split from rails#55282

This commit emits a warning when `pg` gem < 1.6.0 is used with PostgreSQL 18+
to prevent compatibility issues of PG::Connection#cancel.

PostgreSQL 18 (scheduled for release around September/October 2025) changes the format of the cancel request key
, which causes PG::Connection#cancel to fail with pg gem 1.5.9 and below.
This issue is already addressed in ged/ruby-pg#614 and the fix is included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Instead of requiring pg gem 1.6+ for all users when raising minimum supported PostgreSQL version to 10 discussed at rails#55282 ,
warnings are only shown to PostgreSQL 18+ + pg gem ≤ 1.5.9 users actually affected by the PG::Connection#cancel behavior.

Also skip the failing test if pg gem version < 1.6.0 and PostgreSQL version is 18+.

```
$ bundle info pg
  * pg (1.5.9)
    Summary: Pg is the Ruby interface to the PostgreSQL RDBMS
    Homepage: https://github.com/ged/ruby-pg
    Documentation: http://deveiate.org/code/pg
    Source Code: https://github.com/ged/ruby-pg
    Changelog: https://github.com/ged/ruby-pg/blob/master/History.md
    Path: /home/yahonda/.local/share/mise/installs/ruby/3.4.4/lib/ruby/gems/3.4.0/gems/pg-1.5.9
    Reverse Dependencies:
        queue_classic (4.0.0) depends on pg (>= 1.1, < 2.0)
$
$ ARCONN=postgresql bin/test test/cases/adapters/postgresql/transaction_test.rb -n test_raises_Interrupt_when_canceling_statement_via_interrupt
Using postgresql
Run options: -n test_raises_Interrupt_when_canceling_statement_via_interrupt --seed 17678

F

Failure:
ActiveRecord::PostgresqlTransactionTest#test_raises_Interrupt_when_canceling_statement_via_interrupt [test/cases/adapters/postgresql/transaction_test.rb:199]:
Expected 10.014372003 to be < 5.

bin/test test/cases/adapters/postgresql/transaction_test.rb:183

Finished in 10.067954s, 0.0993 runs/s, 0.1987 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
```
yahonda added a commit to yahonda/rails that referenced this pull request Jul 22, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
 the format of the cancel request key, which causes compatibility issues with older versions of the pg gem.

This change was introduced in PostgreSQL core via postgres/postgres@a460251,
and the issue is addressed in ged/ruby-pg#614 with a fix included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Rails main currently claims support for PostgreSQL 9.3+.
However, to ensure forward compatibility with PostgreSQL 18 and future releases, we need to establish a more sustainable baseline.

* Changes in this commit:
- Bump minimum required PostgreSQL version from 9.3 to 10.0
- Deprecate `supports_pgcrypto_uuid?` (no longer needed since PostgreSQL 10+ includes pgcrypto by default)

* Reasons for choosing PostgreSQL 10.0 baseline:
- The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via ged/ruby-pg#606
- PostgreSQL 9.3 reached end-of-life in November 2018, and PostgreSQL 9.6 reached end-of-life in November 2021
- While Ruby on Rails has not historically dropped database support solely based on EOL status,
PostgreSQL 9.3 (released in 2013) is now over a decade old and maintaining compatibility becomes increasingly challenging

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Aug 24, 2025
…reSQL 18 client library (libpq)

PostgreSQL 18 changes the length of the cancel request key. With libpq 18
or newer the call to PG::Connection#cancel fails when the pg gem is older
than 1.6.0. Rails calls PG::Connection#cancel from cancel_any_running_query,
so this mismatch leads to runtime errors.

Before this change pull request rails#55368 checked the PostgreSQL server version
inside check_version. That was not correct. The incompatibility is between
the pg gem version and the client library version (libpq),
as discussed in rails#55368.

Refer to
ged/ruby-pg#614
rails#55368
rails#55413

Co-authored-by: Lars Kanis <lars@greiz-reinsdorf.de>
yahonda added a commit to yahonda/rails that referenced this pull request Aug 29, 2025
…reSQL 18 client library (libpq)

PostgreSQL 18 changes the length of the cancel request key. With libpq 18
or newer the call to PG::Connection#cancel fails when the pg gem is older
than 1.6.0. Rails calls PG::Connection#cancel from cancel_any_running_query,
so this mismatch leads to runtime errors.

Before this change pull request rails#55368 checked the PostgreSQL server version
inside check_version. That was not correct. The incompatibility is between
the pg gem version and the client library version (libpq),
as discussed in rails#55368.

Refer to
ged/ruby-pg#614
rails#55368
rails#55413

Co-authored-by: Lars Kanis <lars@greiz-reinsdorf.de>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 2, 2025
…reSQL 18 client library (libpq)

PostgreSQL 18 changes the length of the cancel request key. With libpq 18
or newer the call to PG::Connection#cancel fails when the pg gem is older
than 1.6.0. Rails calls PG::Connection#cancel from cancel_any_running_query,
so this mismatch leads to runtime errors.

Before this change pull request rails#55368 checked the PostgreSQL server version
inside check_version. That was not correct. The incompatibility is between
the pg gem version and the client library version (libpq),
as discussed in rails#55368.

Refer to
ged/ruby-pg#614
rails#55368
rails#55413

Co-authored-by: Lars Kanis <lars@greiz-reinsdorf.de>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 2, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
 the format of the cancel request key, which causes compatibility issues with older versions of the pg gem.

This change was introduced in PostgreSQL core via postgres/postgres@a460251,
and the issue is addressed in ged/ruby-pg#614 with a fix included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Rails main currently claims support for PostgreSQL 9.3+.
However, to ensure forward compatibility with PostgreSQL 18 and future releases, we need to establish a more sustainable baseline.

* Changes in this commit:
- Bump minimum required PostgreSQL version from 9.3 to 10.0
- Deprecate `supports_pgcrypto_uuid?` (no longer needed since PostgreSQL 10+ includes pgcrypto by default)

* Reasons for choosing PostgreSQL 10.0 baseline:
- The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via ged/ruby-pg#606
- PostgreSQL 9.3 reached end-of-life in November 2018, and PostgreSQL 9.6 reached end-of-life in November 2021
- While Ruby on Rails has not historically dropped database support solely based on EOL status,
PostgreSQL 9.3 (released in 2013) is now over a decade old and maintaining compatibility becomes increasingly challenging

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Sep 3, 2025
….6.0

PostgreSQL 18 introduces protocol version 3.2, which changes the length of
the cancel request key. This makes PG::Connection#cancel fail if the pg gem
is older than 1.6.0.

PG::Connection#cancel is invoked from cancel_any_running_query, which is
only called from exec_rollback_db_transaction and exec_restart_db_transaction.
Skipping the cancel call may slow down rollback, but rollback still completes.

Before this change, pull request rails#55368 checked the PostgreSQL server version
inside check_version. That was incorrect—the incompatibility depends on the
pg gem version and the client library version (libpq), as discussed in rails#55368.

References:
- ged/ruby-pg#614
- rails#55368
- rails#55413

Co-authored-by: Lars Kanis <lars@greiz-reinsdorf.de>
yahonda added a commit to yahonda/rails that referenced this pull request Sep 4, 2025
….6.0

PostgreSQL 18 introduces protocol version 3.2, which changes the length of
the cancel request key. This makes PG::Connection#cancel fail if the pg gem
is older than 1.6.0.

PG::Connection#cancel is invoked from cancel_any_running_query, which is
only called from exec_rollback_db_transaction and exec_restart_db_transaction.
Skipping the cancel call may slow down rollback, but rollback still completes.

Before this change, pull request rails#55368 checked the PostgreSQL server version
inside check_version. That was incorrect—the incompatibility depends on the
pg gem version and the client library version (libpq), as discussed in rails#55368.

References:
- ged/ruby-pg#614
- rails#55368
- rails#55413

Co-authored-by: Lars Kanis <lars@greiz-reinsdorf.de>
yahonda added a commit to yahonda/rails that referenced this pull request Oct 17, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
 the format of the cancel request key, which causes compatibility issues with older versions of the pg gem.

This change was introduced in PostgreSQL core via postgres/postgres@a460251,
and the issue is addressed in ged/ruby-pg#614 with a fix included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Rails main currently claims support for PostgreSQL 9.3+.
However, to ensure forward compatibility with PostgreSQL 18 and future releases, we need to establish a more sustainable baseline.

* Changes in this commit:
- Bump minimum required PostgreSQL version from 9.3 to 10.0
- Deprecate `supports_pgcrypto_uuid?` (no longer needed since PostgreSQL 10+ includes pgcrypto by default)

* Reasons for choosing PostgreSQL 10.0 baseline:
- The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via ged/ruby-pg#606
- PostgreSQL 9.3 reached end-of-life in November 2018, and PostgreSQL 9.6 reached end-of-life in November 2021
- While Ruby on Rails has not historically dropped database support solely based on EOL status,
PostgreSQL 9.3 (released in 2013) is now over a decade old and maintaining compatibility becomes increasingly challenging

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Nov 6, 2025
PostgreSQL 18 (scheduled for release around September/October 2025) changes
 the format of the cancel request key, which causes compatibility issues with older versions of the pg gem.

This change was introduced in PostgreSQL core via postgres/postgres@a460251,
and the issue is addressed in ged/ruby-pg#614 with a fix included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Rails main currently claims support for PostgreSQL 9.3+.
However, to ensure forward compatibility with PostgreSQL 18 and future releases, we need to establish a more sustainable baseline.

* Changes in this commit:
- Bump minimum required PostgreSQL version from 9.3 to 10.0
- Deprecate `supports_pgcrypto_uuid?` (no longer needed since PostgreSQL 10+ includes pgcrypto by default)

* Reasons for choosing PostgreSQL 10.0 baseline:
- The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via ged/ruby-pg#606
- PostgreSQL 9.3 reached end-of-life in November 2018, and PostgreSQL 9.6 reached end-of-life in November 2021
- While Ruby on Rails has not historically dropped database support solely based on EOL status,
PostgreSQL 9.3 (released in 2013) is now over a decade old and maintaining compatibility becomes increasingly challenging

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
yahonda added a commit to yahonda/rails that referenced this pull request Jan 7, 2026
PostgreSQL 18 (scheduled for release around September/October 2025) changes
 the format of the cancel request key, which causes compatibility issues with older versions of the pg gem.

This change was introduced in PostgreSQL core via postgres/postgres@a460251,
and the issue is addressed in ged/ruby-pg#614 with a fix included in pg gem v1.6.0 (currently released as v1.6.0.rc2).

Rails main currently claims support for PostgreSQL 9.3+.
However, to ensure forward compatibility with PostgreSQL 18 and future releases, we need to establish a more sustainable baseline.

* Changes in this commit:
- Bump minimum required PostgreSQL version from 9.3 to 10.0
- Deprecate `supports_pgcrypto_uuid?` (no longer needed since PostgreSQL 10+ includes pgcrypto by default)

* Reasons for choosing PostgreSQL 10.0 baseline:
- The pg gem v1.6 raises its minimum required PostgreSQL version to 10 via ged/ruby-pg#606
- PostgreSQL 9.3 reached end-of-life in November 2018, and PostgreSQL 9.6 reached end-of-life in November 2021
- While Ruby on Rails has not historically dropped database support solely based on EOL status,
PostgreSQL 9.3 (released in 2013) is now over a decade old and maintaining compatibility becomes increasingly challenging

Discussed at https://discuss.rubyonrails.org/t/proposal-bump-the-minimum-supported-postgresql-version-from-9-3-to-10/89422
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant