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

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

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

pgsql: Fix crash in autoprewarm.

2024-01-23 Thread Nathan Bossart
Fix crash in autoprewarm. Commit abb0b4fc03 moved the shared state for autoprewarm to a dynamic shared memory (DSM) segment, but it left apw_detach_shmem() in the on_shmem_exit callback list for the autoprewarm leader process. This is a problem because shmem_exit() detaches all the DSM segments

pgsql: Fix possible NULL pointer dereference in GetNamedDSMSegment().

2024-01-22 Thread Nathan Bossart
Fix possible NULL pointer dereference in GetNamedDSMSegment(). GetNamedDSMSegment() doesn't check whether dsm_attach() returns NULL, which creates the possibility of a NULL pointer dereference soon after. To fix, emit an ERROR if dsm_attach() returns NULL. This shouldn't happen, but it would be

pgsql: Teach autoprewarm to use the dynamic shared memory registry.

2024-01-19 Thread Nathan Bossart
Teach autoprewarm to use the dynamic shared memory registry. Besides showcasing the DSM registry, this prevents pg_prewarm from stealing from the main shared memory segment's extra buffer space when autoprewarm_start_worker() and autoprewarm_dump_now() are used without loading the module via

pgsql: Introduce the dynamic shared memory registry.

2024-01-19 Thread Nathan Bossart
Introduce the dynamic shared memory registry. Presently, the most straightforward way for a shared library to use shared memory is to request it at server startup via a shmem_request_hook, which requires specifying the library in shared_preload_libraries. Alternatively, the library can create a

pgsql: doc: Reorganize section for shared memory and LWLocks.

2024-01-19 Thread Nathan Bossart
doc: Reorganize section for shared memory and LWLocks. Presently, this section meanders through a few different features, and the text itself is terse. This commit attempts to improve matters by splitting the section into smaller sections and by expanding the text for clarity. This is

pgsql: Improve some documentation about the bootstrap superuser.

2024-01-18 Thread Nathan Bossart
Improve some documentation about the bootstrap superuser. This commit adds some notes about the inability to remove superuser privileges from the bootstrap superuser. This has been blocked since commit e530be2c5c, but it wasn't intended be a supported feature before that, either. In passing,

pgsql: Fix documentation for wal_summary_keep_time.

2024-01-09 Thread Nathan Bossart
Fix documentation for wal_summary_keep_time. The documentation for this parameter lists its type as boolean, but it is actually an integer. Furthermore, there is no mention of how the value is interpreted when specified without units. This commit fixes these oversights in commit 174c480508.

pgsql: Cross-check lists of predefined LWLocks.

2024-01-09 Thread Nathan Bossart
Cross-check lists of predefined LWLocks. Both lwlocknames.txt and wait_event_names.txt contain a list of all the predefined LWLocks, i.e., those with predefined positions within MainLWLockArray. It is easy to miss one or the other, especially since the list in wait_event_names.txt omits the

pgsql: Add macros for looping through a List without a ListCell.

2024-01-04 Thread Nathan Bossart
Add macros for looping through a List without a ListCell. Many foreach loops only use the ListCell pointer to retrieve the content of the cell, like so: ListCell *lc; foreach(lc, mylist) { int myint = lfirst_int(lc); ... } This commit adds a few

pgsql: Optimize pg_atomic_exchange_u32 and pg_atomic_exchange_u64.

2023-12-18 Thread Nathan Bossart
Optimize pg_atomic_exchange_u32 and pg_atomic_exchange_u64. Presently, all platforms implement atomic exchanges by performing an atomic compare-and-swap in a loop until it succeeds. This can be especially expensive when there is contention on the atomic variable. This commit optimizes atomic

pgsql: Micro-optimize datum_to_json_internal() some more.

2023-12-18 Thread Nathan Bossart
Micro-optimize datum_to_json_internal() some more. Commit dc3f9bc549 mainly targeted the JSONTYPE_NUMERIC code path. This commit applies similar optimizations (e.g., removing unnecessary runtime calls to strlen() and palloc()) to nearby code. Reviewed-by: Tom Lane Discussion:

pgsql: Micro-optimize JSONTYPE_NUMERIC code path in json.c.

2023-12-08 Thread Nathan Bossart
Micro-optimize JSONTYPE_NUMERIC code path in json.c. This commit does the following: * In datum_to_json_internal(), the call to IsValidJsonNumber() is replaced with simplified validation code. This avoids an extra call to strlen() in this path, and it avoids validating the entire string

pgsql: Suppress -Wunused-result warning about write().

2023-12-06 Thread Nathan Bossart
Suppress -Wunused-result warning about write(). pg_test_fsync's signal_cleanup() intentionally ignores the write() result since there's not much we could do about it, but certain compilers make that harder than it ought to be. This was missed in commit 52e98d4502. Reviewed-by: Tristan Partin,

pgsql: Teach convert() and friends to avoid copying when possible.

2023-12-04 Thread Nathan Bossart
Teach convert() and friends to avoid copying when possible. Presently, pg_convert() allocates a new bytea and copies the result regardless of whether any conversion actually happened. This commit adjusts this function to return the source pointer as-is if no conversion occurred. This

pgsql: Retire a few backwards compatibility macros.

2023-11-27 Thread Nathan Bossart
Retire a few backwards compatibility macros. As of commits dd04e958c8 and 1833f1a1c3, tuplestore_donestoring(), SPI_push(), SPI_pop(), SPI_push_conditional(), SPI_pop_conditional(), and SPI_restore_connection() are no-op macros provided for backwards compatibility. This commit removes these

pgsql: Fix fallback implementation for pg_atomic_test_set_flag().

