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: Improve eviction algorithm in ReorderBuffer using max-heap for m

2024-04-02 Thread Masahiko Sawada
Improve eviction algorithm in ReorderBuffer using max-heap for many subtransactions. Previously, when selecting the transaction to evict during logical decoding, we check all transactions to find the largest transaction. This could lead to a significant replication lag especially in the case

pgsql: Don't adjust ressortgroupref in generate_setop_child_grouplist()

2024-04-02 Thread David Rowley
Don't adjust ressortgroupref in generate_setop_child_grouplist() This is already done inside assignSortGroupRef(), therefore is redundant. Oversight from 66c0185a3. Reported-by: Tom Lane Discussion: https://postgr.es/m/3703023.1711654...@sss.pgh.pa.us Branch -- master Details ---

pgsql: Add functions to binaryheap for efficient key removal and update

2024-04-02 Thread Masahiko Sawada
Add functions to binaryheap for efficient key removal and update. Previously, binaryheap didn't support updating a key and removing a node in an efficient way. For example, in order to remove a node from the binaryheap, the caller had to pass the node's position within the array that the

pgsql: Make binaryheap enlargeable.

2024-04-02 Thread Masahiko Sawada
Make binaryheap enlargeable. The node array space of the binaryheap is doubled when there is no available space. Reviewed-by: Vignesh C, Peter Smith, Hayato Kuroda, Ajin Cherian, Tomas Vondra, Shubham Khanna Discussion:

pgsql: Move WaitLSNShmemInit() to CreateOrAttachShmemStructs()

2024-04-02 Thread Alexander Korotkov
Move WaitLSNShmemInit() to CreateOrAttachShmemStructs() Thanks to Andres Freund, Thomas Munrom and David Rowley for investigating this issue. Discussion: https://postgr.es/m/CAPpHfdvap5mMLikt8CUjA0osAvCJHT0qnYeR3f84EJ_Kvse0mg%40mail.gmail.com Branch -- master Details ---

Re: pgsql: Implement pg_wal_replay_wait() stored procedure

2024-04-02 Thread Thomas Munro
On Wed, Apr 3, 2024 at 9:42 AM Alexander Korotkov wrote: > On Tue, Apr 2, 2024 at 10:58 PM Alexander Korotkov > wrote: > > Implement pg_wal_replay_wait() stored procedure > > I'm trying to figure out if this failure could be related to this commit... >

Re: pgsql: Implement pg_wal_replay_wait() stored procedure

2024-04-02 Thread David Rowley
On Wed, 3 Apr 2024 at 09:42, Alexander Korotkov wrote: > I'm trying to figure out if this failure could be related to this commit... > https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=culicidae=2024-04-02%2020%3A24%3A55 Yeah, I think it is. The problem is that in WaitLSNSetLatches()

pgsql: Don't zero tuple_fraction when planning UNIONs with ORDER BYs

2024-04-02 Thread David Rowley
Don't zero tuple_fraction when planning UNIONs with ORDER BYs Since 66c0185a3, the planner is able to use Merge Append -> Unique to implement UNION queries and each subquery is prompted to produce Paths correctly sorted by the UNION's targetlist. Here we remove some now redundant code which was

Re: pgsql: Allow SIGINT to cancel psql database reconnections.

2024-04-02 Thread Alexander Korotkov
On Tue, Apr 2, 2024 at 5:30 PM Robert Haas wrote: > Allow SIGINT to cancel psql database reconnections. > > After installing the SIGINT handler in psql, SIGINT can no longer cancel > database reconnections. For instance, if the user starts a reconnection > and then needs to do some form of

Re: pgsql: Implement pg_wal_replay_wait() stored procedure

2024-04-02 Thread Alexander Korotkov
On Tue, Apr 2, 2024 at 10:58 PM Alexander Korotkov wrote: > Implement pg_wal_replay_wait() stored procedure I'm trying to figure out if this failure could be related to this commit... https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=culicidae=2024-04-02%2020%3A24%3A55 -- Regards,

pgsql: Implement pg_wal_replay_wait() stored procedure

2024-04-02 Thread Alexander Korotkov
Implement pg_wal_replay_wait() stored procedure pg_wal_replay_wait() is to be used on standby and specifies waiting for the specific WAL location to be replayed before starting the transaction. This option is useful when the user makes some data changes on primary and needs a guarantee to see

pgsql: Avoid deadlock during orphan temp table removal.

2024-04-02 Thread Tom Lane
Avoid deadlock during orphan temp table removal. If temp tables have dependencies (such as sequences) then it's possible for autovacuum's cleanup of orphan temp tables to deadlock against an incoming backend that's trying to clean out the temp namespace for its own use. That can happen because

pgsql: Avoid deadlock during orphan temp table removal.

