]> git.ipfire.org Git - thirdparty/psycopg.git/log
thirdparty/psycopg.git
13 months agodocs: add documentation about none-returning dumpers 642/head
Daniele Varrazzo [Sat, 1 Jun 2024 11:06:38 +0000 (13:06 +0200)] 
docs: add documentation about none-returning dumpers

13 months agodocs: add news entry about none support in dumpers
Daniele Varrazzo [Wed, 4 Jan 2023 16:06:35 +0000 (16:06 +0000)] 
docs: add news entry about none support in dumpers

13 months agofix(c): allow dumpers to return none in copy
Daniele Varrazzo [Wed, 29 May 2024 19:43:09 +0000 (21:43 +0200)] 
fix(c): allow dumpers to return none in copy

13 months agotest: verify that dumpers returning None are used correctly in copy
Daniele Varrazzo [Mon, 19 Sep 2022 10:47:23 +0000 (11:47 +0100)] 
test: verify that dumpers returning None are used correctly in copy

13 months agofix: manage dumpers returning None in nested dumpers
Daniele Varrazzo [Mon, 19 Sep 2022 01:20:38 +0000 (02:20 +0100)] 
fix: manage dumpers returning None in nested dumpers

13 months agotest: verify that dumpers returning None are used correctly in queries
Daniele Varrazzo [Mon, 19 Sep 2022 00:54:44 +0000 (01:54 +0100)] 
test: verify that dumpers returning None are used correctly in queries

13 months agofix: annotate every dumper to return Optional[Buffer]
Daniele Varrazzo [Mon, 19 Sep 2022 00:42:34 +0000 (01:42 +0100)] 
fix: annotate every dumper to return Optional[Buffer]

Even if these classes never return None, this allows to create
subclasses returning None without making Mypy unhappy.

Similarly, annotate quote() methods as returning Buffer to allow
subclasses to return other types.

13 months agofix: manage None as return value of Dumper.dump()
Daniele Varrazzo [Mon, 19 Sep 2022 00:08:19 +0000 (01:08 +0100)] 
fix: manage None as return value of Dumper.dump()

These are only the changes suggested by Mypy; no test added to verify
that the code paths actually work.

Only Python test fixed, no C yet.

13 months agofeat: extend signature of Dumper.dump() to allow returning None
Daniele Varrazzo [Sun, 18 Sep 2022 23:36:35 +0000 (00:36 +0100)] 
feat: extend signature of Dumper.dump() to allow returning None

13 months agodocs: extend on the type info note
Daniele Varrazzo [Sat, 1 Jun 2024 11:05:54 +0000 (13:05 +0200)] 
docs: extend on the type info note

13 months agofeat: add libpq interface to change a password
Denis Laxalde [Wed, 17 Apr 2024 08:35:45 +0000 (10:35 +0200)] 
feat: add libpq interface to change a password

See https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=a7be2a6c262d5352756d909b29c419ea5e5fa1d9:
> drivers built on top of libpq should expose this function and its
> use should be generally encouraged over doing ALTER USER directly for
> password changes.

The test case assumes that the role connected to postgres has CREATEROLE
rights. If this is not true, the test is skipped.

13 months agofix(copy): fix count of chars to escape
Daniele Varrazzo [Wed, 29 May 2024 19:45:57 +0000 (21:45 +0200)] 
fix(copy): fix count of chars to escape

We missed to reset the number of chars to escape at every field. As a
consequence, we end up resizing and scanning all the fields after the
first one requiring an escape and allocating a bit more memory than
needed.

13 months agochore(deps): bump pypa/cibuildwheel in the actions group
dependabot[bot] [Thu, 30 May 2024 20:33:57 +0000 (20:33 +0000)] 
chore(deps): bump pypa/cibuildwheel in the actions group

Bumps the actions group with 1 update: [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel).

Updates `pypa/cibuildwheel` from 2.17.0 to 2.18.1
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v2.17.0...v2.18.1)

---
updated-dependencies:
- dependency-name: pypa/cibuildwheel
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
13 months agoMerge pull request #824
Daniele Varrazzo [Thu, 30 May 2024 20:33:15 +0000 (22:33 +0200)] 
Merge pull request #824

Updates action versions and add dependabot to check monthly for updates

