pgsql: Remove option to fall back from direct to postgres SSL negotiati

2024-05-16 Thread Heikki Linnakangas
Remove option to fall back from direct to postgres SSL negotiation There were three problems with the sslnegotiation options: 1. The sslmode=prefer and sslnegotiation=requiredirect combination was somewhat dangerous, as you might unintentionally fall back to plaintext authentication when

pgsql: Change ALPN protocol ID to IANA-approved "postgresql"

2024-05-11 Thread Heikki Linnakangas
Change ALPN protocol ID to IANA-approved "postgresql" "TBD-pgsql" was a placeholder until the IANA registration was approved. Discussion: https://www.postgresql.org/message-id/87jzk2hj2n.fsf%40wibble.ilmari.org Discussion:

Re: pgsql: Fix compilation on OpenSSL 1.0.2 and LibreSSL

2024-05-04 Thread Heikki Linnakangas
On 03/05/2024 11:44, Daniel Gustafsson wrote: On 2 May 2024, at 12:30, Heikki Linnakangas wrote: On 02/05/2024 13:24, Daniel Gustafsson wrote: This makes targeting 7.0 as the lowest LibreSSL version appealing in my patchset for removing support for old OpenSSL and LibreSSL versions. Works

Re: pgsql: Fix compilation on OpenSSL 1.0.2 and LibreSSL

2024-05-02 Thread Heikki Linnakangas
On 02/05/2024 13:24, Daniel Gustafsson wrote: On 2 May 2024, at 11:30, Heikki Linnakangas wrote: And I don't see the symbol in a fresh checkout of the portable libressl repository at https://github.com/libressl/portable. The portable repo only contains the portable parts, did you pull

Re: pgsql: Fix compilation on OpenSSL 1.0.2 and LibreSSL

2024-05-02 Thread Heikki Linnakangas
On 02/05/2024 12:09, Daniel Gustafsson wrote: On 30 Apr 2024, at 07:26, Heikki Linnakangas wrote: Fix compilation on OpenSSL 1.0.2 and LibreSSL SSL_AD_NO_APPLICATION_PROTOCOL was introduced in OpenSSL 1.1.0. +* https://github.com/openssl/openssl/issues/24300. This is available

pgsql: Fix compilation on OpenSSL 1.0.2 and LibreSSL

2024-04-29 Thread Heikki Linnakangas
Fix compilation on OpenSSL 1.0.2 and LibreSSL SSL_AD_NO_APPLICATION_PROTOCOL was introduced in OpenSSL 1.1.0. While we're at it, add a link to the related OpenSSL github issue to the comment. Per buildfarm and Tom Lane. Discussion:

Re: pgsql: Reject SSL connection if ALPN is used but there's no common prot

2024-04-29 Thread Heikki Linnakangas
On 30/04/2024 02:32, Tom Lane wrote: Heikki Linnakangas writes: Reject SSL connection if ALPN is used but there's no common protocol A moderately large fraction of the buildfarm doesn't seem to recognize SSL_AD_NO_APPLICATION_PROTOCOL. *sigh*. I checked that it exists on OpenSSL 1.1.1

pgsql: libpq: Fix error messages when server rejects SSL or GSS

2024-04-29 Thread Heikki Linnakangas
libpq: Fix error messages when server rejects SSL or GSS These messages were lost in commit 05fd30c0e7. Put them back. This makes one change in the error message behavior compared to v16, in the case that the server responds to GSSRequest with an error instead of rejecting it with 'N'.

pgsql: libpq: Enforce ALPN in direct SSL connections

2024-04-29 Thread Heikki Linnakangas
libpq: Enforce ALPN in direct SSL connections ALPN is mandatory with direct SSL connections. That is documented, and the server checks it, but libpq was missing the check. Reported-by: Jacob Champion Reviewed-by: Michael Paquier Discussion:

pgsql: Reject SSL connection if ALPN is used but there's no common prot

2024-04-29 Thread Heikki Linnakangas
Reject SSL connection if ALPN is used but there's no common protocol If the client supports ALPN but tries to use some other protocol, like HTTPS, reject the connection in the server. That is surely a confusion of some sort. Furthermore, the ALPN RFC 7301 says: > In the event that the server

pgsql: libpq: If ALPN is not used, make PQsslAttribute(conn, "alpn") ==

2024-04-29 Thread Heikki Linnakangas
libpq: If ALPN is not used, make PQsslAttribute(conn, "alpn") == "" The documentation says that PQsslAttribute(conn, "alpn") returns an empty string if ALPN is not used, but the code actually returned NULL. Fix the code to match the documentation. Reported-by: Michael Paquier Discussion:

pgsql: Fix documentation and comments on what happens after GSS rejecti