2023-11-15 Thread Nathan Bossart
Fix fallback implementation for pg_atomic_test_set_flag(). The fallback implementation of pg_atomic_test_set_flag() that uses atomic-exchange gives pg_atomic_exchange_u32_impl() an extra argument. This issue has been present since the introduction of the atomics API in commit b64d92f1a5.

pgsql: Fix fallback implementation for pg_atomic_test_set_flag().

2023-11-15 Thread Nathan Bossart
Fix fallback implementation for pg_atomic_test_set_flag(). The fallback implementation of pg_atomic_test_set_flag() that uses atomic-exchange gives pg_atomic_exchange_u32_impl() an extra argument. This issue has been present since the introduction of the atomics API in commit b64d92f1a5.

pgsql: Fix fallback implementation for pg_atomic_test_set_flag().

2023-11-15 Thread Nathan Bossart
Fix fallback implementation for pg_atomic_test_set_flag(). The fallback implementation of pg_atomic_test_set_flag() that uses atomic-exchange gives pg_atomic_exchange_u32_impl() an extra argument. This issue has been present since the introduction of the atomics API in commit b64d92f1a5.

pgsql: Fix fallback implementation for pg_atomic_test_set_flag().

2023-11-15 Thread Nathan Bossart
Fix fallback implementation for pg_atomic_test_set_flag(). The fallback implementation of pg_atomic_test_set_flag() that uses atomic-exchange gives pg_atomic_exchange_u32_impl() an extra argument. This issue has been present since the introduction of the atomics API in commit b64d92f1a5.

pgsql: Fix fallback implementation for pg_atomic_test_set_flag().

2023-11-15 Thread Nathan Bossart
Fix fallback implementation for pg_atomic_test_set_flag(). The fallback implementation of pg_atomic_test_set_flag() that uses atomic-exchange gives pg_atomic_exchange_u32_impl() an extra argument. This issue has been present since the introduction of the atomics API in commit b64d92f1a5.

pgsql: Fix fallback implementation for pg_atomic_test_set_flag().

2023-11-15 Thread Nathan Bossart
Fix fallback implementation for pg_atomic_test_set_flag(). The fallback implementation of pg_atomic_test_set_flag() that uses atomic-exchange gives pg_atomic_exchange_u32_impl() an extra argument. This issue has been present since the introduction of the atomics API in commit b64d92f1a5.

pgsql: Retire MemoryContextResetAndDeleteChildren() macro.

2023-11-15 Thread Nathan Bossart
Retire MemoryContextResetAndDeleteChildren() macro. As of commit eaa5808e8e, MemoryContextResetAndDeleteChildren() is just a backwards compatibility macro for MemoryContextReset(). Now that some time has passed, this macro seems more likely to create confusion. This commit removes the macro and

pgsql: Remove dead code in pg_ctl.c.

2023-10-25 Thread Nathan Bossart
Remove dead code in pg_ctl.c. Missed in 39969e2a1e. Author: David Steele Discussion: https://postgr.es/m/0c742f0c-d663-419d-b5a7-4fe867f5566c%40pgmasters.net Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/fdeb6e6a74f26e7b4504d358ffc751a6d74c08ab Modified Files

pgsql: windows: msvc: Define STDIN/OUT/ERR_FILENO.

2023-10-17 Thread Nathan Bossart
windows: msvc: Define STDIN/OUT/ERR_FILENO. This commit (c290e79cf0) was originally back-patched to v15. Commit 97550c0711 added a new use of STDERR_FILENO, and it was back-patched all the way to v11, thus breaking MSVC builds for v11 through v14. Since STDERR_FILENO is now needed on older

pgsql: windows: msvc: Define STDIN/OUT/ERR_FILENO.

2023-10-17 Thread Nathan Bossart
windows: msvc: Define STDIN/OUT/ERR_FILENO. This commit (c290e79cf0) was originally back-patched to v15. Commit 97550c0711 added a new use of STDERR_FILENO, and it was back-patched all the way to v11, thus breaking MSVC builds for v11 through v14. Since STDERR_FILENO is now needed on older

pgsql: windows: msvc: Define STDIN/OUT/ERR_FILENO.

2023-10-17 Thread Nathan Bossart
windows: msvc: Define STDIN/OUT/ERR_FILENO. This commit (c290e79cf0) was originally back-patched to v15. Commit 97550c0711 added a new use of STDERR_FILENO, and it was back-patched all the way to v11, thus breaking MSVC builds for v11 through v14. Since STDERR_FILENO is now needed on older

pgsql: windows: msvc: Define STDIN/OUT/ERR_FILENO.

2023-10-17 Thread Nathan Bossart
windows: msvc: Define STDIN/OUT/ERR_FILENO. This commit (c290e79cf0) was originally back-patched to v15. Commit 97550c0711 added a new use of STDERR_FILENO, and it was back-patched all the way to v11, thus breaking MSVC builds for v11 through v14. Since STDERR_FILENO is now needed on older

pgsql: Avoid calling proc_exit() in processes forked by system().

2023-10-17 Thread Nathan Bossart
Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process

pgsql: Avoid calling proc_exit() in processes forked by system().

2023-10-17 Thread Nathan Bossart
Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process

pgsql: Avoid calling proc_exit() in processes forked by system().

2023-10-17 Thread Nathan Bossart
Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process

pgsql: Avoid calling proc_exit() in processes forked by system().

2023-10-17 Thread Nathan Bossart
Avoid calling proc_exit() in processes forked by system(). The SIGTERM handler for the startup process immediately calls proc_exit() for the duration of the restore_command, i.e., a call to system(). This system() call forks a new process to execute the shell command, and this child process

  1   2   >