13 months agoci: merge all produced artifacts into a single artifact for ease of downloading 824/head
Trenton Holmes [Sat, 18 May 2024 20:21:04 +0000 (13:21 -0700)] 
ci: merge all produced artifacts into a single artifact for ease of downloading

13 months agoci: updates action versions and add dependabot to check monthly for updates
Trenton Holmes [Sat, 18 May 2024 01:41:51 +0000 (18:41 -0700)] 
ci: updates action versions and add dependabot to check monthly for updates

13 months agochore: fix typo in comment
Daniele Varrazzo [Mon, 27 May 2024 14:20:38 +0000 (16:20 +0200)] 
chore: fix typo in comment

13 months agodocs: improve docs about query protocols and PgBouncer
Daniele Varrazzo [Fri, 17 May 2024 00:42:32 +0000 (02:42 +0200)] 
docs: improve docs about query protocols and PgBouncer

13 months agofix: use the simple query protocol to execute BEGIN/COMMIT out of pipeline
Daniele Varrazzo [Tue, 14 May 2024 11:18:40 +0000 (13:18 +0200)] 
fix: use the simple query protocol to execute BEGIN/COMMIT out of pipeline

We started using the extended protocol in e5079184 to fix #350, but,
probably to keep symmetry, we also changed the behaviour out of the
pipeline.

This turns out to be a problem for people connecting to the PgBouncer
admin console. They can use the `ClientCursor`, which tries to use the
simple protocol as much as it can, but they currently have to use
autocommit. With this changeset autocommit shouldn't be needed anymore.
See #808.

13 months agoMerge pull request #811 from psycopg/refactor-typeinfo
Daniele Varrazzo [Wed, 15 May 2024 16:29:30 +0000 (18:29 +0200)] 
Merge pull request #811 from psycopg/refactor-typeinfo

Remove type modifier decoding from Column object

13 months agotest: adapt type representation tests to crdb and postgres < 15 811/head
Daniele Varrazzo [Thu, 9 May 2024 01:49:24 +0000 (03:49 +0200)] 
test: adapt type representation tests to crdb and postgres < 15

13 months agofeat: add Column.type_display
Daniele Varrazzo [Thu, 9 May 2024 01:27:29 +0000 (03:27 +0200)] 
feat: add Column.type_display

13 months agofix: fix representation of bit/varbit columns
Daniele Varrazzo [Thu, 9 May 2024 00:02:08 +0000 (02:02 +0200)] 
fix: fix representation of bit/varbit columns

13 months agofix: improve column type display
Daniele Varrazzo [Wed, 8 May 2024 23:39:30 +0000 (01:39 +0200)] 
fix: improve column type display

Make sure that what displayed is the same displayed by postgres for all
supported types.

13 months agorefactor(column): remove ColumnData internal object
Daniele Varrazzo [Wed, 8 May 2024 21:57:11 +0000 (23:57 +0200)] 
refactor(column): remove ColumnData internal object

13 months agorefactor: dispatch type modifier parsing to type-specific objects
Daniele Varrazzo [Wed, 8 May 2024 21:49:19 +0000 (23:49 +0200)] 
refactor: dispatch type modifier parsing to type-specific objects

This changeset is enough to pass the current test suite, but probably it
might require some cleanup.

Close #450

13 months agostyle(typeinfo): more modern type annotations
Daniele Varrazzo [Fri, 3 May 2024 19:45:24 +0000 (21:45 +0200)] 
style(typeinfo): more modern type annotations

13 months agoAdd instructions for pgbouncer simple query protocol
Ruben Laguna [Tue, 14 May 2024 13:48:08 +0000 (15:48 +0200)] 
Add instructions for pgbouncer simple query protocol

13 months agodocs: add README to build the docs
Daniele Varrazzo [Tue, 14 May 2024 12:03:45 +0000 (14:03 +0200)] 
docs: add README to build the docs

Close #821.

14 months agochore: bump psycopg_pool package version to 3.2.2
Daniele Varrazzo [Fri, 10 May 2024 00:05:25 +0000 (02:05 +0200)] 
chore: bump psycopg_pool package version to 3.2.2

14 months agochore: bump psycopg package version to 3.1.19
Daniele Varrazzo [Fri, 10 May 2024 00:01:14 +0000 (02:01 +0200)] 
chore: bump psycopg package version to 3.1.19