2024-04-28 Thread Heikki Linnakangas
Fix documentation and comments on what happens after GSS rejection The paragraph in the docs and the comment applied to sslnegotiaton=direct, but not sslnegotiation=requiredirect. In 'requiredirect' mode, negotiated SSL is never used. Move the paragraph in the docs under the description of

Re: pgsql: Refactor libpq state machine for negotiating encryption

2024-04-25 Thread Heikki Linnakangas
On 24/04/2024 15:57, Peter Eisentraut wrote: On 08.04.24 03:25, Heikki Linnakangas wrote: Refactor libpq state machine for negotiating encryption This fixes the few corner cases noted in commit 705843d294, as shown by the changes in the test. Either this or something nearby appears to have

pgsql: Put back initialization of 'sslmode', to silence Coverity

2024-04-14 Thread Heikki Linnakangas
Put back initialization of 'sslmode', to silence Coverity Coverity pointed out that the function checks for conn->sslmode != NULL, which implies that it might be NULL, but later we access it without a NULL-check anyway. It doesn't know that it is in fact always initialized earlier, in

Re: pgsql: Refactor libpq state machine for negotiating encryption

2024-04-12 Thread Heikki Linnakangas
On 11/04/2024 20:07, Heikki Linnakangas wrote: On 11/04/2024 02:33, Thomas Munro wrote: On Thu, Apr 11, 2024 at 11:25 AM Tom Lane wrote: Thomas Munro writes: If -Dssl=none and -Dgssapi=disabled, compilation of fe-connect.c fails: call to undeclared function 'encryption_negotiation_failed

pgsql: Document PG_TEST_EXTRA=libpq_encryption and also check 'kerberos

2024-04-12 Thread Heikki Linnakangas
Document PG_TEST_EXTRA=libpq_encryption and also check 'kerberos' In the libpq encryption negotiation tests, don't run the GSSAPI tests unless PG_TEST_EXTRA='kerberos' is also set. That makes it possible to still run most of the tests when GSSAPI support is compiled in, but there's no MIT

pgsql: Fix libpq_encryption tests when compiled without SSL support

2024-04-12 Thread Heikki Linnakangas
Fix libpq_encryption tests when compiled without SSL support It correctly skipped tests involving SSL in the server when SSL support was not compiled in, but even when SSL is not enabled in the server and the connection is established without SSL, libpq behaves differently in many of the test

pgsql: Move libpq encryption negotiation tests

2024-04-12 Thread Heikki Linnakangas
Move libpq encryption negotiation tests The test targets libpq's options, so 'src/test/interfaces/libpq/t' is a more natural place for it. While doing this, I noticed that I had missed adding the libpq_encryption subdir to the Makefile. That's why this commit only needs to remove it from the

pgsql: Fix compilation with --with-gssapi --without-openssl

2024-04-12 Thread Heikki Linnakangas
Fix compilation with --with-gssapi --without-openssl The #define is spelled ENABLE_GSS, not USE_GSS. Introduced in commit 05fd30c0e7, reported by Thomas Munro. Discussion: https://www.postgresql.org/message-id/ca%2bhukg%2bhrttb%2bx%2bkkkj_cfx6snhbeguqmgxjgmwdvpg7ygf...@mail.gmail.com Branch

Re: pgsql: Refactor libpq state machine for negotiating encryption

