pgsql: Replace known_assigned_xids_lck with memory barriers.

2023-09-05 Thread Nathan Bossart
Replace known_assigned_xids_lck with memory barriers. This lock was introduced before memory barrier support was added, and it is only used to guarantee proper memory ordering when KnownAssignedXidsAdd() appends to the array without a lock. Now that such memory barrier support exists, we can

pgsql: Move PG_TEMP_FILE* macros to file_utils.h.

2023-09-05 Thread Nathan Bossart
Move PG_TEMP_FILE* macros to file_utils.h. Presently, frontend code that needs to use these macros must either include storage/fd.h, which declares several frontend-unsafe functions, or duplicate the macros. This commit moves these macros to common/file_utils.h, which is safe for both frontend

pgsql: Allow using syncfs() in frontend utilities.

2023-09-06 Thread Nathan Bossart
Allow using syncfs() in frontend utilities. This commit allows specifying a --sync-method in several frontend utilities that must synchronize many files to disk (initdb, pg_basebackup, pg_checksums, pg_dump, pg_rewind, and pg_upgrade). On Linux, users can specify "syncfs" to synchronize the

pgsql: Make enum for sync methods available to frontend code.

2023-09-06 Thread Nathan Bossart
Make enum for sync methods available to frontend code. This commit renames RecoveryInitSyncMethod to DataDirSyncMethod and moves it to common/file_utils.h. This is preparatory work for a follow-up commit that will allow specifying the synchronization method in frontend utilities such as

pgsql: Add support for syncfs() in frontend support functions.

2023-09-06 Thread Nathan Bossart
Add support for syncfs() in frontend support functions. This commit adds support for using syncfs() in fsync_pgdata() and fsync_dir_recurse() (which have been renamed to sync_pgdata() and sync_dir_recurse()). Like recovery_init_sync_method, sync_pgdata() calls syncfs() for the data directory,

pgsql: pg_upgrade: Bump MESSAGE_WIDTH.

2023-08-24 Thread Nathan Bossart
pg_upgrade: Bump MESSAGE_WIDTH. Commit 7b378237aa added a status message to pg_upgrade that is 60 characters wide. Since the MESSAGE_WIDTH macro is currently set to 60, there is no space between this new status message and the "ok" or "failed" indicator appended when the step completes. To fix

pgsql: pg_upgrade: Bump MESSAGE_WIDTH.

2023-08-24 Thread Nathan Bossart
pg_upgrade: Bump MESSAGE_WIDTH. Commit 7b378237aa added a status message to pg_upgrade that is 60 characters wide. Since the MESSAGE_WIDTH macro is currently set to 60, there is no space between this new status message and the "ok" or "failed" indicator appended when the step completes. To fix

pgsql: Rename some support functions for pgstat* views.

2023-08-30 Thread Nathan Bossart
Rename some support functions for pgstat* views. Presently, pgstat_fetch_stat_beentry() accepts a session's backend ID as its argument, and pgstat_fetch_stat_local_beentry() accepts a 1-based index in an internal array as its argument. The former is typically used wherever a user must provide a

pgsql: Use actual backend IDs in pg_stat_get_backend_subxact().

2023-08-30 Thread Nathan Bossart
Use actual backend IDs in pg_stat_get_backend_subxact(). Unlike the other pg_stat_get_backend* functions, pg_stat_get_backend_subxact() looks up the backend entry by using its integer argument as a 1-based index in an internal array. The other functions look for the entry with the matching

pgsql: Use actual backend IDs in pg_stat_get_backend_subxact().

2023-08-30 Thread Nathan Bossart
Use actual backend IDs in pg_stat_get_backend_subxact(). Unlike the other pg_stat_get_backend* functions, pg_stat_get_backend_subxact() looks up the backend entry by using its integer argument as a 1-based index in an internal array. The other functions look for the entry with the matching

pgsql: Rename some support functions for pgstat* views.

2023-08-30 Thread Nathan Bossart
Rename some support functions for pgstat* views. Presently, pgstat_fetch_stat_beentry() accepts a session's backend ID as its argument, and pgstat_fetch_stat_local_beentry() accepts a 1-based index in an internal array as its argument. The former is typically used wherever a user must provide a

pgsql: Fix misuse of PqMsg_Close.

2023-08-29 Thread Nathan Bossart
Fix misuse of PqMsg_Close. EndCommand() and EndReplicationCommand() should use PqMsg_CommandComplete instead. Oversight in commit f4b54e1ed9. Reported-by: Pavel Stehule, Tatsuo Ishii Author: Pavel Stehule Reviewed-by: Aleksander Alekseev, Michael Paquier Discussion:

