{"id":359431,"date":"2024-05-21T00:32:28","date_gmt":"2024-05-21T00:32:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=359431"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T00:32:28","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=359431","title":{"rendered":"<span>PostgreSQL 17: Part 2 or Commitfest 2023-09<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/8o\/dq\/l0\/8odql0uarhapv8j7k2vwb9fiuxi.png\" data-src=\"https:\/\/habrastorage.org\/webt\/8o\/dq\/l0\/8odql0uarhapv8j7k2vwb9fiuxi.png\"\/><\/p>\n<p>  <\/p>\n<p>We continue to follow the news of the PostgreSQL 17 development. Let&#8217;s find out what the September commitfest brings to the table.<\/p>\n<p>  <\/p>\n<p>If you missed our July commitfest review, you can check it out here: <a href=\"https:\/\/postgrespro.com\/blog\/pgsql\/5970285\">2023-07<\/a>.<\/p>\n<p>  <\/p>\n<p><a href=\"#f691f5b8\">Removed the parameter <em>old_snapshot_threshold<\/em><\/a><br \/>  <a href=\"#7750fefd\">New parameter <em>event_triggers<\/em><\/a><br \/>  <a href=\"#260a1f18\">New functions to_bin and to_oct<\/a><br \/>  <a href=\"#1e68e43d\">New system view pg_wait_events<\/a><br \/>  <a href=\"#5a3423ad\">EXPLAIN: a JIT compilation time counter for tuple deforming<\/a><br \/>  <a href=\"#3900a02c\">Planner: better estimate of the initial cost of the WindowAgg node<\/a><br \/>  <a href=\"#b0e96f31\">pg_constraint: NOT NULL constraints<\/a><br \/>  <a href=\"#11c34b34\">Normalization of CALL, DEALLOCATE and two-phase commit control commands<\/a><br \/>  <a href=\"#59f47fb9\">unaccent: the target rule expressions now support values in quotation marks<\/a><br \/>  <a href=\"#f6d4c9cf\">COPY FROM: FORCE_NOT_NULL * and FORCE_NULL *<\/a><br \/>  <a href=\"#e48b19c5\">Audit of connections without authentication<\/a><br \/>  <a href=\"#13aeaf07\">pg_stat_subscription: new column worker_type<\/a><br \/>  <a href=\"#f593c551\">The behaviour of pg_promote in case of unsuccessful switchover to a replica<\/a><br \/>  <a href=\"#8c16ad3b\">Choosing the disk synchronization method in server utilities<\/a><br \/>  <a href=\"#c103d073\">pg_restore: optimization of parallel recovery of a large number of tables<\/a><br \/>  <a href=\"#cca97ce6\">pg_basebackup and pg_receivewal with the parameter dbname<\/a><br \/>  <a href=\"#b575a26c\">Parameter names for a number of built-in functions<\/a><br \/>  <a href=\"#f347ec76\">psql: \\watch min_rows<\/a><\/p>\n<p><a name=\"habracut\"><\/a><br \/>  <a name=\"f691f5b8\"><\/a>  <\/p>\n<h2 id=\"removed-the-parameter-old_snapshot_thresholdhttpswwwpostgresqlorgmessage-idflatcacg3dezyv2bevo135flrdvn-zusfvsty6ch1ozqwtezueyh6ciqamailgmailcom\"><a href=\"https:\/\/www.postgresql.org\/message-id\/flat\/CACG%3DezYV%2BEvO135fLRdVn-ZusfVsTY6cH1OZqWtezuEYH6ciQA@mail.gmail.com\">Removed the parameter <em>old_snapshot_threshold<\/em><\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/f691f5b8\">f691f5b8<\/a><\/p>\n<p>  <\/p>\n<p>The parameter <em>old_snapshot_threshold<\/em> first appeared in patch 9.6. The parameter defines the time threshold for a snapshot during which old row versions will not be deleted. After the threshold expires, all visible row versions in the snapshot become vacuumable. When querying the vacuumed row versions, PostgreSQL returns an error that is all too familiar to Oracle users: &#171;Snapshot too old&#187;.<\/p>\n<p>  <\/p>\n<p>As it turns out, there are issues with the parameter&#8217;s implementation, including some performance-related ones. With no clear-cut solution in sight so far, the parameter had to be scrapped.<\/p>\n<p>  <a name=\"7750fefd\"><\/a>  <\/p>\n<h2 id=\"new-parameter-event_triggershttpscommitfestpostgresqlorg444013\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4013\/\">New parameter <em>event_triggers<\/em><\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/7750fefd\">7750fefd<\/a><\/p>\n<p>  <\/p>\n<p>The parameter <em>event_triggers<\/em> enables and disables event triggers.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">\\dconfig+ event_triggers<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">               List of configuration parameters    Parameter    | Value | Type |  Context  | Access privileges ----------------+-------+------+-----------+-------------------  event_triggers | on    | bool | superuser | (1 row)<\/code><\/pre>\n<p>  <\/p>\n<p>It is intended as a trigger debugging tool. Previously, the <a href=\"https:\/\/postgrespro.com\/docs\/postgresql\/16\/sql-createeventtrigger\">CREATE EVENT TRIGGER<\/a> command documentation suggested to run the server in single-user mode if a malfunctioning trigger could not be deleted.<\/p>\n<p>  <a name=\"260a1f18\"><\/a>  <\/p>\n<h2 id=\"new-functions-to_bin-and-to_octhttpscommitfestpostgresqlorg444071\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4071\/\">New functions to_bin and to_oct<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/260a1f18\">260a1f18<\/a><\/p>\n<p>  <\/p>\n<p>The existing decimal to hexadecimal conversion function to_hex gets its binary and octal siblings:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SELECT to_bin(2), to_oct(8), to_hex(16);<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\"> to_bin | to_oct | to_hex --------+--------+--------  10     | 10     | 10 (1 row)<\/code><\/pre>\n<p>  <\/p>\n<p>See also:<br \/>  <a href=\"https:\/\/www.depesz.com\/2023\/09\/01\/waiting-for-postgresql-17-add-to_bin-and-to_oct\/\">Waiting for PostgreSQL 17 \u2013 Add to_bin() and to_oct(). \u2013 select * from depesz;<\/a><\/p>\n<p>  <a name=\"1e68e43d\"><\/a>  <\/p>\n<h2 id=\"new-system-view-pg_wait_eventshttpscommitfestpostgresqlorg444490\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4490\/\">New system view pg_wait_events<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/1e68e43d\">1e68e43d<\/a><\/p>\n<p>  <\/p>\n<p>In the documentation for the <code>pg_stat_activity<\/code> view, the <code>wait_event_type<\/code> and <code>wait_event<\/code> columns are described in a <a href=\"https:\/\/www.postgresql.org\/docs\/devel\/monitoring-stats.html#WAIT-EVENT-TABLE\">table explaining the types of wait events<\/a> and several tables describing each wait event type. You can now access these descriptions by querying the new <a href=\"https:\/\/www.postgresql.org\/docs\/devel\/view-pg-wait-events.html\">pg_wait_events<\/a> system view.<\/p>\n<p>  <\/p>\n<p>This can be useful in monitoring systems to get a description of what current processes are waiting for. What is the checkpoint process doing now?<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SELECT a.pid, a.state, a.wait_event_type, a.wait_event, w.description FROM pg_stat_activity a JOIN pg_wait_events w      ON (a.wait_event_type = w.type AND a.wait_event = w.name) WHERE a.backend_type = 'checkpointer'\\gx<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">-[ RECORD 1 ]---+--------------------------------------------- pid             | 21090 state           | wait_event_type | Activity wait_event      | CheckpointerMain description     | Waiting in main loop of checkpointer process<\/code><\/pre>\n<p>  <a name=\"5a3423ad\"><\/a>  <\/p>\n<h2 id=\"explain-a-jit-compilation-time-counter-for-tuple-deforminghttpscommitfestpostgresqlorg443688\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/3688\/\">EXPLAIN: a JIT compilation time counter for tuple deforming<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/5a3423ad\">5a3423ad<\/a><\/p>\n<p>  <\/p>\n<p>The patch adds specific time spent on JIT compilation for tuple deforming to <code>EXPLAIN ANALYZE<\/code> and <code>pg_stat_statements<\/code> outputs.<\/p>\n<p>  <\/p>\n<p>In the following query, JIT compilation is used to calculate the ?:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">EXPLAIN (analyze, summary off) WITH pi AS (   SELECT random() x, random() y   FROM generate_series(1,10000000) ) SELECT 4*sum(1-floor(x*x+y*y))\/count(*) val FROM pi;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">                                                                  QUERY PLAN                                                                    -----------------------------------------------------------------------------------------------------------------------------------------------  Aggregate  (cost=525000.00..525000.02 rows=1 width=8) (actual time=3934.330..3934.331 rows=1 loops=1)    CTE pi      ->  Function Scan on generate_series  (cost=0.00..150000.00 rows=10000000 width=16) (actual time=725.126..1654.054 rows=10000000 loops=1)    ->  CTE Scan on pi  (cost=0.00..200000.00 rows=10000000 width=16) (actual time=725.129..3429.925 rows=10000000 loops=1)  JIT:    Functions: 6    Options: Inlining true, Optimization true, Expressions true, Deforming true    Timing: Generation 0.954 ms (Deform 0.161 ms), Inlining 8.476 ms, Optimization 25.632 ms, Emission 22.098 ms, Total 57.160 ms (8 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>The Generation value in the last line of the plan is the sum of the expression compilation time (toggled by the <em>jit_expressions<\/em> parameter) and the deforming compilation time (<em>jit_tuple_deforming<\/em>). The deforming compilation time specifically is listed in the parentheses (<code>Deform<\/code>).<\/p>\n<p>  <\/p>\n<p>Since there are no tables in this example, tuple deforming compilation can be switched off to save time. Disable the parameter to see how much we save:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SET jit_tuple_deforming = off;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">The JIT section of the plan:   JIT:    Functions: 5    Options: Inlining true, Optimization true, Expressions true, Deforming false    Timing: Generation 0.665 ms (Deform 0.000 ms), Inlining 15.209 ms, Optimization 25.897 ms, Emission 16.664 ms, Total 58.435 ms<\/code><\/pre>\n<p>  <a name=\"3900a02c\"><\/a>  <\/p>\n<h2 id=\"planner-better-estimate-of-the-initial-cost-of-the-windowagg-nodehttpscommitfestpostgresqlorg444334\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4334\/\">Planner: better estimate of the initial cost of the WindowAgg node<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/3900a02c\">3900a02c<\/a><\/p>\n<p>  <\/p>\n<p>The planner greatly underestimated the cost of getting the first row from a window function in cases where the window function processes a large number of rows.<\/p>\n<p>  <\/p>\n<p>In the following (slightly contrived) example, the planner selects a nested loop to join two tables, because the query returns only one row, and the cost of getting the first row is very small:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">16=> EXPLAIN (analyze, settings) SELECT t.ticket_no, SUM(tf.amount) OVER () FROM tickets t JOIN ticket_flights tf ON t.ticket_no = tf.ticket_no LIMIT 1;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">                                                                           QUERY PLAN                                                                            ----------------------------------------------------------------------------------------------------------------------------------------------------------------  Limit  (cost=0.56..0.86 rows=1 width=46) (actual time=30416.237..30416.239 rows=1 loops=1)    ->  WindowAgg  (cost=0.56..2525161.21 rows=8391708 width=46) (actual time=30416.236..30416.237 rows=1 loops=1)          ->  Nested Loop  (cost=0.56..2420264.86 rows=8391708 width=20) (actual time=0.049..27742.105 rows=8391852 loops=1)                ->  Seq Scan on tickets t  (cost=0.00..78913.45 rows=2949845 width=14) (actual time=0.015..287.636 rows=2949857 loops=1)                ->  Index Scan using ticket_flights_pkey on ticket_flights tf  (cost=0.56..0.76 rows=3 width=20) (actual time=0.007..0.009 rows=3 loops=2949857)                      Index Cond: (ticket_no = t.ticket_no)  Settings: jit = 'off', search_path = 'bookings, public'  Planning Time: 0.456 ms  Execution Time: 30454.862 ms (9 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>Note the second line of the plan, the one where the <code>WindowAgg<\/code> node appears. The initial cost is 0.56, but the actual cost of getting the first row was about 30 seconds.<\/p>\n<p>  <\/p>\n<p>The new patch amends the assessment algorithm, so the planner uses a more appropriate hash join instead, immediately increasing the speed of the query:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">17=> EXPLAIN (analyze, settings) SELECT t.ticket_no, SUM(tf.amount) OVER () FROM tickets t JOIN ticket_flights tf ON t.ticket_no = tf.ticket_no LIMIT 1;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">                                                                   QUERY PLAN                                                                     -------------------------------------------------------------------------------------------------------------------------------------------------  Limit  (cost=523778.31..523778.31 rows=1 width=46) (actual time=7157.639..7157.642 rows=1 loops=1)    ->  WindowAgg  (cost=523778.31..523778.36 rows=8392150 width=46) (actual time=7157.638..7157.640 rows=1 loops=1)          ->  Hash Join  (cost=130215.56..418876.48 rows=8392150 width=20) (actual time=740.005..5075.390 rows=8391852 loops=1)                Hash Cond: (tf.ticket_no = t.ticket_no)                ->  Seq Scan on ticket_flights tf  (cost=0.00..153881.50 rows=8392150 width=20) (actual time=0.066..794.699 rows=8391852 loops=1)                ->  Hash  (cost=78938.47..78938.47 rows=2949847 width=14) (actual time=737.972..737.973 rows=2949857 loops=1)                      Buckets: 262144  Batches: 32  Memory Usage: 6190kB                      ->  Seq Scan on tickets t  (cost=0.00..78938.47 rows=2949847 width=14) (actual time=0.029..307.040 rows=2949857 loops=1)  Settings: search_path = 'bookings, public', jit = 'off'  Planning Time: 0.331 ms  Execution Time: 7202.957 ms (11 rows)<\/code><\/pre>\n<p>  <a name=\"b0e96f31\"><\/a>  <\/p>\n<h2 id=\"pg_constraint-not-null-constraintshttpscommitfestpostgresqlorg443869\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/3869\/\">pg_constraint: NOT NULL constraints<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/b0e96f31\">b0e96f31<\/a><\/p>\n<p>  <\/p>\n<p>A new, but well-known, type of integrity constraint, <code>NOT NULL<\/code> is now officially introduced into the <code>pg_constraint<\/code> system catalog. For various reasons, <code>NOT NULL<\/code> constraints were not written to <code>pg_constraint<\/code> before.<\/p>\n<p>  <\/p>\n<p>This change does not bring new application development opportunities, but the information in the system catalog becomes more complete, and working with constraints becomes more consistent.<\/p>\n<p>  <\/p>\n<p>The <code>NOT NULL<\/code> constraints in <code>pg_constraint<\/code> have the <code>contype = 'n'<\/code> type:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">CREATE TABLE t (     col1 int NOT NULL,     col2 int NOT NULL );  SELECT conname, contype, conkey FROM pg_constraint WHERE conrelid = 't'::regclass;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">     conname     | contype | conkey -----------------+---------+--------  t_col1_not_null | n       | {1}  t_col2_not_null | n       | {2} (2 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>Just like any other constraint, the NOT NULL constraint can be removed by name:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">ALTER TABLE t DROP CONSTRAINT t_col2_not_null;<\/code><\/pre>\n<p>  <\/p>\n<p>The constraints are listed in a separate section of the <code>\\d+<\/code> output:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">postgres@postgres(17.0)=# \\d+ t<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">                                            Table \"public.t\"  Column |  Type   | Collation | Nullable | Default | Storage | Compression | Stats target | Description --------+---------+-----------+----------+---------+---------+-------------+--------------+-------------  col1   | integer |           | not null |         | plain   |             |              |  col2   | integer |           |          |         | plain   |             |              | Not-null constraints:     \"t_col1_not_null\" NOT NULL \"col1\" Access method: heap<\/code><\/pre>\n<p>  <\/p>\n<p>Currently, <code>NOT NULL<\/code> constraints cannot be created without checking existing data (<code>NOT VALID<\/code>) or declared deferred (<code>DEFERRED<\/code>). In addition, <code>NOT NULL<\/code> constraints for system catalog tables are not written in <code>pg_constraint<\/code>.<\/p>\n<p>  <a name=\"11c34b34\"><\/a>  <\/p>\n<h2 id=\"normalization-of-call-deallocate-and-two-phase-commit-control-commandshttpswwwpostgresqlorgmessage-idflatb44fa29d-ebd0-4dd9-abc2-16f1cb087074amazoncom\"><a href=\"https:\/\/www.postgresql.org\/message-id\/flat\/B44FA29D-EBD0-4DD9-ABC2-16F1CB087074@amazon.com\">Normalization of CALL, DEALLOCATE and two-phase commit control commands<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/11c34b34\">11c34b34<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/638d42a3\">638d42a3<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/bb45156f\">bb45156f<\/a><\/p>\n<p>  <\/p>\n<p>The command normalization mechanism can now place constants in place of procedure parameters in <code>CALL<\/code> statements. With this patch, a procedure call with different parameters will be recorded in <code>pg_stat_statements<\/code> as a single line:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">CALL p(1); CALL p(2); CALL p(3);  SELECT queryid, query, calls                                                                                FROM pg_stat_statements WHERE query ILIKE 'CALL%';<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">       queryid       |   query    | calls ---------------------+------------+-------  7076031282516132618 | CALL p($1) |     3 (1 row)<\/code><\/pre>\n<p>  <\/p>\n<p>In addition, transaction identifiers in two-phase commit control commands (see the second commit) and names of prepared statements in <code>DEALLOCATE<\/code> (the third commit) can now be replaced with constants as well.<\/p>\n<p>  <\/p>\n<p>See also:<br \/>  <a href=\"https:\/\/postgrespro.com\/blog\/pgsql\/5969981#commit_3db72ebc\">Normalization of DDL and service commands<\/a><br \/>  <a href=\"https:\/\/postgrespro.com\/blog\/pgsql\/5970086#commit_daa8365a\">Normalization of DDL and service commands, continued<\/a><\/p>\n<p>  <a name=\"59f47fb9\"><\/a>  <\/p>\n<h2 id=\"unaccent-the-target-rule-expressions-now-support-values-in-quotation-markshttpscommitfestpostgresqlorg444511\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4511\/\">unaccent: the target rule expressions now support values in quotation marks<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/59f47fb9\">59f47fb9<\/a><\/p>\n<p>  <\/p>\n<p>To eliminate diacritics, the built-in full-text search suggests using the <code>unaccent<\/code> dictionary supplied with the server as an extension under the same name.<\/p>\n<p>  <\/p>\n<p>When defining custom dictionary rules, target expressions can now be enclosed in quotation marks. This is necessary if the target expression must start with a whitespace or end with it. Previously, the leading and trailing spaces were cut off.<\/p>\n<p>  <a name=\"f6d4c9cf\"><\/a>  <\/p>\n<h2 id=\"copy-from-force_not_null--and-force_null-httpscommitfestpostgresqlorg443896\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/3896\/\">COPY FROM: FORCE_NOT_NULL <em> and FORCE_NULL <\/em><\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/f6d4c9cf\">f6d4c9cf<\/a><\/p>\n<p>  <\/p>\n<p>The <code>COPY<\/code> command parameters <code>FORCE_NOT_NULL<\/code> and <code>FORCE_NULL<\/code> appeared a long time ago, in PostgreSQL 9.0 and 9.4, respectively. However, they required an explicit enumeration of columns, even if they were to be applied to all columns in the table.<\/p>\n<p>  <\/p>\n<p>You can now use the asterisk character <code>*<\/code> instead.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">CREATE TABLE t (col1 text NOT NULL, col2 text NOT NULL);  COPY t FROM STDIN WITH (FORMAT csv, FORCE_NOT_NULL *);<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Enter data to be copied followed by a newline. End with a backslash and a period on a line by itself, or an EOF signal. >> \"\",\"\" >> \\. COPY 1<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SELECT * FROM t WHERE col1 = '' and col2 = '';<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\"> col1 | col2 ------+------       | (1 row)<\/code><\/pre>\n<p>  <a name=\"e48b19c5\"><\/a>  <\/p>\n<h2 id=\"audit-of-connections-without-authenticationhttpswwwpostgresqlorgmessage-idflatcafdbl1n7-gf-zxkab3xuga2bcksmnjfvqb8hgjmndfd2buhl2u-amailgmailcom\"><a href=\"https:\/\/www.postgresql.org\/message-id\/flat\/CAFdbL1N7-GF-ZXKaB3XuGA%2BCkSmnjFvqb8hgjMnDfd%2BuhL2u-A@mail.gmail.com\">Audit of connections without authentication<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/e48b19c5\">e48b19c5<\/a><\/p>\n<p>  <\/p>\n<p>If a user connects without authentication while the parameter <em>log_connections<\/em> is enabled, an entry about the connection will be recorded in the server log, indicating the triggered line number (117) with the <code>trust<\/code> method in pg_hba.conf:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">2023-10-19 11:40:07.609 MSK [111233] LOG:  connection authenticated: user=\"postgres\" method=trust (\/home\/pal\/master\/data\/pg_hba.conf:117) 2023-10-19 11:40:07.609 MSK [111233] LOG:  connection authorized: user=postgres database=demo application_name=psql<\/code><\/pre>\n<p>  <\/p>\n<p>Previously, only the second line was recorded for the <code>trust<\/code> method.<\/p>\n<p>  <\/p>\n<p>Note that the <code>SYSTEM_USER<\/code> function still returns <code>NULL<\/code> for such connections.<\/p>\n<p>  <\/p>\n<p>See also:<br \/>  <a href=\"https:\/\/www.depesz.com\/2023\/09\/01\/waiting-for-postgresql-17-generate-new-log-for-trust-connections-under-log_connections\/\">Waiting for PostgreSQL 17 \u2013 Generate new LOG for \u201ctrust\u201d connections under log_connections \u2013 select * from depesz;<\/a><\/p>\n<p>  <a name=\"13aeaf07\"><\/a>  <\/p>\n<h2 id=\"pg_stat_subscription-new-column-worker_typehttpscommitfestpostgresqlorg444503\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4503\/\">pg_stat_subscription: new column worker_type<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/13aeaf07\">13aeaf07<\/a><\/p>\n<p>  <\/p>\n<p>The new <a href=\"https:\/\/www.postgresql.org\/docs\/devel\/monitoring-stats.html#MONITORING-PG-STAT-SUBSCRIPTION\">pg_stat_subscription<\/a> view column <code>worker_type<\/code> helps to quickly identify what task is being performed by the process serving the subscription. Possible values are self-explanatory: <code>apply<\/code>, <code>parallel apply<\/code> and <code>table synchronization<\/code>.<\/p>\n<p>  <\/p>\n<p>Remember that from PostgreSQL 16 and onwards, the server can now use multiple processes to apply transactions.<\/p>\n<p>  <a name=\"f593c551\"><\/a>  <\/p>\n<h2 id=\"the-behaviour-of-pg_promote-in-case-of-unsuccessful-switchover-to-a-replicahttpscommitfestpostgresqlorg444504\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4504\/\">The behaviour of pg_promote in case of unsuccessful switchover to a replica<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/f593c551\">f593c551<\/a><\/p>\n<p>  <\/p>\n<p>One of the means of switching to a replica is the <code>pg_promote<\/code> function. If the switchover is unsuccessful, the function returns <code>false<\/code>, no matter what caused it:<\/p>\n<p>  <\/p>\n<ul>\n<li>the switchover timeout,<\/li>\n<li>failure to send the SIGUSR1 signal to the postmaster,<\/li>\n<li>or even the postmaster crashing mid-switch.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>The two latter cases resulted in a warning in the server log, though. With the new patch, the warnings are changed to errors, so the function will only return <code>false<\/code> upon timeout, and will error out in other cases.<\/p>\n<p>  <a name=\"8c16ad3b\"><\/a>  <\/p>\n<h2 id=\"choosing-the-disk-synchronization-method-in-server-utilitieshttpscommitfestpostgresqlorg444467\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4467\/\">Choosing the disk synchronization method in server utilities<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/8c16ad3b\">8c16ad3b<\/a><\/p>\n<p>  <\/p>\n<p>Server utilities that write files to disk now have a new parameter <code>--synch-method<\/code>. These include <code>initdb<\/code>, <code>pg_basebackup<\/code>, <code>pg_checksums<\/code>, <code>pg_dump<\/code>, <code>pg_rewind<\/code> and <code>pg_upgrade<\/code>.<\/p>\n<p>  <\/p>\n<p>By default, <code>--synch-method=fsync<\/code> is used.<\/p>\n<p>  <\/p>\n<p>On linux systems, you can use <code>syncfs<\/code> to synchronize the entire file system at once, instead of calling fsync on each file. It will be faster in most cases. However, if other applications that modify files are actively working with the same file system, some side effects are possible, because their writing to disk must also be synchronized. There is a new appendix in the documentation warning about this: <a href=\"https:\/\/www.postgresql.org\/docs\/devel\/syncfs.html\">Appendix O. syncfs() Caveats<\/a>.<\/p>\n<p>  <a name=\"c103d073\"><\/a>  <\/p>\n<h2 id=\"pg_restore-optimization-of-parallel-recovery-of-a-large-number-of-tableshttpscommitfestpostgresqlorg444452\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4452\/\">pg_restore: optimization of parallel recovery of a large number of tables<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/c103d073\">c103d073<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/5af0263a\">5af0263a<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/9bfd44bb\">9bfd44bb<\/a><\/p>\n<p>  <\/p>\n<p>Parallel recovery in <code>pg_restore<\/code> was performed suboptimally on backups containing a large number of tables (tens of thousands and more).<\/p>\n<p>  <\/p>\n<p>The problem is that the parent coordinator process sorted the list of tables each time to find the largest one and pass it to a worker process for recovery. The sorting took up so many resources that the parent process itself became a bottleneck while workers were idle waiting for work.<\/p>\n<p>  <\/p>\n<p>To optimize the selection of the next table, the list of tables was placed in a binary heap. Now <code>pg_restore<\/code> will be much faster when recovering a large number of tables.<\/p>\n<p>  <a name=\"cca97ce6\"><\/a>  <\/p>\n<h2 id=\"pg_basebackup-and-pg_receivewal-with-the-parameter-dbnamehttpscommitfestpostgresqlorg444435\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4435\/\">pg_basebackup and pg_receivewal with the parameter dbname<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/cca97ce6\">cca97ce6<\/a><\/p>\n<p>  <\/p>\n<p><code>pg_basebackup<\/code> and <code>pg_receivewal<\/code> accept <code>dbname<\/code> as a connection parameter. Generally, you don&#8217;t need to specify it, since backups and WAL are at the database cluster level. But in case of connection via proxy, particularly with <code>pgbouncer<\/code>, the database must be specified.<\/p>\n<p>  <\/p>\n<p>Whether you should connect to the system over <code>pgbouncer<\/code> to perform backups may be up for debate, but if there is no other way to connect to the database, then this patch gives you an out.<\/p>\n<p>  <a name=\"b575a26c\"><\/a>  <\/p>\n<h2 id=\"parameter-names-for-a-number-of-built-in-functionshttpscommitfestpostgresqlorg444275\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4275\/\">Parameter names for a number of built-in functions<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/b575a26c\">b575a26c<\/a><\/p>\n<p>  <\/p>\n<p>When defining a function, you don&#8217;t have to define its parameter names \u2013 just their types. This is why most of the built-in functions don&#8217;t have parameter names. But if a function has more than one parameter of the same type, then distinguishing which parameter does what in the <code>\\df<\/code> output becomes sinuous, forcing you to look it up in the documentation.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">16=> \\df string_agg<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">                            List of functions    Schema   |    Name    | Result data type | Argument data types | Type ------------+------------+------------------+---------------------+------  pg_catalog | string_agg | bytea            | bytea, bytea        | agg  pg_catalog | string_agg | text             | text, text          | agg (2 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>The patch adds parameter names to definitions of some aggregate functions that have multiple parameters. The clarity has improved:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">17=> \\df string_agg<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">                                List of functions    Schema   |    Name    | Result data type |     Argument data types      | Type ------------+------------+------------------+------------------------------+------  pg_catalog | string_agg | bytea            | value bytea, delimiter bytea | agg  pg_catalog | string_agg | text             | value text, delimiter text   | agg (2 rows)<\/code><\/pre>\n<p>  <a name=\"f347ec76\"><\/a>  <\/p>\n<h2 id=\"psql-watch-min_rowshttpscommitfestpostgresqlorg444347\"><a href=\"https:\/\/commitfest.postgresql.org\/44\/4347\/\">psql: \\watch min_rows<\/a><\/h2>\n<p>  <\/p>\n<p>commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/f347ec76\">f347ec76<\/a><\/p>\n<p>  <\/p>\n<p>PostgreSQL 16 added the <a href=\"https:\/\/postgrespro.com\/blog\/pgsql\/5970086#commit_00beecfe\">count parameter<\/a> to the <code>\\watch<\/code> command. The parameter allows the user to specify how many times should the query repeat.<\/p>\n<p>  <\/p>\n<p>The patch adds a new way to interrupt the execution of <code>\\watch<\/code>. If the query returns less rows than specified by the parameter <code>min_rows<\/code>, the query will no longer repeat. This can be convenient when monitoring job execution.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">CREATE TABLE job (id int, status text DEFAULT 'NEW'); INSERT INTO job VALUES (1),(2),(3);<\/code><\/pre>\n<p>  <\/p>\n<p>For the demonstration, job processing is done together with monitoring:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">WITH process_job AS (     UPDATE job SET status = 'PROCESSED'     WHERE id = (SELECT id                 FROM job                 WHERE status = 'NEW'                 ORDER BY id LIMIT 1) ) SELECT * FROM job WHERE status = 'NEW' \\watch min_rows=1<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Mon 16 Oct 2023 05:55:53 PM MSK (every 2s)   id | status ----+--------   1 | NEW   2 | NEW   3 | NEW (3 rows)  Mon 16 Oct 2023 05:55:55 PM MSK (every 2s)   id | status ----+--------   2 | NEW   3 | NEW (2 rows)  Mon 16 Oct 2023 05:55:57 PM MSK (every 2s)   id | status ----+--------   3 | NEW (1 row)  Mon 16 Oct 2023 05:55:59 PM MSK (every 2s)   id | status ----+-------- (0 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>See also:<br \/>  <a href=\"https:\/\/www.depesz.com\/2023\/09\/07\/waiting-for-postgresql-17-allow-watch-queries-to-stop-on-minimum-rows-returned\/\">Waiting for PostgreSQL 17 \u2013 Allow \\watch queries to stop on minimum rows returned \u2013 select * from depesz;<\/a><\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<p>This is all for now. Looking forward to the November commitfest!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/772168\/\"> https:\/\/habr.com\/ru\/articles\/772168\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/8o\/dq\/l0\/8odql0uarhapv8j7k2vwb9fiuxi.png\" data-src=\"https:\/\/habrastorage.org\/webt\/8o\/dq\/l0\/8odql0uarhapv8j7k2vwb9fiuxi.png\"\/><\/p>\n<p>  <\/p>\n<p>We continue to follow the news of the PostgreSQL 17 development. Let&#8217;s find out what the September commitfest brings to the table.<\/p>\n<p>  <\/p>\n<p>If you missed our July commitfest review, you can check it out here: <a href=\"https:\/\/postgrespro.com\/blog\/pgsql\/5970285\">2023-07<\/a>.<\/p>\n<p>  <\/p>\n<p><a href=\"#f691f5b8\">Removed the parameter <em>old_snapshot_threshold<\/em><\/a><br \/>  <a href=\"#7750fefd\">New parameter <em>event_triggers<\/em><\/a><br \/>  <a href=\"#260a1f18\">New functions to_bin and to_oct<\/a><br \/>  <a href=\"#1e68e43d\">New system view pg_wait_events<\/a><br \/>  <a href=\"#5a3423ad\">EXPLAIN: a JIT compilation time counter for tuple deforming<\/a><br \/>  <a href=\"#3900a02c\">Planner: better estimate of the initial cost of the WindowAgg node<\/a><br \/>  <a href=\"#b0e96f31\">pg_constraint: NOT NULL constraints<\/a><br \/>  <a href=\"#11c34b34\">Normalization of CALL, DEALLOCATE and two-phase commit control commands<\/a><br \/>  <a href=\"#59f47fb9\">unaccent: the target rule expressions now support values in quotation marks<\/a><br \/>  <a href=\"#f6d4c9cf\">COPY FROM: FORCE_NOT_NULL * and FORCE_NULL *<\/a><br \/>  <a href=\"#e48b19c5\">Audit of connections without authentication<\/a><br \/>  <a href=\"#13aeaf07\">pg_stat_subscription: new column worker_type<\/a><br \/>  <a href=\"#f593c551\">The behaviour of pg_promote in case of unsuccessful switchover to a replica<\/a><br \/>  <a href=\"#8c16ad3b\">Choosing the disk synchronization method in server utilities<\/a><br \/>  <a href=\"#c103d073\">pg_restore: optimization of parallel recovery of a large number of tables<\/a><br \/>  <a href=\"#cca97ce6\">pg_basebackup and pg_receivewal with the parameter dbname<\/a><br \/>  <a href=\"#b575a26c\">Parameter names for a number of built-in functions<\/a><br \/>  <a href=\"#f347ec76\">psql: \\watch min_rows<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-359431","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/359431","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=359431"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/359431\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=359431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=359431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=359431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}