14 months agoci(macos): test and build macOS packages on M1 runners
Daniele Varrazzo [Tue, 9 Apr 2024 23:57:50 +0000 (01:57 +0200)] 
ci(macos): test and build macOS packages on M1 runners

Separate macos runners because:

The macos-14 runner can build amd64 images, but doesn't have Python <
3.10.

The macos-12 runner can only build x86_64 images.

Run Postgres from CI rather than from cibuildwheel, as cibw won't use a
docker image on macOS anyway. It makes it more uniform w.r.t. other
runners and doesn't require a "before" script.

14 months agoMerge pull request #791
Daniele Varrazzo [Wed, 8 May 2024 20:12:01 +0000 (22:12 +0200)] 
Merge pull request #791

Replace SELECT 1 with an empty query

14 months agodocs(pool): mention running an empty query on check in news file 791/head
Daniele Varrazzo [Wed, 8 May 2024 16:49:41 +0000 (18:49 +0200)] 
docs(pool): mention running an empty query on check in news file

14 months agorefactor(pool): replace --ping with empty string
Eyal Halpern Shalev [Sat, 4 May 2024 12:57:56 +0000 (15:57 +0300)] 
refactor(pool): replace --ping with empty string

14 months agoperf(pool): replace SELECT 1 with an empty query
Eyal Halpern Shalev [Mon, 15 Apr 2024 23:09:45 +0000 (02:09 +0300)] 
perf(pool): replace SELECT 1 with an empty query

14 months agoMerge pull request #746 from ankane/copy-performance
Daniele Varrazzo [Wed, 8 May 2024 16:35:58 +0000 (18:35 +0200)] 
Merge pull request #746 from ankane/copy-performance

Improve performance of copy

14 months agoperf(copy): only flush at every row on copy on macOS 746/head
Daniele Varrazzo [Mon, 6 May 2024 16:43:10 +0000 (18:43 +0200)] 
perf(copy): only flush at every row on copy on macOS

With some benchmark, it seems that on Linux and Windows performances are worse.
See #746 for details.

14 months agotest(copy): add minimal copy benchmark framework
Daniele Varrazzo [Fri, 3 May 2024 11:08:11 +0000 (13:08 +0200)] 
test(copy): add minimal copy benchmark framework

14 months agoImprove performance of copy
Andrew Kane [Mon, 4 Mar 2024 22:34:56 +0000 (14:34 -0800)] 
Improve performance of copy

14 months agofix(pool): avoid possible deadlock (until timeout) on pool closing
Daniele Varrazzo [Mon, 6 May 2024 09:21:33 +0000 (11:21 +0200)] 
fix(pool): avoid possible deadlock (until timeout) on pool closing