pgsql: Move extra code out of the Pre/PostRestoreCommand() section.

2023-10-16 Thread Nathan Bossart
Move extra code out of the Pre/PostRestoreCommand() section. If SIGTERM is received within this section, the startup process will immediately proc_exit() in the signal handler, so it is inadvisable to include any more code than is required there (as such code is unlikely to be compatible with

pgsql: Move extra code out of the Pre/PostRestoreCommand() section.

2023-10-16 Thread Nathan Bossart
Move extra code out of the Pre/PostRestoreCommand() section. If SIGTERM is received within this section, the startup process will immediately proc_exit() in the signal handler, so it is inadvisable to include any more code than is required there (as such code is unlikely to be compatible with

pgsql: Move extra code out of the Pre/PostRestoreCommand() section.

2023-10-16 Thread Nathan Bossart
Move extra code out of the Pre/PostRestoreCommand() section. If SIGTERM is received within this section, the startup process will immediately proc_exit() in the signal handler, so it is inadvisable to include any more code than is required there (as such code is unlikely to be compatible with

pgsql: Improve the naming in wal_sync_method code.

2023-10-13 Thread Nathan Bossart
Improve the naming in wal_sync_method code. * sync_method is renamed to wal_sync_method. * sync_method_options[] is renamed to wal_sync_method_options[]. * assign_xlog_sync_method() is renamed to assign_wal_sync_method(). * The names of the available synchronization methods are now prefixed

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

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: 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: Remove open-coded binary heap in pg_dump_sort.c.

2023-09-19 Thread Nathan Bossart
Remove open-coded binary heap in pg_dump_sort.c. Thanks to commit 5af0263afd, binaryheap is available to frontend code. This commit replaces the open-coded heap implementation in pg_dump_sort.c with a binaryheap, saving a few lines of code. Reviewed-by: Tom Lane Discussion:

pgsql: Convert pg_restore's ready_list to a priority queue.

2023-09-19 Thread Nathan Bossart
Convert pg_restore's ready_list to a priority queue. Presently, parallel restores spend a lot of time sorting this list so that we pick the largest items first. With many tables, this sorting can become a significant bottleneck. There are a couple of reports from the field about this, and it is

pgsql: Make binaryheap available to frontend code.

2023-09-18 Thread Nathan Bossart
Make binaryheap available to frontend code. There are a couple of places in frontend code that could make use of this simple binary heap implementation. This commit makes binaryheap usable in frontend code, much like commit 26aaf97b68 did for StringInfo. Like StringInfo, the header file is left

pgsql: Fix MSVC build for changes to binaryheap.

2023-09-18 Thread Nathan Bossart
Fix MSVC build for changes to binaryheap. After 5af0263afd, binaryheap.c needs to be listed in Mkvcbuild.pm. Per buildfarm. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/83223f5f714482dd44883c68ecac2ae8c2d838e8 Modified Files --

pgsql: Add worker type to pg_stat_subscription.

2023-09-25 Thread Nathan Bossart
Add worker type to pg_stat_subscription. Thanks to commit 2a8b40e368, the logical replication worker type is easily determined. The worker type could already be deduced via other columns such as leader_pid and relid, but that is unnecessary complexity for users. Bumps catversion. Author: Peter

pgsql: Document that --sync-method takes an argument.

2023-10-04 Thread Nathan Bossart
Document that --sync-method takes an argument. This was missed in commit 8c16ad3b43. Reported-by: Robert Haas Reviewed-by: Daniel Gustafsson, Robert Haas, Alvaro Herrera, Tom Lane Discussion: https://postgr.es/m/CA%2BTgmoZi7pcx-ec3oJLWSr2R%3DDn2Zeiyx3EXQKc_1TTvA6Eepg%40mail.gmail.com Branch

pgsql: Add function for removing arbitrary nodes in binaryheap.

2023-09-18 Thread Nathan Bossart
Add function for removing arbitrary nodes in binaryheap. This commit introduces binaryheap_remove_node(), which can be used to remove any node from a binary heap. The implementation is straightforward. The target node is replaced with the last node in the heap, and then we sift as needed to

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: Add a few recent commits to .git-blame-ignore-revs.

2023-08-17 Thread Nathan Bossart
Add a few recent commits to .git-blame-ignore-revs. Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/20230815203109.GA2596919%40nathanxps13 Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/0df7d1da40e3e639739eacccf3bca99a81803da7 Modified Files

pgsql: Introduce macros for protocol characters.

2023-08-22 Thread Nathan Bossart
Introduce macros for protocol characters. This commit introduces descriptively-named macros for the identifiers used in wire protocol messages. These new macros are placed in a new header file so that they can be easily used by third-party code. Author: Dave Cramer Reviewed-by: Alvaro Herrera,

pgsql: Add to_bin() and to_oct().

2023-08-23 Thread Nathan Bossart
Add to_bin() and to_oct(). This commit introduces functions for converting numbers to their equivalent binary and octal representations. Also, the base conversion code for these functions and to_hex() has been moved to a common helper function. Co-authored-by: Eric Radman Reviewed-by: Ian

pgsql: Bump catversion for to_bin() and to_oct().

2023-08-23 Thread Nathan Bossart
Bump catversion for to_bin() and to_oct(). Missed in 260a1f18da. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/d7f249020a11a87cedad04fb071f3287321d5f20 Modified Files -- src/include/catalog/catversion.h | 2 +- 1 file changed, 1 insertion(+), 1

pgsql: Prevent underflow in KeepLogSeg().

2023-04-27 Thread Nathan Bossart
Prevent underflow in KeepLogSeg(). The call to XLogGetReplicationSlotMinimumLSN() might return a greater LSN than the one given to the function. Subsequent segment number calculations might then underflow, which could result in unexpected behavior when removing or recyling WAL files. This was

pgsql: Prevent underflow in KeepLogSeg().

2023-04-27 Thread Nathan Bossart
Prevent underflow in KeepLogSeg(). The call to XLogGetReplicationSlotMinimumLSN() might return a greater LSN than the one given to the function. Subsequent segment number calculations might then underflow, which could result in unexpected behavior when removing or recyling WAL files. This was

pgsql: Prevent underflow in KeepLogSeg().

2023-04-27 Thread Nathan Bossart
Prevent underflow in KeepLogSeg(). The call to XLogGetReplicationSlotMinimumLSN() might return a greater LSN than the one given to the function. Subsequent segment number calculations might then underflow, which could result in unexpected behavior when removing or recyling WAL files. This was

pgsql: Prevent underflow in KeepLogSeg().

2023-04-27 Thread Nathan Bossart
Prevent underflow in KeepLogSeg(). The call to XLogGetReplicationSlotMinimumLSN() might return a greater LSN than the one given to the function. Subsequent segment number calculations might then underflow, which could result in unexpected behavior when removing or recyling WAL files. This was

pgsql: Revert MAINTAIN privilege and pg_maintain predefined role.

2023-07-07 Thread Nathan Bossart
Revert MAINTAIN privilege and pg_maintain predefined role. This reverts the following commits: 4dbdb82513, c2122aae63, 5b1a879943, 9e1e9d6560, ff9618e82a, 60684dd834, 4441fc704d, and b5d6382496. A role with the MAINTAIN privilege may be able to use search_path tricks to escalate privileges to

pgsql: Revert MAINTAIN privilege and pg_maintain predefined role.

2023-07-07 Thread Nathan Bossart
Revert MAINTAIN privilege and pg_maintain predefined role. This reverts the following commits: 4dbdb82513, c2122aae63, 5b1a879943, 9e1e9d6560, ff9618e82a, 60684dd834, 4441fc704d, and b5d6382496. A role with the MAINTAIN privilege may be able to use search_path tricks to escalate privileges to

pgsql: Rename session_auth_is_superuser to current_role_is_superuser.

2023-07-12 Thread Nathan Bossart
Rename session_auth_is_superuser to current_role_is_superuser. This variable might've been accurately named when it was added in ea886339b8, but the name hasn't been accurate since at least the introduction of SET ROLE in e5d6b91220. The corresponding documentation was fixed in eedb068c0a. This

pgsql: Teach in-tree getopt_long() to move non-options to the end of ar

2023-07-12 Thread Nathan Bossart
Teach in-tree getopt_long() to move non-options to the end of argv. Unlike the other implementations of getopt_long() I could find, the in-tree implementation does not reorder non-options to the end of argv. Instead, it returns -1 as soon as the first non-option is found, even if there are other

pgsql: Fix privilege check for SET SESSION AUTHORIZATION.

2023-07-13 Thread Nathan Bossart
Fix privilege check for SET SESSION AUTHORIZATION. Presently, the privilege check for SET SESSION AUTHORIZATION checks whether the original authenticated role was a superuser at connection start time. Even if the role loses the superuser attribute, its existing sessions are permitted to change

pgsql: Move privilege check for SET SESSION AUTHORIZATION.

2023-07-13 Thread Nathan Bossart
Move privilege check for SET SESSION AUTHORIZATION. Presently, the privilege check for SET SESSION AUTHORIZATION is performed in session_authorization's assign_hook. A relevant comment states, "It's OK because the check does not require catalog access and can't fail during an end-of-transaction

pgsql: Remove db_user_namespace.

2023-07-17 Thread Nathan Bossart
Remove db_user_namespace. This feature was intended to be a temporary measure to support per-database user names. A better one hasn't materialized in the ~21 years since it was added, and nobody claims to be using it, so let's just remove it. Reviewed-by: Michael Paquier, Magnus Hagander

pgsql: Simplify option handling in pg_ctl.

2023-07-14 Thread Nathan Bossart
Simplify option handling in pg_ctl. Now that the in-tree getopt_long() moves non-options to the end of argv (see commit 411b720343), we can remove pg_ctl's workaround for getopt_long() implementations that don't reorder argv. Reviewed-by: Michael Paquier Discussion:

pgsql: Doc: move unparenthesized syntaxes for a few commands.

2023-07-19 Thread Nathan Bossart
Doc: move unparenthesized syntaxes for a few commands. Move documentation of the unparenthesized syntaxes for VACUUM, ANALYZE, EXPLAIN, and CLUSTER to the "Compatibility" section of their documentation to improve readability of the preferred, parenthesized syntaxes. Author: Melanie Plageman

pgsql: Support parenthesized syntax for CLUSTER without a table name.

2023-07-19 Thread Nathan Bossart
Support parenthesized syntax for CLUSTER without a table name. b5913f6120 added a parenthesized syntax for CLUSTER, but it requires specifying a table name. This is unlike commands such as VACUUM and ANALYZE, which do not require specifying a table in the parenthesized syntax. This change

pgsql: Rearrange CLUSTER rules in gram.y.

2023-07-19 Thread Nathan Bossart
Rearrange CLUSTER rules in gram.y. This change moves the unparenthesized syntax for CLUSTER to the end of the ClusterStmt rules in preparation for a follow-up commit that will move this syntax to the "Compatibility" section of the CLUSTER documentation. The documentation for the CLUSTER syntaxes

pgsql: Don't truncate database and user names in startup packets.

2023-07-03 Thread Nathan Bossart
Don't truncate database and user names in startup packets. Unlike commands such as CREATE DATABASE, ProcessStartupPacket() does not perform multibyte-aware truncation of overlength names. This means that connection attempts might fail even if the user provides the same overlength names that were

pgsql: Increase size of bgw_library_name.

2023-07-03 Thread Nathan Bossart
Increase size of bgw_library_name. This commit increases the size of the bgw_library_name member of the BackgroundWorker struct from BGW_MAXLEN (96) bytes to MAXPGPATH (default of 1024) bytes so that it can store longer file names (e.g., absolute paths). Author: Yurii Rashkovskii Reviewed-by:

pgsql: Fix missing word in nbtree/README.

2023-06-08 Thread Nathan Bossart
Fix missing word in nbtree/README. Reported-by: Daniel Westermann Author: Gurjeet Singh Reviewed-by: Richard Guo Discussion: https://postgr.es/m/ZR0P278MB0427F0E0CE4ED140F52D1923D250A%40ZR0P278MB0427.CHEP278.PROD.OUTLOOK.COM Branch -- master Details ---

pgsql: Fix remaining references to gss_accept_deleg.

2023-05-20 Thread Nathan Bossart
Fix remaining references to gss_accept_deleg. These were missed in 9c0a0e2ed9. Discussion: https://postgr.es/m/20230521031757.GA3835667%40nathanxps13 Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/f4001a553770b3114dd11846c6789ad6c34ef111 Modified Files

pgsql: Rename some createuser options.

2023-05-21 Thread Nathan Bossart
Rename some createuser options. This change renames --admin to --with-admin, --role to --member-of, and --member to --with-member. Many people found the previous names to be confusing. The --admin and --member options are new in v16, but --role has been there for a while, so that one has been

pgsql: Document deprecated createuser option.

2023-05-23 Thread Nathan Bossart
Document deprecated createuser option. 2dcd1578c4 left the --role option undocumented, which is inconsistent with other deprecated options such as pg_dump's --blobs and --no-blobs. This change adds --role back to createuser's documentation and usage output and marks it as deprecated.

pgsql: Harmonize password reuse in vacuumdb, clusterdb, and reindexdb.

2023-07-28 Thread Nathan Bossart
Harmonize password reuse in vacuumdb, clusterdb, and reindexdb. Commits 83dec5a712 and ff402ae11b taught vacuumdb to reuse passwords instead of prompting repeatedly. However, the docs still warn about repeated prompts, and this improvement was not applied to clusterdb and reindexdb. This commit

pgsql: Adjust extra lines generated by psql to be valid SQL comments.

2023-07-26 Thread Nathan Bossart
Adjust extra lines generated by psql to be valid SQL comments. psql's --echo-hidden, --log-file, and --single-step options generate extra lines to clearly separate queries from other output. Presently, these extra lines are not valid SQL comments, which makes them a hazard for anyone trying to

pgsql: Move bool parameter for vacuum_rel() to option bits.

2023-06-20 Thread Nathan Bossart
Move bool parameter for vacuum_rel() to option bits. ff9618e82a introduced the skip_privs parameter, which is used to skip privilege checks when recursing to a relation's TOAST table. This parameter should have been added as a flag bit in VacuumParams->options instead. Suggested-by: Michael

pgsql: Fix cache lookup hazards introduced by ff9618e82a.

2023-06-22 Thread Nathan Bossart
Fix cache lookup hazards introduced by ff9618e82a. ff9618e82a introduced has_partition_ancestor_privs(), which is used to check whether a user has MAINTAIN on any partition ancestors. This involves syscache lookups, and presently this function does not take any relation locks, so it is likely

pgsql: Improve privilege documentation for maintenance commands.

2023-06-22 Thread Nathan Bossart
Improve privilege documentation for maintenance commands. The documentation of the required privileges for maintenance commands (i.e., VACUUM, ANALYZE, CLUSTER, LOCK TABLE, REFRESH MATERIALIZED VIEW, and REINDEX) is redundant, inaccurate, and difficult to read. This commit fixes and simplifies

pgsql: Fix psql \?'s entries for \dp and \z.

2023-06-28 Thread Nathan Bossart
Fix psql \?'s entries for \dp and \z. d913928c9c added support for the "S" modifier to psql's \dp and \z meta-commands, but it missed updating the corresponding entries in \?'s output. Author: Noriyoshi Shinoda Discussion:

pgsql: Improve error message for pg_create_subscription.

2023-05-12 Thread Nathan Bossart
Improve error message for pg_create_subscription. c3afe8cf5a updated this error message, but it didn't use the new style established in de4d456b40. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/20230512203721.GA2644063%40nathanxps13.home Branch -- master Details ---

pgsql: Move return statements out of PG_TRY blocks.

2023-05-04 Thread Nathan Bossart
Move return statements out of PG_TRY blocks. If we exit a PG_TRY block early via "continue", "break", "goto", or "return", we'll skip unwinding its exception stack. This change moves a couple of such "return" statements in PL/Python out of PG_TRY blocks. This was introduced in d0aa965c0a and

pgsql: Move return statements out of PG_TRY blocks.

2023-05-04 Thread Nathan Bossart
Move return statements out of PG_TRY blocks. If we exit a PG_TRY block early via "continue", "break", "goto", or "return", we'll skip unwinding its exception stack. This change moves a couple of such "return" statements in PL/Python out of PG_TRY blocks. This was introduced in d0aa965c0a and

pgsql: Move return statements out of PG_TRY blocks.

2023-05-04 Thread Nathan Bossart
Move return statements out of PG_TRY blocks. If we exit a PG_TRY block early via "continue", "break", "goto", or "return", we'll skip unwinding its exception stack. This change moves a couple of such "return" statements in PL/Python out of PG_TRY blocks. This was introduced in d0aa965c0a and

pgsql: Move return statements out of PG_TRY blocks.

2023-05-04 Thread Nathan Bossart
Move return statements out of PG_TRY blocks. If we exit a PG_TRY block early via "continue", "break", "goto", or "return", we'll skip unwinding its exception stack. This change moves a couple of such "return" statements in PL/Python out of PG_TRY blocks. This was introduced in d0aa965c0a and

pgsql: Move return statements out of PG_TRY blocks.

2023-05-04 Thread Nathan Bossart
Move return statements out of PG_TRY blocks. If we exit a PG_TRY block early via "continue", "break", "goto", or "return", we'll skip unwinding its exception stack. This change moves a couple of such "return" statements in PL/Python out of PG_TRY blocks. This was introduced in d0aa965c0a and

pgsql: Move return statements out of PG_TRY blocks.

2023-05-04 Thread Nathan Bossart
Move return statements out of PG_TRY blocks. If we exit a PG_TRY block early via "continue", "break", "goto", or "return", we'll skip unwinding its exception stack. This change moves a couple of such "return" statements in PL/Python out of PG_TRY blocks. This was introduced in d0aa965c0a and

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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.

  1   2   >