pgsql: Introduce num_os_semaphores GUC.

2024-07-26 Thread Nathan Bossart
Introduce num_os_semaphores GUC. The documentation for System V IPC parameters provides complicated formulas to determine the appropriate values for SEMMNI and SEMMNS. Furthermore, these formulas have often been wrong because folks forget to update them (e.g., when adding a new auxiliary

pgsql: pg_upgrade: Move live_check variable to user_opts.

2024-07-26 Thread Nathan Bossart
pg_upgrade: Move live_check variable to user_opts. At the moment, pg_upgrade stores whether it is doing a "live check" (i.e., the user specified --check and the old server is still running) in a local variable scoped to main(). This live_check variable is passed to several functions. To further

pgsql: pg_upgrade: Retrieve subscription count more efficiently.

2024-07-24 Thread Nathan Bossart
pg_upgrade: Retrieve subscription count more efficiently. Presently, pg_upgrade obtains the number of subscriptions in the to-be-upgraded cluster by first querying pg_subscription in every database for the number of subscriptions in only that database. Then, in count_old_cluster_subscriptions(),

pgsql: pg_upgrade: Retrieve subscription count more efficiently.

2024-07-24 Thread Nathan Bossart
pg_upgrade: Retrieve subscription count more efficiently. Presently, pg_upgrade obtains the number of subscriptions in the to-be-upgraded cluster by first querying pg_subscription in every database for the number of subscriptions in only that database. Then, in count_old_cluster_subscriptions(),

pgsql: Detect integer overflow in array_set_slice().

2024-07-23 Thread Nathan Bossart
Detect integer overflow in array_set_slice(). When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted:

pgsql: Detect integer overflow in array_set_slice().

2024-07-23 Thread Nathan Bossart
Detect integer overflow in array_set_slice(). When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted:

pgsql: Detect integer overflow in array_set_slice().

2024-07-23 Thread Nathan Bossart
Detect integer overflow in array_set_slice(). When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted:

pgsql: Detect integer overflow in array_set_slice().

2024-07-23 Thread Nathan Bossart
Detect integer overflow in array_set_slice(). When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted:

pgsql: Detect integer overflow in array_set_slice().

2024-07-23 Thread Nathan Bossart
Detect integer overflow in array_set_slice(). When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted:

pgsql: Detect integer overflow in array_set_slice().

2024-07-23 Thread Nathan Bossart
Detect integer overflow in array_set_slice(). When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted:

pgsql: Detect integer overflow in array_set_slice().

2024-07-23 Thread Nathan Bossart
Detect integer overflow in array_set_slice(). When provided an empty initial array, array_set_slice() fails to check for overflow when computing the new array's dimensions. While such overflows are ordinarily caught by ArrayGetNItems(), commands with the following form are accepted:

pgsql: Add overflow checks to money type.

2024-07-19 Thread Nathan Bossart
Add overflow checks to money type. None of the arithmetic functions for the the money type handle overflow. This commit introduces several helper functions with overflow checking and makes use of them in the money type's arithmetic functions. Fixes bug #18240. Reported-by: Alexander Lakhin

pgsql: Add overflow checks to money type.

2024-07-19 Thread Nathan Bossart
Add overflow checks to money type. None of the arithmetic functions for the the money type handle overflow. This commit introduces several helper functions with overflow checking and makes use of them in the money type's arithmetic functions. Fixes bug #18240. Reported-by: Alexander Lakhin

pgsql: Add overflow checks to money type.

2024-07-19 Thread Nathan Bossart
Add overflow checks to money type. None of the arithmetic functions for the the money type handle overflow. This commit introduces several helper functions with overflow checking and makes use of them in the money type's arithmetic functions. Fixes bug #18240. Reported-by: Alexander Lakhin

pgsql: Add overflow checks to money type.

2024-07-19 Thread Nathan Bossart
Add overflow checks to money type. None of the arithmetic functions for the the money type handle overflow. This commit introduces several helper functions with overflow checking and makes use of them in the money type's arithmetic functions. Fixes bug #18240. Reported-by: Alexander Lakhin

pgsql: Add overflow checks to money type.

2024-07-19 Thread Nathan Bossart
Add overflow checks to money type. None of the arithmetic functions for the the money type handle overflow. This commit introduces several helper functions with overflow checking and makes use of them in the money type's arithmetic functions. Fixes bug #18240. Reported-by: Alexander Lakhin

pgsql: Add overflow checks to money type.

2024-07-19 Thread Nathan Bossart
Add overflow checks to money type. None of the arithmetic functions for the the money type handle overflow. This commit introduces several helper functions with overflow checking and makes use of them in the money type's arithmetic functions. Fixes bug #18240. Reported-by: Alexander Lakhin

pgsql: Add overflow checks to money type.

2024-07-19 Thread Nathan Bossart
Add overflow checks to money type. None of the arithmetic functions for the the money type handle overflow. This commit introduces several helper functions with overflow checking and makes use of them in the money type's arithmetic functions. Fixes bug #18240. Reported-by: Alexander Lakhin

pgsql: Use PqMsg_* macros in more places.

2024-07-17 Thread Nathan Bossart
Use PqMsg_* macros in more places. Commit f4b54e1ed9, which introduced macros for protocol characters, missed updating a few places. It also did not introduce macros for messages sent from parallel workers to their leader processes. This commit adds a new section in protocol.h for those.

pgsql: Use PqMsg_* macros in more places.

2024-07-17 Thread Nathan Bossart
Use PqMsg_* macros in more places. Commit f4b54e1ed9, which introduced macros for protocol characters, missed updating a few places. It also did not introduce macros for messages sent from parallel workers to their leader processes. This commit adds a new section in protocol.h for those.

pgsql: Add a couple of recent commits to .git-blame-ignore-revs.

2024-07-16 Thread Nathan Bossart
Add a couple of recent commits to .git-blame-ignore-revs. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/0a8ca122e511884d98a640cb3302866b74638688 Modified Files -- .git-blame-ignore-revs | 6 ++ 1 file changed, 6 insertions(+)

pgsql: Revamp documentation for predefined roles.

2024-07-10 Thread Nathan Bossart
Revamp documentation for predefined roles. Presently, the page for predefined roles contains a table with brief descriptions of what each role allows. Below the table, there is a separate section with more detailed information about some of the roles. As the set of predefined roles has grown

pgsql: Introduce pg_signal_autovacuum_worker.

2024-07-09 Thread Nathan Bossart
Introduce pg_signal_autovacuum_worker. Since commit 3a9b18b309, roles with privileges of pg_signal_backend cannot signal autovacuum workers. Many users treated the ability to signal autovacuum workers as a feature instead of a bug, so we are reintroducing it via a new predefined role. Having

pgsql: Use CREATE DATABASE ... STRATEGY = FILE_COPY in pg_upgrade.

2024-07-08 Thread Nathan Bossart
Use CREATE DATABASE ... STRATEGY = FILE_COPY in pg_upgrade. While this strategy is ordinarily quite costly because it requires performing two checkpoints, testing shows that it tends to be a faster choice than WAL_LOG during pg_upgrade, presumably because fsync is turned off. Furthermore, we can

pgsql: Remove check hooks for GUCs that contribute to MaxBackends.

2024-07-05 Thread Nathan Bossart
Remove check hooks for GUCs that contribute to MaxBackends. Each of max_connections, max_worker_processes, autovacuum_max_workers, and max_wal_senders has a GUC check hook that verifies the sum of those GUCs does not exceed a hard-coded limit (see the comment for MAX_BACKENDS in postmaster.h).

pgsql: Improve performance of binary_upgrade_set_pg_class_oids().

2024-07-03 Thread Nathan Bossart
Improve performance of binary_upgrade_set_pg_class_oids(). This function generates the commands that preserve the OIDs and relfilenodes of relations during pg_upgrade. It is called once per relevant relation, and each such call executes a relatively expensive query to retrieve information for a

pgsql: Remove is_index parameter from binary_upgrade_set_pg_class_oids(

2024-07-03 Thread Nathan Bossart
Remove is_index parameter from binary_upgrade_set_pg_class_oids(). Since commit 9a974cbcba, this function retrieves the relkind before it needs to know whether the relation is an index, so we no longer need callers to provide this information. Suggested-by: Daniel Gustafsson Reviewed-by: Daniel

pgsql: Add CODE_OF_CONDUCT.md, CONTRIBUTING.md, and SECURITY.md.

2024-07-02 Thread Nathan Bossart
Add CODE_OF_CONDUCT.md, CONTRIBUTING.md, and SECURITY.md. These "community health files" provide important information about the project and will be displayed prominently on the PostgreSQL GitHub mirror. For now, they just point to the website, but we may want to expand on the content in the

pgsql: pg_dump: Remove some unused return values.

2024-07-02 Thread Nathan Bossart
pg_dump: Remove some unused return values. getSchemaData() does not use the return values of many of its get* helper functions because they store the data elsewhere. For example, commit 92316a4582 introduced a separate hash table for dumpable objects that said helper functions populate. This

pgsql: Remove redundant privilege check from pg_sequences system view.

2024-07-01 Thread Nathan Bossart
Remove redundant privilege check from pg_sequences system view. This commit adjusts pg_sequence_last_value() to return NULL instead of ERROR-ing for sequences for which the current user lacks privileges. This allows us to remove the call to has_sequence_privilege() in the definition of the

pgsql: Add --no-sync to pg_upgrade's uses of pg_dump and pg_dumpall.

2024-07-01 Thread Nathan Bossart
Add --no-sync to pg_upgrade's uses of pg_dump and pg_dumpall. There's no reason to ensure that the files pg_upgrade generates with pg_dump and pg_dumpall have been written safely to disk. If there is a crash during pg_upgrade, the upgrade must be restarted from the beginning; dump files left

pgsql: Use PqMsg_* macros in fe-auth.c.

2024-06-26 Thread Nathan Bossart
Use PqMsg_* macros in fe-auth.c. Commit f4b54e1ed9, which introduced macros for protocol characters, missed updating a few places in fe-auth.c. Author: Jelte Fennema-Nio Discussion: https://postgr.es/m/CAGECzQSoPHtZ4xe0raJ6FYSEiPPS%2BYWXBhOGo%2BY1YecLgknF3g%40mail.gmail.com Branch --

pgsql: Fix comment in pg_upgrade.h.

2024-06-19 Thread Nathan Bossart
Fix comment in pg_upgrade.h. Contrary to what the comment for the "check" struct member claims, 'pg_upgrade --check' performs only the checks and does not ask the user for permission to make changes. Reviewed-by: Daniel Gustafsson Discussion: https://postgr.es/m/ZnHk7ci5IuTWVc_c%40nathan Branch

pgsql: Fix documentation for POSIX semaphores.

2024-06-05 Thread Nathan Bossart
Fix documentation for POSIX semaphores. The documentation for POSIX semaphores is missing a reference to max_wal_senders. This commit fixes that in the same way that commit 4ebe51a5fb fixed the same issue in the documentation for System V semaphores. Discussion:

pgsql: Fix documentation for POSIX semaphores.

2024-06-05 Thread Nathan Bossart
Fix documentation for POSIX semaphores. The documentation for POSIX semaphores is missing a reference to max_wal_senders. This commit fixes that in the same way that commit 4ebe51a5fb fixed the same issue in the documentation for System V semaphores. Discussion:

pgsql: Fix documentation for POSIX semaphores.

2024-06-05 Thread Nathan Bossart
Fix documentation for POSIX semaphores. The documentation for POSIX semaphores is missing a reference to max_wal_senders. This commit fixes that in the same way that commit 4ebe51a5fb fixed the same issue in the documentation for System V semaphores. Discussion:

pgsql: Fix documentation for POSIX semaphores.

2024-06-05 Thread Nathan Bossart
Fix documentation for POSIX semaphores. The documentation for POSIX semaphores is missing a reference to max_wal_senders. This commit fixes that in the same way that commit 4ebe51a5fb fixed the same issue in the documentation for System V semaphores. Discussion:

pgsql: Fix documentation for POSIX semaphores.

2024-06-05 Thread Nathan Bossart
Fix documentation for POSIX semaphores. The documentation for POSIX semaphores is missing a reference to max_wal_senders. This commit fixes that in the same way that commit 4ebe51a5fb fixed the same issue in the documentation for System V semaphores. Discussion:

pgsql: Fix documentation for POSIX semaphores.

2024-06-05 Thread Nathan Bossart
Fix documentation for POSIX semaphores. The documentation for POSIX semaphores is missing a reference to max_wal_senders. This commit fixes that in the same way that commit 4ebe51a5fb fixed the same issue in the documentation for System V semaphores. Discussion:

pgsql: Fix documentation for System V semaphores.

2024-06-03 Thread Nathan Bossart
Fix documentation for System V semaphores. The formulas for SEMMNI and SEMMNS do not include the archiver process, which was converted to an auxiliary process in v14, and the WAL summarizer process, which was introduced in v17. This commit corrects these formulas and adds a missing reference to

pgsql: Fix documentation for System V semaphores.

2024-06-03 Thread Nathan Bossart
Fix documentation for System V semaphores. The formulas for SEMMNI and SEMMNS do not include the archiver process, which was converted to an auxiliary process in v14, and the WAL summarizer process, which was introduced in v17. This commit corrects these formulas and adds a missing reference to

pgsql: Fix documentation for System V semaphores.

2024-06-03 Thread Nathan Bossart
Fix documentation for System V semaphores. The formulas for SEMMNI and SEMMNS do not include the archiver process, which was converted to an auxiliary process in v14, and the WAL summarizer process, which was introduced in v17. This commit corrects these formulas and adds a missing reference to

pgsql: Fix documentation for System V semaphores.

2024-06-03 Thread Nathan Bossart
Fix documentation for System V semaphores. The formulas for SEMMNI and SEMMNS do not include the archiver process, which was converted to an auxiliary process in v14, and the WAL summarizer process, which was introduced in v17. This commit corrects these formulas and adds a missing reference to

pgsql: Fix documentation for System V semaphores.

2024-06-03 Thread Nathan Bossart
Fix documentation for System V semaphores. The formulas for SEMMNI and SEMMNS do not include the archiver process, which was converted to an auxiliary process in v14, and the WAL summarizer process, which was introduced in v17. This commit corrects these formulas and adds a missing reference to

pgsql: Fix documentation for System V semaphores.

2024-06-03 Thread Nathan Bossart
Fix documentation for System V semaphores. The formulas for SEMMNI and SEMMNS do not include the archiver process, which was converted to an auxiliary process in v14, and the WAL summarizer process, which was introduced in v17. This commit corrects these formulas and adds a missing reference to

pgsql: Fix pg_sequence_last_value() for unlogged sequences on standbys.

2024-05-14 Thread Nathan Bossart
Fix pg_sequence_last_value() for unlogged sequences on standbys. Presently, when this function is called for an unlogged sequence on a standby server, it will error out with a message like ERROR: could not open file "base/5/16388": No such file or directory Since the pg_sequences

pgsql: Fix pg_sequence_last_value() for unlogged sequences on standbys.

2024-05-14 Thread Nathan Bossart
Fix pg_sequence_last_value() for unlogged sequences on standbys. Presently, when this function is called for an unlogged sequence on a standby server, it will error out with a message like ERROR: could not open file "base/5/16388": No such file or directory Since the pg_sequences

pgsql: Fix pg_sequence_last_value() for unlogged sequences on standbys.

2024-05-14 Thread Nathan Bossart
Fix pg_sequence_last_value() for unlogged sequences on standbys. Presently, when this function is called for an unlogged sequence on a standby server, it will error out with a message like ERROR: could not open file "base/5/16388": No such file or directory Since the pg_sequences

pgsql: Fix pg_sequence_last_value() for unlogged sequences on standbys.

2024-05-14 Thread Nathan Bossart
Fix pg_sequence_last_value() for unlogged sequences on standbys. Presently, when this function is called for an unlogged sequence on a standby server, it will error out with a message like ERROR: could not open file "base/5/16388": No such file or directory Since the pg_sequences

pgsql: Fix pg_sequence_last_value() for unlogged sequences on standbys.

2024-05-14 Thread Nathan Bossart
Fix pg_sequence_last_value() for unlogged sequences on standbys. Presently, when this function is called for an unlogged sequence on a standby server, it will error out with a message like ERROR: could not open file "base/5/16388": No such file or directory Since the pg_sequences

pgsql: Fix pg_sequence_last_value() for unlogged sequences on standbys.

2024-05-14 Thread Nathan Bossart
Fix pg_sequence_last_value() for unlogged sequences on standbys. Presently, when this function is called for an unlogged sequence on a standby server, it will error out with a message like ERROR: could not open file "base/5/16388": No such file or directory Since the pg_sequences

pgsql: Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs.

2024-05-09 Thread Nathan Bossart
Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs. The catalog view pg_stats_ext fails to consider privileges for expression statistics. The catalog view pg_stats_ext_exprs fails to consider privileges and row-level security policies. To fix, restrict the data in these views to table

pgsql: Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs.

2024-05-09 Thread Nathan Bossart
Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs. The catalog view pg_stats_ext fails to consider privileges for expression statistics. The catalog view pg_stats_ext_exprs fails to consider privileges and row-level security policies. To fix, restrict the data in these views to table

pgsql: Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs.

2024-05-09 Thread Nathan Bossart
Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs. The catalog view pg_stats_ext fails to consider privileges for expression statistics. The catalog view pg_stats_ext_exprs fails to consider privileges and row-level security policies. To fix, restrict the data in these views to table

pgsql: Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs.

2024-05-09 Thread Nathan Bossart
Fix privilege checks in pg_stats_ext and pg_stats_ext_exprs. The catalog view pg_stats_ext fails to consider privileges for expression statistics. The catalog view pg_stats_ext_exprs fails to consider privileges and row-level security policies. To fix, restrict the data in these views to table

pgsql: Fix code for probing availability of AVX-512.

2024-04-23 Thread Nathan Bossart
Fix code for probing availability of AVX-512. This commit fixes a few things: * Instead of checking for CPU support of the "xsave" extension, we need to check for OS support of XGETBV instructions via the "osxsave" flag. * We must check that additional XCR0 bits are set to be sure the ZMM

pgsql: doc: Note exceptions for SET ROLE's effect on privilege checks.

2024-04-15 Thread Nathan Bossart
doc: Note exceptions for SET ROLE's effect on privilege checks. The documentation for SET ROLE states that superusers who switch to a non-superuser role lose their superuser privileges. While this is true for most commands, there are exceptions such as SET ROLE and SET SESSION AUTHORIZATION,

pgsql: Optimize visibilitymap_count() with AVX-512 instructions.

2024-04-06 Thread Nathan Bossart
Optimize visibilitymap_count() with AVX-512 instructions. Commit 792752af4e added infrastructure for using AVX-512 intrinsic functions, and this commit uses that infrastructure to optimize visibilitymap_count(). Specificially, a new pg_popcount_masked() function is introduced that applies a

pgsql: Optimize pg_popcount() with AVX-512 instructions.

2024-04-06 Thread Nathan Bossart
Optimize pg_popcount() with AVX-512 instructions. Presently, pg_popcount() processes data in 32-bit or 64-bit chunks when possible. Newer hardware that supports AVX-512 instructions can use 512-bit chunks, which provides a nice speedup, especially for larger buffers. This commit introduces the

pgsql: Inline pg_popcount() for small buffers.

2024-04-03 Thread Nathan Bossart
Inline pg_popcount() for small buffers. If there aren't many bytes to process, the function call overhead of the optimized implementation isn't worth taking, so instead we inline a loop that consults pg_number_of_ones in that case. If there are many bytes to process, we accept the function call

pgsql: Add built-in ERROR handling for archive callbacks.

2024-04-02 Thread Nathan Bossart
Add built-in ERROR handling for archive callbacks. Presently, the archiver process restarts when an archive callback ERRORs. To avoid this, archive module authors can use sigsetjmp(), manage a memory context, etc., but that requires a lot of extra code that will likely look roughly the same

pgsql: Avoid function call overhead of pg_popcount() in syslogger.c.

2024-04-02 Thread Nathan Bossart
Avoid function call overhead of pg_popcount() in syslogger.c. Instead of calling the pg_popcount() function for a single byte, we can look up the value in the pg_number_of_ones array. Discussion: https://postgr.es/m/20240401221117.GB2362108%40nathanxps13 Branch -- master Details ---

pgsql: Refactor code for setting pg_popcount* function pointers.

2024-04-02 Thread Nathan Bossart
Refactor code for setting pg_popcount* function pointers. Presently, there are three copies of this code, and a proposed follow-up patch would add more code to each copy. This commit introduces a new inline function for this code and makes use of it in the pg_popcount*_choose functions, thereby

pgsql: Improve style of pg_lfind32().

2024-03-27 Thread Nathan Bossart
Improve style of pg_lfind32(). This commit simplifies pg_lfind32() a bit by moving the standard one-by-one linear search code to an inline helper function. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/20240327013616.GA3940109%40nathanxps13 Branch -- master Details ---

pgsql: Adjust documentation for syncfs().

2024-03-27 Thread Nathan Bossart
Adjust documentation for syncfs(). Commit 8c16ad3b43 created a new appendix for syncfs(), which is excessive for such a small amount of content. This commit moves the description of the caveats to be aware of when using syncfs() back to the documentation for recovery_init_sync_method. The

pgsql: Fix compiler warning for pg_lfind32().

2024-03-26 Thread Nathan Bossart
Fix compiler warning for pg_lfind32(). The newly-introduced "one_by_one" label produces -Wunused-label warnings when building without SIMD support. To fix, move the label into the SIMD section of this function. Oversight in commit 7644a7340c. Reported-by: Tom Lane Discussion:

pgsql: Add commit 64e401b62b to .git-blame-ignore-revs.

2024-03-26 Thread Nathan Bossart
Add commit 64e401b62b to .git-blame-ignore-revs. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/ffa9bb53ecb1cec14039d0c78e6f941565e8f986 Modified Files -- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+)

pgsql: Optimize roles_is_member_of() with a Bloom filter.

2024-03-26 Thread Nathan Bossart
Optimize roles_is_member_of() with a Bloom filter. When the list of roles gathered by roles_is_member_of() grows very large, a Bloom filter is created to help avoid some linear searches through the list. The threshold for creating the Bloom filter is set arbitrarily high and may require future

pgsql: Micro-optimize pg_lfind32().

2024-03-26 Thread Nathan Bossart
Micro-optimize pg_lfind32(). This commit improves the performance of pg_lfind32() in many cases by modifying it to process the remaining "tail" of elements with SIMD instructions instead of processing them one-by-one. Since the SIMD code processes a large block of elements, this means that we

pgsql: Adjust pgbench option for debug mode.

2024-03-25 Thread Nathan Bossart
Adjust pgbench option for debug mode. Many other utilities use -d to specify the database to use, but pgbench uses it to enable debug mode. This is causing some users to accidentally enable it. This commit changes -d to accept the database name and introduces --dbname. Debug mode can still be

pgsql: doc: Clarify requirements for SET ROLE.

2024-03-24 Thread Nathan Bossart
doc: Clarify requirements for SET ROLE. Since commit 3d14e171e9, SET ROLE has required the current session user to have membership with the SET option in the target role, but the SET ROLE documentation only mentions the membership requirement. This commit adds this important detail to the SET

pgsql: doc: Clarify requirements for SET ROLE.

2024-03-24 Thread Nathan Bossart
doc: Clarify requirements for SET ROLE. Since commit 3d14e171e9, SET ROLE has required the current session user to have membership with the SET option in the target role, but the SET ROLE documentation only mentions the membership requirement. This commit adds this important detail to the SET

pgsql: Revise the style of a paragraph in README.md.

2024-03-21 Thread Nathan Bossart
Revise the style of a paragraph in README.md. Presently, one of the lines in README.md has trailing whitespace, which was added by commit 363eb05996 to maintain a line break that was in the non-Markdown version. Instead of changing .gitattributes, let's match this paragraph's style with the

pgsql: Avoid overflow in MaybeRemoveOldWalSummaries().

2024-03-20 Thread Nathan Bossart
Avoid overflow in MaybeRemoveOldWalSummaries(). This commit limits the maximum value of wal_summary_keep_time to INT_MAX / SECS_PER_MINUTE to avoid overflow when it is converted to seconds. In passing, use the HOURS_PER_DAY, MINS_PER_HOUR, and SECS_PER_MINUTE macros in the code for this GUC

pgsql: Revert "Temporary patch to help debug pg_walsummary test failure

2024-03-20 Thread Nathan Bossart
Revert "Temporary patch to help debug pg_walsummary test failures." Thanks to commits ea18eb7d62, b6ee30ec08, and 19a829a327, the 002_blocks.pl test now consistently passes, so we can remove this temporary debugging code. This reverts commit 5ddf9973477729cf161b4ad0a1efd52f4fea9c88. Discussion:

pgsql: Inline pg_popcount{32,64} into pg_popcount().

2024-03-19 Thread Nathan Bossart
Inline pg_popcount{32,64} into pg_popcount(). On some systems, calls to pg_popcount{32,64} are indirected through a function pointer. This commit converts pg_popcount() to a function pointer on those systems so that we can inline the appropriate pg_popcount{32,64} implementations into each of

pgsql: Initialize variables to placate compiler.

2024-03-17 Thread Nathan Bossart
Initialize variables to placate compiler. Since commit 012460ee93, some compilers have been warning that a couple of variables may be used uninitialized. There doesn't appear to be any actual risk, so let's just initialize these variables to 0 to silence the compiler warnings. Discussion:

pgsql: Add pg_column_toast_chunk_id().

2024-03-14 Thread Nathan Bossart
Add pg_column_toast_chunk_id(). This function returns the chunk_id of an on-disk TOASTed value. If the value is un-TOASTed or not on-disk, it returns NULL. This is useful for identifying which values are actually TOASTed and for investigating "unexpected chunk number" errors. Bumps catversion.

pgsql: Reintroduce MAINTAIN privilege and pg_maintain predefined role.

2024-03-13 Thread Nathan Bossart
Reintroduce MAINTAIN privilege and pg_maintain predefined role. Roles with MAINTAIN on a relation may run VACUUM, ANALYZE, REINDEX, REFRESH MATERIALIZE VIEW, CLUSTER, and LOCK TABLE on the relation. Roles with privileges of pg_maintain may run those same commands on all relations. This was

pgsql: reindexdb: Allow specifying objects to process in all databases.

2024-03-11 Thread Nathan Bossart
reindexdb: Allow specifying objects to process in all databases. Presently, reindexdb's --table, --schema, --index, and --system options cannot be used together with --all, i.e., you cannot specify objects to process in all databases. This commit removes this unnecessary restriction.

pgsql: clusterdb: Allow specifying tables to process in all databases.

2024-03-11 Thread Nathan Bossart
clusterdb: Allow specifying tables to process in all databases. Presently, clusterdb's --table option cannot be used together with --all, i.e., you cannot specify tables to process in all databases. This commit removes this unnecessary restriction. In passing, change the synopsis in the

pgsql: vacuumdb: Allow specifying objects to process in all databases.

2024-03-11 Thread Nathan Bossart
vacuumdb: Allow specifying objects to process in all databases. Presently, vacuumdb's --table, --schema, and --exclude-schema options cannot be used together with --all, i.e., you cannot specify tables or schemas to process in all databases. This commit removes this unnecessary restriction, thus

pgsql: Add a few recent commits to .git-blame-ignore-revs.

2024-03-05 Thread Nathan Bossart
Add a few recent commits to .git-blame-ignore-revs. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/571530452fe0b15727b8b6730e64800a5e96a7b2 Modified Files -- .git-blame-ignore-revs | 12 1 file changed, 12 insertions(+)

pgsql: Add macro for customizing an archiving WARNING message.

2024-03-04 Thread Nathan Bossart
Add macro for customizing an archiving WARNING message. Presently, if an archive module's check_configured_cb callback returns false, a generic WARNING message is emitted, which unfortunately provides no actionable details about the reason why the module is not configured. This commit introduces

pgsql: Convert unloggedLSN to an atomic variable.

2024-02-29 Thread Nathan Bossart
Convert unloggedLSN to an atomic variable. Currently, this variable is an XLogRecPtr protected by a spinlock. By converting it to an atomic variable, we can remove the spinlock, which saves a small amount of shared memory space. Since this code is not performance-critical, we use atomic

pgsql: Convert archiver's force_dir_scan variable to an atomic variable

2024-02-29 Thread Nathan Bossart
Convert archiver's force_dir_scan variable to an atomic variable. Commit bd5132db55 introduced new atomic read/write functions with full barrier semantics, which are intended to simplify converting non-performance-critical code to use atomic variables. This commit demonstrates one such

pgsql: Introduce atomic read/write functions with full barrier semantic

2024-02-29 Thread Nathan Bossart
Introduce atomic read/write functions with full barrier semantics. Writing correct code using atomic variables is often difficult due to the memory barrier semantics (or lack thereof) of the underlying operations. This commit introduces atomic read/write functions with full barrier semantics to

pgsql: Convert README to Markdown.

2024-02-28 Thread Nathan Bossart
Convert README to Markdown. This is a first step toward modernizing our README file. Some popular developer platforms support rendering README.md files, so a direct conversion to Markdown seems like a good place to start. The intent is to keep this file legible as plain text even as it

pgsql: Fix comments for the dshash_parameters struct.

2024-02-27 Thread Nathan Bossart
Fix comments for the dshash_parameters struct. A recent commit added a copy_function member to the dshash_parameters struct, but it missed updating a couple of comments that refer to the function pointer members of this struct. One of those comments also refers to a tranche_name member and non-

pgsql: Use NULL instead of 0 for 'arg' argument in dshash_create() call

2024-02-26 Thread Nathan Bossart
Use NULL instead of 0 for 'arg' argument in dshash_create() calls. A couple of dshash_create() callers provide 0 for the 'void *arg' argument, which might give readers the incorrect impression that this is some sort of "flags" parameter. Reviewed-by: Andy Fan Discussion:

pgsql: Add helper functions for dshash tables with string keys.

2024-02-26 Thread Nathan Bossart
Add helper functions for dshash tables with string keys. Presently, string keys are not well-supported for dshash tables. The dshash code always copies key_size bytes into new entries' keys, and dshash.h only provides compare and hash functions that forward to memcmp() and tag_hash(), both of

pgsql: Use new overflow-safe integer comparison functions.

2024-02-16 Thread Nathan Bossart
Use new overflow-safe integer comparison functions. Commit 6b80394781 introduced integer comparison functions designed to be as efficient as possible while avoiding overflow. This commit makes use of these functions in many of the in-tree qsort() comparators to help ensure transitivity. Many of

pgsql: Introduce overflow-safe integer comparison functions.

2024-02-16 Thread Nathan Bossart
Introduce overflow-safe integer comparison functions. This commit adds integer comparison functions that are designed to be as efficient as possible while avoiding overflow. A follow-up commit will make use of these functions in many of the in-tree qsort() comparators. The new functions are not

pgsql: Replace calls to pg_qsort() with the qsort() macro.

2024-02-16 Thread Nathan Bossart
Replace calls to pg_qsort() with the qsort() macro. Calls to this function might give the impression that pg_qsort() is somehow different than qsort(), when in fact there is a qsort() macro in port.h that expands all in-tree uses to pg_qsort(). Reviewed-by: Mats Kindahl Discussion:

pgsql: Remove obsolete check in SIGTERM handler for the startup process

2024-02-14 Thread Nathan Bossart
Remove obsolete check in SIGTERM handler for the startup process. Thanks to commit 3b00fdba9f, this check in the SIGTERM handler for the startup process is now obsolete and can be removed. Instead of leaving around the dead function write_stderr_signal_safe(), I've opted to just remove it for

pgsql: Centralize logic for restoring errno in signal handlers.

2024-02-14 Thread Nathan Bossart
Centralize logic for restoring errno in signal handlers. Presently, we rely on each individual signal handler to save the initial value of errno and then restore it before returning if needed. This is easily forgotten and, if missed, often goes undetected for a long time. In commit 3b00fdba9f,

pgsql: Check that MyProcPid == getpid() in backend signal handlers.

2024-02-14 Thread Nathan Bossart
Check that MyProcPid == getpid() in backend signal handlers. In commit 97550c0711, we added a similar check to the SIGTERM handler for the startup process. This commit adds this check to backend signal handlers installed with pqsignal(). This is done by using a wrapper function that performs

pgsql: Allow pg_monitor to execute pg_current_logfile().

2024-02-14 Thread Nathan Bossart
Allow pg_monitor to execute pg_current_logfile(). We allow roles with privileges of pg_monitor to execute functions like pg_ls_logdir(), so it seems natural that such roles would also be able to execute this function. Bumps catversion. Co-authored-by: Pavlo Golub Reviewed-by: Daniel Gustafsson

pgsql: Remove Start* macros in postmaster.c.

2024-02-07 Thread Nathan Bossart
Remove Start* macros in postmaster.c. These macros are just shorthands for calling StartChildProcess() with the appropriate process type, and they arguably make the code harder to understand. Suggested-by: Andres Freund Author: Reid Thompson Reviewed-by: Bharath Rupireddy Discussion:

pgsql: Move is_valid_ascii() to ascii.h.

2024-01-29 Thread Nathan Bossart
Move is_valid_ascii() to ascii.h. This function requires simd.h, which is a rather large dependency for a widely-used header file like pg_wchar.h. Furthermore, there is a report of a third-party tool that is struggling to use pg_wchar.h due to its dependence on simd.h (presumably because simd.h

  1   2   >