With the previous change to avoid finding open connections in the pool
(#784), stopping the worker was moved into the critical section. This
can create a deadlock in case a worker is in the process of obtaining a
new connection, because putting it to the pool requires the lock. The
deadlock only last for the default 5s timeout passed to _stop_workers().

Solve the problem by guarding _add_to_pool() to avoid it to try to add
the connection if the pool is closed.

However, refactor the pool closing sequence too and close the workers
and other resources that now out of the state outside the critical
section to keep the operation running under lock to a minimum.

14 months agotest: fix running pool tests using Psycopg 3.1
Daniele Varrazzo [Sat, 20 Apr 2024 22:03:56 +0000 (00:03 +0200)] 
test: fix running pool tests using Psycopg 3.1

Avoid using Capabilities at import time in the test suite.

14 months agoMerge branch 'fix-734'
Daniele Varrazzo [Sat, 20 Apr 2024 21:46:46 +0000 (23:46 +0200)] 
Merge branch 'fix-734'

14 months agofix(c): solve undefined behaviour caused by unaligned access 735/head
Daniele Varrazzo [Sun, 11 Feb 2024 01:34:20 +0000 (02:34 +0100)] 
fix(c): solve undefined behaviour caused by unaligned access

Close #734

14 months agoci: add test to check for misaligned memory access
Daniele Varrazzo [Wed, 10 Apr 2024 23:24:02 +0000 (01:24 +0200)] 
ci: add test to check for misaligned memory access

14 months agofix: fix handling of floating point values for connect_timeout 796/head
Daniele Varrazzo [Thu, 18 Apr 2024 01:38:17 +0000 (03:38 +0200)] 
fix: fix handling of floating point values for connect_timeout

14 months agoMerge pull request #780 from dlax/cancel-safe-timeout
Daniele Varrazzo [Wed, 17 Apr 2024 21:52:02 +0000 (23:52 +0200)] 
Merge pull request #780 from dlax/cancel-safe-timeout

feat: add a timeout parameter to Connection.cancel_safe()

14 months agorefactor: set the meaningful timeout for _try_cancel() as a default 780/head
Denis Laxalde [Tue, 16 Apr 2024 07:11:30 +0000 (09:11 +0200)] 
refactor: set the meaningful timeout for _try_cancel() as a default

14 months agofix: avoid to swallow exceptions in public cancel methods
Daniele Varrazzo [Sat, 13 Apr 2024 10:23:38 +0000 (12:23 +0200)] 
fix: avoid to swallow exceptions in public cancel methods

Only ignore errors in every internal usage, in order to cancel as a best
effort and don't clobber a likely more meaningful exception.

14 months agodocs: adjust cancel_safe() docstring
Daniele Varrazzo [Sat, 13 Apr 2024 10:23:38 +0000 (12:23 +0200)] 
docs: adjust cancel_safe() docstring

14 months agodocs: reword notes on cancellation
Daniele Varrazzo [Sat, 13 Apr 2024 10:23:38 +0000 (12:23 +0200)] 
docs: reword notes on cancellation

14 months agotest: more uniform treatment of timeout approx check
Daniele Varrazzo [Fri, 12 Apr 2024 22:51:22 +0000 (00:51 +0200)] 
test: more uniform treatment of timeout approx check

14 months agorefactor: check if cancel safe is implemented via capabilities
Daniele Varrazzo [Fri, 12 Apr 2024 22:36:36 +0000 (00:36 +0200)] 
refactor: check if cancel safe is implemented via capabilities

14 months agotest(proxy): use 127.0.0.1 rather than localhost
Daniele Varrazzo [Fri, 12 Apr 2024 12:46:49 +0000 (14:46 +0200)] 
test(proxy): use 127.0.0.1 rather than localhost

Try to fix the flakiness shown by deaf_listen() in CI. Maybe there is a
race condition in listen()/connect() but I have also seen problems
related with localhost in the /etc/hosts file and ipv6, so let's first
try this.

14 months agofeat: add a timeout parameter to Connection.cancel_safe()
Denis Laxalde [Mon, 8 Apr 2024 13:00:17 +0000 (15:00 +0200)] 
feat: add a timeout parameter to Connection.cancel_safe()

This will only work for PGcancelConn, i.e. libpq >= 17, or thanks to
added waiting logic in AsyncConnection's implementation; so we add a
note about the limitation in Connection's documentation.

14 months agofeat: add libpq interface for retrieving results in chunks 793/head
Denis Laxalde [Wed, 17 Apr 2024 08:35:45 +0000 (10:35 +0200)] 
feat: add libpq interface for retrieving results in chunks

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=4643a2b265e967cc5f13ffa0c7c6912dbb3466d0

14 months agofix(c): fix the goto label in the HAVE_POLL branch of wait_c_impl()
Denis Laxalde [Tue, 16 Apr 2024 14:21:16 +0000 (16:21 +0200)] 
fix(c): fix the goto label in the HAVE_POLL branch of wait_c_impl()

This resolves the following warning when building the extension module:

    $ python psycopg_c/setup.py build_ext -i
    [...]
    building 'psycopg_c._psycopg' extension
    x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/denis/.local/pgsql/include -I/home/denis/src/psycopg3/.venv/include -I/usr/include/python3.11 -c psycopg_c/_psycopg.c -o build/temp.linux-x86_64-cpython-311/psycopg_c/_psycopg.o
    psycopg_c/_psycopg.c: In function ‘wait_c_impl’:
    psycopg_c/_psycopg.c:1649:1: warning: label ‘error’ defined but not used [-Wunused-label]
     1649 |
          | ^

14 months agoMerge branch 'cancel-exceptions-swallow'
Daniele Varrazzo [Fri, 12 Apr 2024 22:11:15 +0000 (00:11 +0200)] 
Merge branch 'cancel-exceptions-swallow'

14 months agofix: avoid explicit str() call when logging exception 785/head
Daniele Varrazzo [Fri, 12 Apr 2024 12:11:22 +0000 (14:11 +0200)] 
fix: avoid explicit str() call when logging exception

This was done as paranoia check for Sentry which might uses the repr of
the exception even if we asked for `%s` and therefore might leak
secrets, but frankly it's not our responsibility.

https://github.com/getsentry/sentry-python/issues/2417

14 months agorefactor: clearer cancel_safe implementation
Daniele Varrazzo [Wed, 10 Apr 2024 20:37:24 +0000 (22:37 +0200)] 
refactor: clearer cancel_safe implementation

Avoid catching NotSupported, just check for the libpq version.

Also avoid the half exception handler in `_cancel_gen()`: as in the
legacy branch, warn and ignore any error happening in the outermost
method, without adding an ignore exception policy in an implementation
method.

Close #778.

14 months agorefactor: drop _try_cancel internal method.
Daniele Varrazzo [Wed, 10 Apr 2024 20:16:47 +0000 (22:16 +0200)] 
refactor: drop _try_cancel internal method.

This method was useful before introducing cancel_safe, which is now the
function of choice for internal cancelling.

Also refactor the exception handling to account for possible errors in
`PGcancel.cancel()`, not only in `PGconn.get_cancel()`, to make sure to
not clobber an exception bubbling up with ours, whatever happens to the
underlying connection.

14 months agoMerge branch 'capabilities'
Daniele Varrazzo [Fri, 12 Apr 2024 22:09:23 +0000 (00:09 +0200)] 
Merge branch 'capabilities'

14 months agorefactor(capabilities): add caching to capabilities check 782/head
Daniele Varrazzo [Fri, 12 Apr 2024 12:04:57 +0000 (14:04 +0200)] 
refactor(capabilities): add caching to capabilities check

14 months agorefactor(pipeline): use Capabilities to implement is_supported
Daniele Varrazzo [Tue, 9 Apr 2024 22:13:18 +0000 (00:13 +0200)] 
refactor(pipeline): use Capabilities to implement is_supported

14 months agodocs: add capabilities documentation
Daniele Varrazzo [Tue, 9 Apr 2024 21:41:28 +0000 (23:41 +0200)] 
docs: add capabilities documentation

14 months agofeat: add psycopg.capability
Daniele Varrazzo [Tue, 9 Apr 2024 20:30:43 +0000 (22:30 +0200)] 
feat: add psycopg.capability

Close #772

14 months agorefactor: use consistently the version_pretty() function
Daniele Varrazzo [Tue, 9 Apr 2024 20:15:39 +0000 (22:15 +0200)] 
refactor: use consistently the version_pretty() function

14 months agofeat: add pq.version_pretty() function
Daniele Varrazzo [Tue, 9 Apr 2024 13:54:55 +0000 (15:54 +0200)] 
feat: add pq.version_pretty() function

14 months agoMerge branch 'async-to-sync-refactor'
Daniele Varrazzo [Fri, 12 Apr 2024 22:07:29 +0000 (00:07 +0200)] 
Merge branch 'async-to-sync-refactor'

14 months agorefactor(async-to-sync): rename --convert-all option to --all 787/head
Daniele Varrazzo [Fri, 12 Apr 2024 22:05:00 +0000 (00:05 +0200)] 
refactor(async-to-sync): rename --convert-all option to --all

14 months agochore(async-to-sync): drop --all argument
Daniele Varrazzo [Fri, 12 Apr 2024 17:37:25 +0000 (19:37 +0200)] 
chore(async-to-sync): drop --all argument

Working on all inputs is a meaningful default.

14 months agorefactor(async-to-sync): use pattern matching for more compact tests
Daniele Varrazzo [Fri, 12 Apr 2024 00:47:05 +0000 (02:47 +0200)] 
refactor(async-to-sync): use pattern matching for more compact tests

14 months agorefactor(async-to-sync): simpler pattern to convert string literals
Daniele Varrazzo [Thu, 11 Apr 2024 23:32:18 +0000 (01:32 +0200)] 
refactor(async-to-sync): simpler pattern to convert string literals

15 months agofix(pool): make sure there are no connection in the pool after close()
Daniele Varrazzo [Wed, 10 Apr 2024 21:58:24 +0000 (23:58 +0200)] 
fix(pool): make sure there are no connection in the pool after close()

The case has been reported in #784. While not easy to reproduce, it
seems that it might be caused by the pool being closed while a worker is
still trying to create a connection, which will be put in the _pool
state after supposedly no other operation should have been performed.

Stop the workers and then empty the pool only after they have stopped to
run.

Also refactor the cleanup of the pool and waiting queue, moving them
to close(). There is no reason why a method called "stop workers" should
empty them, and there is no other code path that use such feature.

Close #784.

15 months agotest: replace deaf_port fixture with deaf_listen method on proxy 783/head
Daniele Varrazzo [Wed, 10 Apr 2024 19:40:00 +0000 (21:40 +0200)] 
test: replace deaf_port fixture with deaf_listen method on proxy

This allows to replace the listening proxy port with a port that blocks
connection and to write more easily cancel timeout tests (as in #780).

15 months agotests: fix allow to skip running the pool tests again
Daniele Varrazzo [Thu, 11 Apr 2024 23:15:34 +0000 (01:15 +0200)] 
tests: fix allow to skip running the pool tests again

`pytest -m not pool` should allow to skip the pool test. However,
because of the attribute access at import time to define the test
marker, import failed as well.

Convert the marker to strings which will be used in a getattr by the
fixture. Extend async-to-sync to convert the pool classes names from the
string too.

15 months agotest: add missing prepared async tests
Daniele Varrazzo [Thu, 11 Apr 2024 22:44:42 +0000 (00:44 +0200)] 
test: add missing prepared async tests

Sync and async sides diverged because the async-to-sync check in CI was
pretty much disabled by the lack of the -B.

15 months agoci: restore async-to-sync check to check all the files
Daniele Varrazzo [Thu, 11 Apr 2024 22:34:21 +0000 (00:34 +0200)] 
ci: restore async-to-sync check to check all the files

15 months agotest(pool): more lenient timeout in reconnect test timings
Daniele Varrazzo [Wed, 10 Apr 2024 22:03:33 +0000 (00:03 +0200)] 
test(pool): more lenient timeout in reconnect test timings

15 months agochore: ignore spelling in html files
Daniele Varrazzo [Tue, 9 Apr 2024 22:33:27 +0000 (00:33 +0200)] 
chore: ignore spelling in html files

These files are generated by cython to display the C code generated...
and are a mess.

15 months agoMerge pull request #763 from dlax/pg17/non-blocking-pqcancel
Daniele Varrazzo [Tue, 9 Apr 2024 10:49:33 +0000 (11:49 +0100)] 
Merge pull request #763 from dlax/pg17/non-blocking-pqcancel

Add encrypted and non-blocking cancellation

15 months agofix: fix type signature of to_thread() compat 763/head
Denis Laxalde [Tue, 9 Apr 2024 07:19:27 +0000 (09:19 +0200)] 
fix: fix type signature of to_thread() compat

15 months agodocs: shorten news entry about Connection.cancel_safe()
Denis Laxalde [Tue, 9 Apr 2024 07:18:07 +0000 (09:18 +0200)] 
docs: shorten news entry about Connection.cancel_safe()

15 months agodocs: improve cancel_safe documentation
Daniele Varrazzo [Mon, 8 Apr 2024 22:57:53 +0000 (00:57 +0200)] 
docs: improve cancel_safe documentation

15 months agofeat: use non-blocking cancellation upon Copy termination
Denis Laxalde [Fri, 24 Mar 2023 13:55:18 +0000 (14:55 +0100)] 
feat: use non-blocking cancellation upon Copy termination

The logic of Copy termination, in finish(), is reworked so that
connection cancellation is invoked from there directly instead of from
_end_copy_out_gen() as we cannot call async code from the generator.

15 months agofeat: fall back to cancel() in cancel_safe() for libpq < 17
Denis Laxalde [Mon, 8 Apr 2024 08:00:04 +0000 (10:00 +0200)] 
feat: fall back to cancel() in cancel_safe() for libpq < 17

We run this in a thread executor in the AsyncConnection.
As asyncio's to_thread() is not available in Python 3.8, so we add a
compat layer.

15 months agofeat: add encrypted and non-blocking cancellation
Denis Laxalde [Fri, 24 Mar 2023 13:55:18 +0000 (14:55 +0100)] 
feat: add encrypted and non-blocking cancellation

We introduce Connection.cancel_safe() which uses the encrypted and
non-blocking libpq cancellation API available with PostgreSQL 17. As a
non-blocking entry point, cancel_safe() delegates to a generator function,
namely _cancel_gen(). If the libpq version is too old, the method raises
a NotSupportedError.

CTRL+C handling (in Connection.wait() or Cursor.stream()) also uses the
non-blocking cancellation but falls back to old method if the former is
not supported.

The behavior of cancel() method (either on Connection or
AsyncConnection) is kept unchanged to use the old cancellation API.

15 months agofeat: add generators.cancel()
Denis Laxalde [Fri, 24 Mar 2023 13:08:20 +0000 (14:08 +0100)] 
feat: add generators.cancel()

This is a PQGenConn generator as the socket for the PGcancelConn needs
to be retrieved after (at least) the first poll() call.

15 months agoMerge pull request #773 from psycopg/pgbouncer-prepare
Daniele Varrazzo [Tue, 9 Apr 2024 09:34:38 +0000 (10:34 +0100)] 
Merge pull request #773 from psycopg/pgbouncer-prepare

Make prepared statements compatible with PgBouncer

15 months agofeat(prepare): allow setting connection.prepare_max to None 773/head
Daniele Varrazzo [Mon, 8 Apr 2024 20:22:02 +0000 (20:22 +0000)] 
feat(prepare): allow setting connection.prepare_max to None

15 months agodocs(prepare): add note about PgBouncer max prepared statements setting
Daniele Varrazzo [Mon, 8 Apr 2024 20:13:37 +0000 (22:13 +0200)] 
docs(prepare): add note about PgBouncer max prepared statements setting

15 months agodocs(prepare): add notes about the PgBouncer and prepared statements
Daniele Varrazzo [Sat, 6 Apr 2024 20:54:21 +0000 (20:54 +0000)] 
docs(prepare): add notes about the PgBouncer and prepared statements

15 months agofeat(prepare): send Close messages to deallocate when possible
Daniele Varrazzo [Sat, 6 Apr 2024 19:26:18 +0000 (19:26 +0000)] 
feat(prepare): send Close messages to deallocate when possible

This allows for compatibility with PgBouncer, but requires libpq v17 at
least.

15 months agorefactor(prepare): queue statement names, not SQL commands
Daniele Varrazzo [Sat, 6 Apr 2024 17:36:54 +0000 (17:36 +0000)] 
refactor(prepare): queue statement names, not SQL commands

15 months agorefactor(prepare): make maintenance operation a PQGen generator
Daniele Varrazzo [Sat, 6 Apr 2024 16:36:16 +0000 (16:36 +0000)] 
refactor(prepare): make maintenance operation a PQGen generator

This will allow us to replace the SQL commands with protocol messages.

15 months agodocs(readme): fix hyperlink in bullet list
Daniele Varrazzo [Mon, 8 Apr 2024 19:21:42 +0000 (19:21 +0000)] 
docs(readme): fix hyperlink in bullet list

The problem was reported in #775, but the file is not wrong, and
rst2html renders correctly without warnings.

The problem is that the Github reST implementation doesn't get the
hyperlinks indented at bullet list level right.

My preference is to move the links out of the list rather than inserting
the URLs in the flow of the text and get awkward newlines or long lines.

15 months agodocs: drop spurious word in readme
Daniele Varrazzo [Mon, 8 Apr 2024 19:14:25 +0000 (19:14 +0000)] 
docs: drop spurious word in readme

Close #775

15 months agotest: fix test suite import on master with Python 3.1
Daniele Varrazzo [Sun, 7 Apr 2024 12:25:52 +0000 (12:25 +0000)] 
test: fix test suite import on master with Python 3.1

15 months agotest: fix cancel connection status test on Unix socket connection
Daniele Varrazzo [Sat, 6 Apr 2024 19:29:37 +0000 (19:29 +0000)] 
test: fix cancel connection status test on Unix socket connection

15 months agoMerge branch 'libpq-cancel-nonblocking'
Daniele Varrazzo [Fri, 5 Apr 2024 19:49:09 +0000 (19:49 +0000)] 
Merge branch 'libpq-cancel-nonblocking'