2024-04-02 Thread Tom Lane
Avoid deadlock during orphan temp table removal. If temp tables have dependencies (such as sequences) then it's possible for autovacuum's cleanup of orphan temp tables to deadlock against an incoming backend that's trying to clean out the temp namespace for its own use. That can happen because

pgsql: Avoid deadlock during orphan temp table removal.

2024-04-02 Thread Tom Lane
Avoid deadlock during orphan temp table removal. If temp tables have dependencies (such as sequences) then it's possible for autovacuum's cleanup of orphan temp tables to deadlock against an incoming backend that's trying to clean out the temp namespace for its own use. That can happen because

pgsql: Avoid deadlock during orphan temp table removal.

2024-04-02 Thread Tom Lane
Avoid deadlock during orphan temp table removal. If temp tables have dependencies (such as sequences) then it's possible for autovacuum's cleanup of orphan temp tables to deadlock against an incoming backend that's trying to clean out the temp namespace for its own use. That can happen because

pgsql: Avoid deadlock during orphan temp table removal.

2024-04-02 Thread Tom Lane
Avoid deadlock during orphan temp table removal. If temp tables have dependencies (such as sequences) then it's possible for autovacuum's cleanup of orphan temp tables to deadlock against an incoming backend that's trying to clean out the temp namespace for its own use. That can happen because

pgsql: Avoid deadlock during orphan temp table removal.

2024-04-02 Thread Tom Lane
Avoid deadlock during orphan temp table removal. If temp tables have dependencies (such as sequences) then it's possible for autovacuum's cleanup of orphan temp tables to deadlock against an incoming backend that's trying to clean out the temp namespace for its own use. That can happen because

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: Unwind #if spaghetti in hmac_openssl.c a bit.

2024-04-02 Thread Tom Lane
Unwind #if spaghetti in hmac_openssl.c a bit. Make this code a little less confusing by defining a separate macro that controls whether we'll use ResourceOwner facilities to track the existence of a pg_hmac_ctx context. The proximate reason to touch this is that since b8bff07da, we got "unused

pgsql: Allow SIGINT to cancel psql database reconnections.

2024-04-02 Thread Robert Haas
Allow SIGINT to cancel psql database reconnections. After installing the SIGINT handler in psql, SIGINT can no longer cancel database reconnections. For instance, if the user starts a reconnection and then needs to do some form of interaction (ie psql is polling), there is no way to cancel the

pgsql: Expose PQsocketPoll via libpq

2024-04-02 Thread Robert Haas
Expose PQsocketPoll via libpq This is useful when connecting to a database asynchronously via PQconnectStart(), since it handles deciding between poll() and select(), and some of the required boilerplate. Tristan Partin, reviewed by Gurjeet Singh, Heikki Linnakangas, Jelte Fennema-Nio, and me.

pgsql: Provide vectored variant of ReadBuffer().

2024-04-02 Thread Thomas Munro
Provide vectored variant of ReadBuffer(). Break ReadBuffer() up into two steps. StartReadBuffers() and WaitReadBuffers() give us two main advantages: 1. Multiple consecutive blocks can be read with one system call. 2. Advice (hints of future reads) can optionally be issued to the kernel ahead

pgsql: Provide API for streaming relation data.

2024-04-02 Thread Thomas Munro
Provide API for streaming relation data. Introduce an abstraction allowing relation data to be accessed as a stream of buffers, with an implementation that is more efficient than the equivalent sequence of ReadBuffer() calls. Client code supplies a callback that can say which block number it

pgsql: Use streaming I/O in pg_prewarm.

2024-04-02 Thread Thomas Munro
Use streaming I/O in pg_prewarm. Instead of calling ReadBuffer() repeatedly, use the new streaming interface. This commit provides a very simple example of such a transformation. Discussion: https://postgr.es/m/CA+hUKGJkOiOCa+mag4BF+zHo7qo=o9CFheB8=g6ut5tum2g...@mail.gmail.com Branch --

pgsql: Don't use the pg_am system catalog in new test

2024-04-02 Thread Alvaro Herrera
Don't use the pg_am system catalog in new test This causes deadlocks because it's a highly trafficked catalog. Use a regular table created by the same test instead. Discussion: https://postgr.es/m/f3e61e27-19d0-5e40-3eb2-53282fa05...@gmail.com Branch -- master Details ---

pgsql: Revert "Custom reloptions for table AM"

2024-04-02 Thread Alexander Korotkov
Revert "Custom reloptions for table AM" This reverts commit c95c25f9af4bc77f2f66a587735c50da08c12b37 due to multiple design issues spotted after commit. Reported-by: Jeff Davis Discussion: https://postgr.es/m/11550b536211d5748bb2865ed6cb3502ff073bf7.camel%40j-davis.com Branch -- master