2024-04-11 Thread Heikki Linnakangas
still better test coverage than not having the tests at all. But given that no buildfarm members are testing that combination I think it can wait a day. -- Heikki Linnakangas Neon (https://neon.tech)

Re: pgsql: Add tests for libpq gssencmode and sslmode options

2024-04-10 Thread Heikki Linnakangas
On 10/04/2024 17:48, Peter Eisentraut wrote: On 08.04.24 01:50, Heikki Linnakangas wrote: Add tests for libpq gssencmode and sslmode options Why aren't these tests at src/interfaces/libpq/t/nnn_negotiate_encryption.pl ? To be honest, it never occurred to me. It started out as extra tests

Re: pgsql: With gssencmode='require', check credential cache before connect

2024-04-08 Thread Heikki Linnakangas
On 09/04/2024 04:46, Kyotaro Horiguchi wrote: Hello. At Sun, 07 Apr 2024 23:50:08 +, Heikki Linnakangas wrote in With gssencmode='require', check credential cache before connecting This commit adds the following error message (indentations are adjusted

pgsql: libpq error message fixes

2024-04-08 Thread Heikki Linnakangas
libpq error message fixes Remove stray paren, capitalize SSL and ALPN. Author: Kyotaro Horiguchi Discussion: https://www.postgresql.org/message-id/20240409.104613.1653854506705708036.horikyota@gmail.com Branch -- master Details ---

pgsql: Fix typo in docs

2024-04-08 Thread Heikki Linnakangas
Fix typo in docs Author: Erik Rijkers Discussion: https://www.postgresql.org/message-id/0167b1e1-676c-66ba-e857-3ad7cd844...@xs4all.nl Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/e9f29233fd67bd6b6667b61c88aa1f37f61f353a Modified Files --

Re: pgsql: Enhance libpq encryption negotiation tests with new GUC

2024-04-08 Thread Heikki Linnakangas
On 08/04/2024 09:40, Kyotaro Horiguchi wrote: At Sun, 07 Apr 2024 23:50:08 +, Heikki Linnakangas wrote in Enhance libpq encryption negotiation tests with new GUC This commit adds the following messages: gettext_noop("Log details of pre-authentication connection handshake."),

pgsql: Adjust wording of trace_connection_negotiation GUC's description

2024-04-08 Thread Heikki Linnakangas
Adjust wording of trace_connection_negotiation GUC's description We're not very consistent about this across all the GUCs, but the "Logs ..." phrasing is more common than "Log ...", and is used by the neighboring "log_connections" and "log_disconnections" GUCs, so switch to that. Author: Kyotaro

Re: pgsql: Send ALPN in TLS handshake, require it in direct SSL connections

2024-04-07 Thread Heikki Linnakangas
On 08/04/2024 04:50, Andres Freund wrote: On 2024-04-08 01:25:40 +, Heikki Linnakangas wrote: Send ALPN in TLS handshake, require it in direct SSL connections libpq now always tries to send ALPN. With the traditional negotiated SSL connections, the server accepts the ALPN, and refuses

pgsql: Fix check for 'outlen' return from SSL_select_next_proto()

2024-04-07 Thread Heikki Linnakangas
Fix check for 'outlen' return from SSL_select_next_proto() Fixes compiler warning reported by Andres Freund. Discusssion: https://www.postgresql.org/message-id/20240408015055.xsuahullywpfw...@awork3.anarazel.de Branch -- master Details ---

pgsql: Silence perlcritic warnings in new libpq tests

2024-04-07 Thread Heikki Linnakangas
Silence perlcritic warnings in new libpq tests Per buildfarm member 'koel'. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/d60ab76f630921dc4deb958fb7892ef6b0e4a7ee Modified Files -- src/test/libpq_encryption/t/001_negotiate_encryption.pl | 5 +++-- 1

pgsql: Refactor libpq state machine for negotiating encryption

2024-04-07 Thread Heikki Linnakangas
Refactor libpq state machine for negotiating encryption This fixes the few corner cases noted in commit 705843d294, as shown by the changes in the test. Author: Heikki Linnakangas, Matthias van de Meent Reviewed-by: Jacob Champion Branch -- master Details --- https://git.postgresql.org

pgsql: Support TLS handshake directly without SSLRequest negotiation

2024-04-07 Thread Heikki Linnakangas
, but the fallback can be disabled with the sslnegotiation=requiredirect option. Author: Greg Stark, Heikki Linnakangas Reviewed-by: Matthias van de Meent, Jacob Champion Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/d39a49c1e459804831302807c724fa6512e90cf0 Modified

pgsql: Send ALPN in TLS handshake, require it in direct SSL connections

2024-04-07 Thread Heikki Linnakangas
SSL connections, ALPN is mandatory. NOTE: This uses "TBD-pgsql" as the protocol ID. We must register a proper one with IANA before the release! Author: Greg Stark, Heikki Linnakangas Reviewed-by: Matthias van de Meent, Jacob Champion Branch -- master Details --- https://git.post

pgsql: Enhance libpq encryption negotiation tests with new GUC

2024-04-07 Thread Heikki Linnakangas
Enhance libpq encryption negotiation tests with new GUC The new "log_connection_negotiation" server option causes the server to print messages to the log when it receives a SSLRequest or GSSENCRequest packet from the client. Together with "log_connections", it gives a trace of how a connection

pgsql: With gssencmode='require', check credential cache before connect

2024-04-07 Thread Heikki Linnakangas
With gssencmode='require', check credential cache before connecting Previously, libpq would establish the TCP connection, and then immediately disconnect if the credentials were not available. The same thing happened if you tried to use a Unix domain socket with gssencmode=require. Check those

pgsql: Add tests for libpq gssencmode and sslmode options

2024-04-07 Thread Heikki Linnakangas
for "direct SSL" connections, which adds another dimension to the logic. If we add even more options in the future, testing all combinations will become unwieldy and we'll need to rethink this, but for now an exhaustive test is nice. Author: Heikki Linnakangas, Matthias van de Meent Reviewed

pgsql: Move Kerberos module

2024-04-07 Thread Heikki Linnakangas
Move Kerberos module So that we can reuse it in new tests. Discussion: https://www.postgresql.org/message-id/a3af4070-3556-461d-aec8-a8d794f94...@iki.fi Reviewed-by: Jacob Champion, Matthias van de Meent Branch -- master Details ---

pgsql: Improve check in LDAP test to find the OpenLDAP installation

2024-04-07 Thread Heikki Linnakangas
Improve check in LDAP test to find the OpenLDAP installation If the OpenLDAP installation directory is not found, set $setup to 0 so that the LDAP tests are skipped. The macOS checks were already doing that, but the checks on other OS's were not. While we're at it, improve the error message when

pgsql: Improve check in LDAP test to find the OpenLDAP installation

2024-04-07 Thread Heikki Linnakangas
Improve check in LDAP test to find the OpenLDAP installation If the OpenLDAP installation directory is not found, set $setup to 0 so that the LDAP tests are skipped. The macOS checks were already doing that, but the checks on other OS's were not. While we're at it, improve the error message when

pgsql: Improve check in LDAP test to find the OpenLDAP installation

2024-04-07 Thread Heikki Linnakangas
Improve check in LDAP test to find the OpenLDAP installation If the OpenLDAP installation directory is not found, set $setup to 0 so that the LDAP tests are skipped. The macOS checks were already doing that, but the checks on other OS's were not. While we're at it, improve the error message when

pgsql: Don't clobber test exit code at cleanup in LDAP/Kerberors tests

2024-04-07 Thread Heikki Linnakangas
Don't clobber test exit code at cleanup in LDAP/Kerberors tests If the test script die()d before running the first test, the whole test was interpreted as SKIPped rather than failed. The PostgreSQL::Cluster module got this right. Backpatch to all supported versions. Discussion:

pgsql: Improve check in LDAP test to find the OpenLDAP installation

2024-04-07 Thread Heikki Linnakangas
Improve check in LDAP test to find the OpenLDAP installation If the OpenLDAP installation directory is not found, set $setup to 0 so that the LDAP tests are skipped. The macOS checks were already doing that, but the checks on other OS's were not. While we're at it, improve the error message when

pgsql: Don't clobber test exit code at cleanup in LDAP/Kerberors tests

2024-04-07 Thread Heikki Linnakangas
Don't clobber test exit code at cleanup in LDAP/Kerberors tests If the test script die()d before running the first test, the whole test was interpreted as SKIPped rather than failed. The PostgreSQL::Cluster module got this right. Backpatch to all supported versions. Discussion:

pgsql: Don't clobber test exit code at cleanup in LDAP/Kerberors tests

2024-04-07 Thread Heikki Linnakangas
Don't clobber test exit code at cleanup in LDAP/Kerberors tests If the test script die()d before running the first test, the whole test was interpreted as SKIPped rather than failed. The PostgreSQL::Cluster module got this right. Backpatch to all supported versions. Discussion:

pgsql: Don't clobber test exit code at cleanup in LDAP/Kerberors tests

2024-04-07 Thread Heikki Linnakangas
Don't clobber test exit code at cleanup in LDAP/Kerberors tests If the test script die()d before running the first test, the whole test was interpreted as SKIPped rather than failed. The PostgreSQL::Cluster module got this right. Backpatch to all supported versions. Discussion:

pgsql: Don't clobber test exit code at cleanup in LDAP/Kerberors tests

2024-04-07 Thread Heikki Linnakangas
Don't clobber test exit code at cleanup in LDAP/Kerberors tests If the test script die()d before running the first test, the whole test was interpreted as SKIPped rather than failed. The PostgreSQL::Cluster module got this right. Backpatch to all supported versions. Discussion:

pgsql: Improve check in LDAP test to find the OpenLDAP installation

2024-04-07 Thread Heikki Linnakangas
Improve check in LDAP test to find the OpenLDAP installation If the OpenLDAP installation directory is not found, set $setup to 0 so that the LDAP tests are skipped. The macOS checks were already doing that, but the checks on other OS's were not. While we're at it, improve the error message when

pgsql: Improve check in LDAP test to find the OpenLDAP installation

2024-04-07 Thread Heikki Linnakangas
Improve check in LDAP test to find the OpenLDAP installation If the OpenLDAP installation directory is not found, set $setup to 0 so that the LDAP tests are skipped. The macOS checks were already doing that, but the checks on other OS's were not. While we're at it, improve the error message when

pgsql: Don't clobber test exit code at cleanup in LDAP/Kerberors tests

2024-04-07 Thread Heikki Linnakangas
Don't clobber test exit code at cleanup in LDAP/Kerberors tests If the test script die()d before running the first test, the whole test was interpreted as SKIPped rather than failed. The PostgreSQL::Cluster module got this right. Backpatch to all supported versions. Discussion:

pgsql: Combine freezing and pruning steps in VACUUM

2024-04-03 Thread Heikki Linnakangas
Combine freezing and pruning steps in VACUUM Execute both freezing and pruning of tuples in the same heap_page_prune() function, now called heap_page_prune_and_freeze(), and emit a single WAL record containing all changes. That reduces the overall amount of WAL generated. This moves the freezing

pgsql: Refactor how heap_prune_chain() updates prunable_xid

2024-04-03 Thread Heikki Linnakangas
Refactor how heap_prune_chain() updates prunable_xid In preparation of freezing and counting tuples which are not candidates for pruning, split heap_prune_record_unchanged() into multiple functions, depending the kind of line pointer. That's not too interesting right now, but makes the next

pgsql: Introduce 'options' argument to heap_page_prune()

2024-04-01 Thread Heikki Linnakangas
the arguments mean, so prefer a bitmask of options with human-readable names. Author: Melanie Plageman Author: Heikki Linnakangas Discussion: https://www.postgresql.org/message-id/20240401172219.fngjosaqdgqqvg4e@liskov Branch -- master Details --- https://git.postgresql.org/pg/commitdiff

pgsql: Handle non-chain tuples outside of heap_prune_chain()

2024-04-01 Thread Heikki Linnakangas
tem on the page should be marked as processed in the array; an assertion is added for that. Author: Melanie Plageman Author: Heikki Linnakangas Discussion: https://www.postgresql.org/message-id/20240330055710.kqg6ii2cdojsxgje@liskov Branch -- master Details --- https://git.postgresql.org

pgsql: Refactor heap_prune_chain()

2024-04-01 Thread Heikki Linnakangas
Refactor heap_prune_chain() Keep track of the number of deleted tuples in PruneState and record this information when recording a tuple dead, unused or redirected. This removes a special case from the traversal and chain processing logic as well as setting a precedent of recording the impact of

pgsql: Minor refactoring in heap_page_prune

2024-04-01 Thread Heikki Linnakangas
Minor refactoring in heap_page_prune Pass 'page', 'blockno' and 'maxoff' to heap_prune_chain() as arguments, so that it doesn't need to fetch them from the buffer. This saves a few cycles per chain. Remove the "if (off_loc != NULL)" checks, and require the caller to pass a non-NULL 'off_loc'.

pgsql: Remove obsolete comment about VACUUM retrying pruning

2024-03-28 Thread Heikki Linnakangas
Remove obsolete comment about VACUUM retrying pruning Commit 1ccc1e05ae removed the retry logic that the comment talked about. Reviewed-by: Melanie Plageman Discussion: https://www.postgresql.org/message-id/20240328015326.x5gnzsohl6j23b42@liskov Branch -- master Details ---

pgsql: Merge prune, freeze and vacuum WAL record formats

2024-03-25 Thread Heikki Linnakangas
Merge prune, freeze and vacuum WAL record formats The new combined WAL record is now used for pruning, freezing and 2nd pass of vacuum. This is in preparation for changing VACUUM to write a combined prune+freeze record per page, instead of separate two records. The new WAL record format now

pgsql: Reorganize heap_page_prune() function comment

2024-03-20 Thread Heikki Linnakangas
Reorganize heap_page_prune() function comment heap_page_prune()'s function header comment didn't explain the parameters in the same order they appear in the function. Fix that. Author: Melanie Plageman Discussion: https://www.postgresql.org/message-id/20240320013602.6sypr4cx6sefpemg@liskov

pgsql: Remove unused PruneState member rel

2024-03-20 Thread Heikki Linnakangas
Remove unused PruneState member rel PruneState->rel is no longer being used, so just remove it. Author: Melanie Plageman Discussion: https://www.postgresql.org/message-id/20240320013602.6sypr4cx6sefpemg@liskov Branch -- master Details ---

pgsql: Remove assertions that some compiler say are tautological

2024-03-20 Thread Heikki Linnakangas
Remove assertions that some compiler say are tautological To avoid the compiler warnings: launch_backend.c:211:39: warning: comparison of constant 16 with expression of type 'BackendType' (aka 'enum BackendType') is always true [-Wtautological-constant-out-of-range-compare]

pgsql: Fix EXPLAIN Bitmap heap scan to count pages with no visible tupl

2024-03-18 Thread Heikki Linnakangas
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples Previously, bitmap heap scans only counted lossy and exact pages for explain when there was at least one visible tuple on the page. heapam_scan_bitmap_next_block() returned true only if there was a "valid" page with tuples to be

pgsql: Fix EXPLAIN Bitmap heap scan to count pages with no visible tupl

2024-03-18 Thread Heikki Linnakangas
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples Previously, bitmap heap scans only counted lossy and exact pages for explain when there was at least one visible tuple on the page. heapam_scan_bitmap_next_block() returned true only if there was a "valid" page with tuples to be

pgsql: Fix EXPLAIN Bitmap heap scan to count pages with no visible tupl

2024-03-18 Thread Heikki Linnakangas
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples Previously, bitmap heap scans only counted lossy and exact pages for explain when there was at least one visible tuple on the page. heapam_scan_bitmap_next_block() returned true only if there was a "valid" page with tuples to be

pgsql: Fix EXPLAIN Bitmap heap scan to count pages with no visible tupl

2024-03-18 Thread Heikki Linnakangas
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples Previously, bitmap heap scans only counted lossy and exact pages for explain when there was at least one visible tuple on the page. heapam_scan_bitmap_next_block() returned true only if there was a "valid" page with tuples to be

pgsql: Fix EXPLAIN Bitmap heap scan to count pages with no visible tupl

2024-03-18 Thread Heikki Linnakangas
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples Previously, bitmap heap scans only counted lossy and exact pages for explain when there was at least one visible tuple on the page. heapam_scan_bitmap_next_block() returned true only if there was a "valid" page with tuples to be

pgsql: Fix EXPLAIN Bitmap heap scan to count pages with no visible tupl

2024-03-18 Thread Heikki Linnakangas
Fix EXPLAIN Bitmap heap scan to count pages with no visible tuples Previously, bitmap heap scans only counted lossy and exact pages for explain when there was at least one visible tuple on the page. heapam_scan_bitmap_next_block() returned true only if there was a "valid" page with tuples to be

pgsql: Split registration of Win32 deadchild callback to separate funct

2024-03-18 Thread Heikki Linnakangas
Split registration of Win32 deadchild callback to separate function The next commit will move the internal_forkexec() function to a different source file, but it makes sense to keep all the code related to the win32 waitpid() emulation in postmaster.c. Split it off to a separate function now, to

pgsql: Refactor postmaster child process launching

2024-03-18 Thread Heikki Linnakangas
Refactor postmaster child process launching Introduce new postmaster_child_launch() function that deals with the differences in EXEC_BACKEND mode. Refactor the mechanism of passing information from the parent to child process. Instead of using different command-line arguments when launching the

pgsql: Move some functions from postmaster.c to a new source file

2024-03-18 Thread Heikki Linnakangas
Move some functions from postmaster.c to a new source file This just moves the functions, with no other changes, to make the next commits smaller and easier to review. The moved functions are related to launching postmaster child processes in EXEC_BACKEND mode. Reviewed-by: Tristan Partin,

pgsql: Move code for backend startup to separate file

2024-03-18 Thread Heikki Linnakangas
Move code for backend startup to separate file This is code that runs in the backend process after forking, rather than postmaster. Move it out of postmaster.c for clarity. Reviewed-by: Tristan Partin, Andres Freund Discussion:

pgsql: Fix backstop in gin test if injection point is not reached

2024-03-15 Thread Heikki Linnakangas
Fix backstop in gin test if injection point is not reached Per Tom Lane's observation that the test got stuck in infinite loop if the injection_points module was not loaded. It was supposed to give up after 1 iterations, but the backstop was broken. Discussion:

pgsql: Try to unbreak injection-fault tests in the buildfarm

2024-03-15 Thread Heikki Linnakangas
Try to unbreak injection-fault tests in the buildfarm The buildfarm script attempts to run all tests marked as NO_INSTALLCHECK under src/test/modules without paying attention to whether they are enabled or disabled in the parent Makefile. That hasn't been a problem so far, because all the tests

pgsql: Improve log messages referring to background worker processes

2024-03-15 Thread Heikki Linnakangas
Improve log messages referring to background worker processes "Worker" could also mean autovacuum worker or slot sync worker, so let's be more explicit. Per Tristan Partin's suggestion. Discussion: https://www.postgresql.org/message-id/czm6wdx5h4qi.nzg1yuck...@neon.tech Branch -- master

pgsql: Disable tests using injection points in installcheck

2024-03-15 Thread Heikki Linnakangas
Disable tests using injection points in installcheck The 'gin' test injections faults to GIN index build. If another test running concurrently in the same cluster also tries to create a GIN index, it will hit the fault, too. To fix, disable tests using injection points when running against an

pgsql: Remove redundant snapshot copying from parallel leader to worker

2024-03-14 Thread Heikki Linnakangas
Remove redundant snapshot copying from parallel leader to workers The parallel query infrastructure copies the leader backend's active snapshot to the worker processes. But BitmapHeapScan node also had bespoken code to pass the snapshot from leader to the worker. That was redundant, so remove it.

pgsql: Fix copying SockAddr struct

2024-03-12 Thread Heikki Linnakangas
Fix copying SockAddr struct Valgrind alerted about accessing uninitialized bytes after commit 4945e4ed4a: ==700242== VALGRINDERROR-BEGIN ==700242== Conditional jump or move depends on uninitialised value(s) ==700242==at 0x6D8A2A: getnameinfo_unix (ip.c:253) ==700242==by 0x6D8BD1:

pgsql: Set socket options in child process after forking

2024-03-12 Thread Heikki Linnakangas
Set socket options in child process after forking Try to minimize the work done in the postmaster process for each accepted connection, so that postmaster can quickly proceed with its duties. These function calls are very fast so this doesn't make any measurable performance difference in

pgsql: Pass CAC as an argument to the backend process

2024-03-12 Thread Heikki Linnakangas
Pass CAC as an argument to the backend process We used to smuggle it to the child process in the Port struct, but it seems better to pass it down as a separate argument. This paves the way for the next commit, which moves the initialization of the Port struct to the backend process, after

pgsql: Move initialization of the Port struct to the child process

2024-03-12 Thread Heikki Linnakangas
Move initialization of the Port struct to the child process In postmaster, use a more lightweight ClientSocket struct that encapsulates just the socket itself and the remote endpoint's address that you get from accept() call. ClientSocket is passed to the child process, which initializes the

pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode Commit 387da18874 moved the code to put socket into non-blocking mode from socket_set_nonblocking() into the one-time initialization function, pq_init(). In socket_set_nonblocking(), there indeed was a risk of recursion on failure like the

pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode Commit 387da18874 moved the code to put socket into non-blocking mode from socket_set_nonblocking() into the one-time initialization function, pq_init(). In socket_set_nonblocking(), there indeed was a risk of recursion on failure like the

pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode Commit 387da18874 moved the code to put socket into non-blocking mode from socket_set_nonblocking() into the one-time initialization function, pq_init(). In socket_set_nonblocking(), there indeed was a risk of recursion on failure like the

pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode Commit 387da18874 moved the code to put socket into non-blocking mode from socket_set_nonblocking() into the one-time initialization function, pq_init(). In socket_set_nonblocking(), there indeed was a risk of recursion on failure like the

pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode Commit 387da18874 moved the code to put socket into non-blocking mode from socket_set_nonblocking() into the one-time initialization function, pq_init(). In socket_set_nonblocking(), there indeed was a risk of recursion on failure like the

pgsql: Disconnect if socket cannot be put into non-blocking mode

2024-03-12 Thread Heikki Linnakangas
Disconnect if socket cannot be put into non-blocking mode Commit 387da18874 moved the code to put socket into non-blocking mode from socket_set_nonblocking() into the one-time initialization function, pq_init(). In socket_set_nonblocking(), there indeed was a risk of recursion on failure like the

pgsql: Remove unneeded vacuum_delay_point from heap_vac_scan_get_next_b

2024-03-11 Thread Heikki Linnakangas
Remove unneeded vacuum_delay_point from heap_vac_scan_get_next_block heap_vac_scan_get_next_block() does relatively little work, so there is no need to call vacuum_delay_point(). A future commit will call heap_vac_scan_get_next_block() from a callback, and we would like to avoid calling

pgsql: Confine vacuum skip logic to lazy_scan_skip()

2024-03-11 Thread Heikki Linnakangas
to using a streaming read interface, and eventually AIO (https://postgr.es/m/CA%2BhUKGJkOiOCa%2Bmag4BF%2BzHo7qo%3Do9CFheB8%3Dg6uT5TUm2gkvA%40mail.gmail.com) Author: Melanie Plageman, Heikki Linnakangas Reviewed-by: Andres Freund (older version) Discussion: https://postgr.es/m

pgsql: Set all_visible_according_to_vm correctly with DISABLE_PAGE_SKIP

2024-03-11 Thread Heikki Linnakangas
Set all_visible_according_to_vm correctly with DISABLE_PAGE_SKIPPING It's important for 'all_visible_according_to_vm' to correctly reflect whether the VM bit is set or not, even when we are not trusting the VM to skip pages, because contrary to what the comment said, lazy_scan_prune() relies on

pgsql: Set all_visible_according_to_vm correctly with DISABLE_PAGE_SKIP

2024-03-11 Thread Heikki Linnakangas
Set all_visible_according_to_vm correctly with DISABLE_PAGE_SKIPPING It's important for 'all_visible_according_to_vm' to correctly reflect whether the VM bit is set or not, even when we are not trusting the VM to skip pages, because contrary to what the comment said, lazy_scan_prune() relies on

pgsql: Don't destroy SMgrRelations at relcache invalidation

2024-03-11 Thread Heikki Linnakangas
Don't destroy SMgrRelations at relcache invalidation With commit 21d9c3ee4e, SMgrRelations remain valid until end of transaction (or longer if they're "pinned"). Relcache invalidation can happen in the middle of a transaction, so we must not destroy them at relcache invalidation anymore. This

Re: pgsql: Unicode case mapping tables and functions.

2024-03-08 Thread Heikki Linnakangas
inated. But srclen is of type size_t, which is unsigned. -- Heikki Linnakangas Neon (https://neon.tech)

pgsql: Fix references to renamed function in comments

2024-03-05 Thread Heikki Linnakangas
Fix references to renamed function in comments I renamed the function in commit 024c521117, but missed these comments. Reported-by: Richard Guo Discussion: https://www.postgresql.org/message-id/cambws4-jr6qc7jrmkwz-zxqy_ayluz3phjgep4b91of321c...@mail.gmail.com Branch -- master Details

pgsql: Fix a leftover reference to backend_id in comment

2024-03-04 Thread Heikki Linnakangas
Fix a leftover reference to backend_id in comment Commit 024c521117 replaced backend_id with proc_number. Reported-by: Alexander Lakhin Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/55cdba2647ed6bbe1126c6b6d8f53e8602ec05a1 Modified Files --

pgsql: Remove unused ParallelWorkerInfo.pid field

2024-03-04 Thread Heikki Linnakangas
Remove unused ParallelWorkerInfo.pid field The pid was originally used in error context of messages propagated from parallel workers, but commit 292794f82b removed that. If the need arises in the future, you can also get the pid with "shm_mq_get_sender(pcxt->worker[i].error_mqh)->pid". Branch

pgsql: Remove unused 'countincludesself' argument to pq_sendcountedtext

2024-03-04 Thread Heikki Linnakangas
Remove unused 'countincludesself' argument to pq_sendcountedtext() It has been unused since we removed support for protocol version 2. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/24eebc65c26cfcc0ea5b8a95b61fa2fda6118e68 Modified Files --

pgsql: Remove MyAuxProcType, use MyBackendType instead

2024-03-04 Thread Heikki Linnakangas
Remove MyAuxProcType, use MyBackendType instead MyAuxProcType was redundant with MyBackendType. Reviewed-by: Reid Thompson, Andres Freund Discussion: https://www.postgresql.org/message-id/f3ecd4cb-85ee-4e54-8278-5fabfb3a4...@iki.fi Branch -- master Details ---

pgsql: Use MyBackendType in more places to check what process this is

2024-03-04 Thread Heikki Linnakangas
Use MyBackendType in more places to check what process this is Remove IsBackgroundWorker, IsAutoVacuumLauncherProcess(), IsAutoVacuumWorkerProcess(), and IsLogicalSlotSyncWorker() in favor of new Am*Process() macros that use MyBackendType. For consistency with the existing Am*Process() macros.

pgsql: Replace BackendIds with 0-based ProcNumbers

2024-03-03 Thread Heikki Linnakangas
Replace BackendIds with 0-based ProcNumbers Now that BackendId was just another index into the proc array, it was redundant with the 0-based proc numbers used in other places. Replace all usage of backend IDs with proc numbers. The only place where the term "backend id" remains is in a few

pgsql: Redefine backend ID to be an index into the proc array

2024-03-03 Thread Heikki Linnakangas
Redefine backend ID to be an index into the proc array Previously, backend ID was an index into the ProcState array, in the shared cache invalidation manager (sinvaladt.c). The entry in the ProcState array was reserved at backend startup by scanning the array for a free entry, and that was also

pgsql: Remove configure --with-CC option

2024-02-28 Thread Heikki Linnakangas
Remove configure --with-CC option It's been deprecated since commit cb292206c5 from July 2000. Discussion: https://www.postgresql.org/message-id/a2a0f5d8-2d80-48e5-b8f7-0a0a6018c...@iki.fi Branch -- master Details ---

pgsql: Run autoconf, for update of a comment.

2024-02-28 Thread Heikki Linnakangas
Run autoconf, for update of a comment. I forgot to run autoconf in commit 0b16bb8776, after some last minute comment changes. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/802d886054ff948022a93bae324eae66276623cc Modified Files -- configure | 2 +- 1

  1   2   3   4   5   6   7   >