{"id":415820,"date":"2024-06-30T00:35:45","date_gmt":"2024-06-30T00:35:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=415820"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=415820","title":{"rendered":"<span>PostgreSQL 16: Part 3 or CommitFest 2022-11<\/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\/3g\/bg\/we\/3gbgwemx8w9bejtzmrdle2jweze.png\" alt=\"image\" data-src=\"https:\/\/habrastorage.org\/webt\/3g\/bg\/we\/3gbgwemx8w9bejtzmrdle2jweze.png\"\/><\/p>\n<p>  <\/p>\n<p>We continue to follow the news of the upcoming PostgreSQL 16. The third CommitFest concluded in early December. Let&#8217;s look at the results.<\/p>\n<p>  <\/p>\n<p>If you missed the previous CommitFests, check out our reviews: <a href=\"https:\/\/habr.com\/ru\/company\/postgrespro\/blog\/699610\/\">2022-07<\/a>, <a href=\"https:\/\/habr.com\/ru\/company\/postgrespro\/blog\/696816\/\">2022-09<\/a>.<\/p>\n<p>  <\/p>\n<p>Here are the patches I want to talk about:<\/p>\n<p>  <\/p>\n<p><a href=\"#commit_e6927270\">meson: a new source code build system<\/a><br \/>  <a href=\"#commit_66bc9d2d\">Documentation: a new chapter on transaction processing<\/a><br \/>  <a href=\"#commit_bd95816f\">psql: \\d+ indicates foreign partitions in a partitioned table<\/a><br \/>  <a href=\"#commit_5b66de34\">psql: extended query protocol support<\/a><br \/>  <a href=\"#commit_43351557\">Predicate locks on materialized views<\/a><br \/>  <a href=\"#commit_c0374718\">Tracking last scan time of indexes and tables<\/a><br \/>  <a href=\"#commit_2589434a\">pg_buffercache: a new function pg_buffercache_summary<\/a><br \/>  <a href=\"#commit_af205152\">walsender displays the database name in the process status<\/a><br \/>  <a href=\"#commit_9e540599\">Reducing the WAL overhead of freezing tuples<\/a><br \/>  <a href=\"#commit_cd4329d9\">Reduced power consumption when idle<\/a><br \/>  <a href=\"#commit_97da4824\">postgres_fdw: batch mode for COPY<\/a><br \/>  <a href=\"#commit_f13b2088\">Modernizing the GUC infrastructure<\/a><br \/>  <a href=\"#commit_e09d7a12\">Hash index build optimization<\/a><br \/>  <a href=\"#commit_60684dd8\">MAINTAIN \u2015 a new privilege for table maintenance<\/a><br \/>  <a href=\"#commit_3d14e171\">SET ROLE: better role change management<\/a><br \/>  <a href=\"#commit_a54b658c\">Support for file inclusion directives in pg_hba.conf and pg_ident.conf<\/a><br \/>  <a href=\"#commit_8fea8683\">Regular expressions support in pg_hba.conf<\/a><\/p>\n<p><a name=\"habracut\"><\/a><br \/>  <a name=\"commit_e6927270\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/39\/3395\/\">meson: a new source code build system<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/e6927270\">e6927270<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/4c72102e\">4c72102e<\/a><\/p>\n<p>  <\/p>\n<p>Meson support was first introduced in a commit way back in September. Several dozen more commits followed. Several dozens more followed. In early December, a <a href=\"https:\/\/www.postgresql.org\/docs\/devel\/install-meson.html\">documentation section<\/a> describing the new build process was committed. There is also a <a href=\"https:\/\/wiki.postgresql.org\/wiki\/Meson\">wiki page<\/a> that explains, among other things, what was behind the decision to introduce the new building tool. One of the reasons is to simplify building the server for Windows systems and to be able to eventually stop supporting the PostgreSQL&#8217;s own build tools from the \/src\/tools\/msvc entirely.<\/p>\n<p>  <\/p>\n<p>The new build system will be available alongside with autoconf and make, there is no plans to replace the good old tools.<\/p>\n<p>  <\/p>\n<p>However, I specifically used Meson to build the fresh PostgreSQL 16 testing environment for this article. On Ubuntu, the building went as follows:<\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">$ git clone git:\/\/git.postgresql.org\/git\/postgresql.git $ cd postgresql $ meson setup build --prefix=\/home\/pal\/pg16 -Dpgport=5416 $ cd build $ ninja $ ninja install<\/code><\/pre>\n<p>  <\/p>\n<p>I left everything on default, except for the installation location and the server port.<\/p>\n<p>  <\/p>\n<p>All what&#8217;s left is to initialize the cluster and start the server, which you do the same way regardless of the build tool used.<\/p>\n<p>  <a name=\"commit_66bc9d2d\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3899\/\">Documentation: a new chapter on transaction processing<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/66bc9d2d\">66bc9d2d<\/a><\/p>\n<p>  <\/p>\n<p>A new chapter has been added to the documentation: <a href=\"https:\/\/www.postgresql.org\/docs\/devel\/transactions.html\">74. Transaction processing<\/a>. It lives in the Internals section and gives a brief overview of what virtual and real transaction identifiers are, how they are shown in pg_locks, and how subtransactions and two-phase transactions work.<\/p>\n<p>  <a name=\"commit_bd95816f\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3972\/\">psql: \\d+ indicates foreign partitions in a partitioned table<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/bd95816f\">bd95816f<\/a><\/p>\n<p>  <\/p>\n<p>For a partitioned table, the \\d+ command will mark sections that are foreign tables with the word FOREIGN.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">\\d+ data<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">                                    Partitioned table \"public.data\"   Column   | Type | Collation | Nullable | Default | Storage  | Compression | Stats target | Description -----------+------+-----------+----------+---------+----------+-------------+--------------+-------------  data_year | text |           |          |         | extended |             |              | Partition key: LIST (data_year) Partitions: data_2020 FOR VALUES IN ('2020'), FOREIGN,             data_2021 FOR VALUES IN ('2021'), FOREIGN,             data_2022 FOR VALUES IN ('2022')<\/code><\/pre>\n<p>  <a name=\"commit_5b66de34\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3974\/\">psql: extended query protocol support<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/5b66de34\">5b66de34<\/a><\/p>\n<p>  <\/p>\n<p>Until now, psql has not directly supported the <a href=\"https:\/\/www.postgresql.org\/docs\/current\/protocol-overview.html#PROTOCOL-QUERY-CONCEPTS\">extended query protocol<\/a>. Therefore, parameterized queries could only be performed indirectly, such as with the PREPARE statement.<\/p>\n<p>  <\/p>\n<p>Now the \\bind command has been added to psql to bind values to the parameters of the next query. Here&#8217;s how it works:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SET log_statement='all';  \\bind 42 'Answer: '  SELECT $2||$1;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">  ?column?   ------------ Answer: 42 (1 row)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"pgsql\">\\! tail -2 logfile<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">2022-12-05 12:58:05.924 MSK [16566] LOG:  execute &lt;unnamed>: SELECT $2||$1; 2022-12-05 12:58:05.924 MSK [16566] DETAIL:  parameters: $1 = '42', $2 = 'Answer: '<\/code><\/pre>\n<p>  <\/p>\n<p>Only a fraction of the capabilities of the extended query protocol has been implemented, but the initiative is very welcome.<\/p>\n<p>  <a name=\"commit_43351557\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3804\/\">Predicate locks on materialized views<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/43351557\">43351557<\/a><\/p>\n<p>  <\/p>\n<p>Predicate locks are used to ensure consistency for transactions with the SERIALIZABLE isolation level. They were never designed to update materialized views with the REFRESH MATERIALIZED VIEW command, because it exclusively locks the view in order to prevent any concurrent access anomalies.<\/p>\n<p>  <\/p>\n<p>But when updating with the CONCURRENTLY parameter and without predicate locks, transactions with the SERIALIZABLE isolation level could experience write skew. Now the problem is fixed.<\/p>\n<p>  <a name=\"commit_c0374718\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3836\/\">Tracking last scan time of indexes and tables<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/c0374718\">c0374718<\/a><\/p>\n<p>  <\/p>\n<p>In addition to counting table and index scans, the cumulative statistics system now records time and date of the last recorded scan. This data is stored in the last_seq_scan and last_idx_scan columns in pg_stat_all_tables and the last_idx_scan column in pg_stat_all_indexes.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SELECT seq_scan, last_seq_scan, idx_scan, last_idx_scan FROM   pg_stat_all_tables WHERE  relid = 'tickets'::regclass;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\"> seq_scan |         last_seq_scan         | idx_scan |         last_idx_scan          ----------+-------------------------------+----------+-------------------------------         23 | 2022-12-07 15:17:57.261575+03 |        2 | 2022-12-05 14:59:53.564968+03 (1 row)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SELECT indexrelname, idx_scan, last_idx_scan FROM pg_stat_all_indexes WHERE relid = 'tickets'::regclass;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">     indexrelname     | idx_scan |         last_idx_scan          ----------------------+----------+-------------------------------  tickets_pkey         |        2 | 2022-12-05 14:59:53.564968+03  tickets_book_ref_idx |        0 | (2 rows)<\/code><\/pre>\n<p>  <\/p>\n<p>It can be helpful for analyzing index and table use if no dedicated monitoring system is implemented.<\/p>\n<p>  <a name=\"commit_2589434a\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3839\/\">pg_buffercache: a new function pg_buffercache_summary<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/2589434a\">2589434a<\/a><\/p>\n<p>  <\/p>\n<p>The pg_buffercache extension now can display aggregated buffer cache data:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">CREATE EXTENSION pg_buffercache;  SELECT * FROM pg_buffercache_summary()\\gx<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">-[ RECORD 1 ]--+------------------ buffers_used   | 2544 buffers_unused | 13840 buffers_dirty  | 38 buffers_pinned | 0 usagecount_avg | 2.183176100628931<\/code><\/pre>\n<p>  <\/p>\n<p>We used to obtain this data by aggregating the pg_buffercache view, but the new function does not lock the buffers, therefore it is cheaper and can be easily integrated into monitoring systems.<\/p>\n<p>  <a name=\"commit_af205152\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3937\/\">walsender displays the database name in the process status<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/af205152\">af205152<\/a><\/p>\n<p>  <\/p>\n<p>walsender is the process that handles replication protocol connections. For physical replication or backup, walsender connects to an instance, but not to a specific database. When you create a logical replication subscription, however, the publisher creates a logical replication slot, and walsender connects to the database where the publication is created.<\/p>\n<p>  <\/p>\n<p>The patch adds the name of the database to walsender process description in case of logical replication, which makes monitoring those processes more convenient.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">16(sub)=# CREATE SUBSCRIPTION sub CONNECTION 'port=5416 user=postgres dbname=demo' PUBLICATION pub;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">NOTICE:  created replication slot \"sub\" on publisher CREATE SUBSCRIPTION<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"pgsql\">16(pub)=# \\! ps -o pid,command --ppid `head -n 1 \/home\/pal\/pg16\/data\/postmaster.pid`<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">    PID COMMAND   38514 postgres: checkpointer   38515 postgres: background writer   38517 postgres: walwriter   38518 postgres: autovacuum launcher   38519 postgres: logical replication launcher   38522 postgres: postgres demo [local] idle   38662 postgres: walsender postgres demo [local] START_REPLICATION<\/code><\/pre>\n<p>  <\/p>\n<p>Here, the walsender process status displays the demo database name.<\/p>\n<p>  <a name=\"commit_9e540599\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3886\/\">Reducing the WAL overhead of freezing tuples<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/9e540599\">9e540599<\/a><\/p>\n<p>  <\/p>\n<p>Peter Geoghegan is <a href=\"https:\/\/wiki.postgresql.org\/wiki\/Freezing\/skipping_strategies_patch:_motivating_examples\">working<\/a> on proactive tuple freezing. The purpose is clear: to avoid transaction counter wraparound, you need to start freezing in advance. However, an earlier freeze leads to a larger WAL volume and increases the associated overhead (WAL replication and archiving).<\/p>\n<p>  <\/p>\n<p>In this patch, Peter proposed to form WAL freezing records more compactly (~5 times so).<\/p>\n<p>  <a name=\"commit_cd4329d9\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3566\/\">Reduced power consumption when idle<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/cd4329d9\">cd4329d9<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/05a7be93\">05a7be93<\/a><\/p>\n<p>  <\/p>\n<p>When the main server is idle, the startup process on physical replicas still wakes up every 5 seconds to check if the file specified in the <em>promote_trigger_file<\/em> has appeared. But there are other mechanisms for promoting a replica: pg_ctl promote and the pg_promote function. To reduce resource consumption for such wake-ups, the <em>promote_trigger_file<\/em> parameter was removed.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/05a7be93\">Similar work<\/a> was done with the walreceiver process, which woke up 10 times a second, checking whether it needed to do something. Now, the process calculates the time of its next start in advance.<\/p>\n<p>  <a name=\"commit_97da4824\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/2601\/\">postgres_fdw: batch mode for COPY<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/97da4824\">97da4824<\/a><\/p>\n<p>  <\/p>\n<p>Batch-inserting records into foreign tables <a href=\"https:\/\/habr.com\/ru\/company\/postgrespro\/blog\/541252#commit_b663a413\">first became possible<\/a> in the 14th release. The batch size is set by the batch_size parameter at the foreign server or table level. However, it was implemented only for the INSERT command. This patch adds support for batch paste mode for the COPY FROM command.<\/p>\n<p>  <\/p>\n<p>Let&#8217;s compare the insertion speed by different commands. To do this, I first create an empty bookings table in the postgres database, into which we will insert data.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">postgres=# CREATE TABLE public.bookings (     book_ref char(6),     book_date timestamptz,     total_amount numeric(10,2) );<\/code><\/pre>\n<p>  <\/p>\n<p>In the demo database in the same cluster, let&#8217;s create a foreign table for the bookings table.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">CREATE EXTENSION postgres_fdw;  CREATE SERVER srv     FOREIGN DATA WRAPPER postgres_fdw     OPTIONS (dbname 'postgres', batch_size '1');  CREATE USER MAPPING FOR postgres     SERVER srv     OPTIONS (user 'postgres');  CREATE FOREIGN TABLE bookings_remote (     book_ref char(6),     book_date timestamptz,     total_amount numeric(10,2)  ) SERVER srv      OPTIONS (schema_name 'public', table_name 'bookings');<\/code><\/pre>\n<p>  <\/p>\n<p>The batch size is set at the server level as 1, which means that the batch mode is disabled and records are sent one at a time.<\/p>\n<p>  <\/p>\n<p>Let&#8217;s dump the bookings table contents from the <a href=\"https:\/\/postgrespro.com\/community\/demodb\">demo database<\/a> into a file:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">\\COPY bookings TO 'bookings.txt'<\/code><\/pre>\n<p>  <\/p>\n<p>Now, upload the file contents into the foreign table and measure the time:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">\\timing on \\COPY bookings_remote FROM 'bookings.txt'<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">COPY 2111110 Time: 57327,152 ms (00:57,327)<\/code><\/pre>\n<p>  <\/p>\n<p>It took almost a minute to insert a little more than two million rows. Set the batch size to 100 and repeat the test:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">TRUNCATE bookings_remote; ALTER SERVER srv OPTIONS (SET batch_size '100');  \\COPY bookings_remote FROM 'bookings.txt'<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"pgsql\">COPY 2111110 Time: 8780,000 ms (00:08,780)<\/code><\/pre>\n<p>  <\/p>\n<p>The insertion speed has increased by more than 6 times!<\/p>\n<p>  <\/p>\n<p>Curiously, the INSERT command works even faster in batch mode:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">TRUNCATE bookings_remote; INSERT INTO bookings_remote SELECT * FROM bookings;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">INSERT 0 2111110 Time: 6669,504 ms (00:06,670)<\/code><\/pre>\n<p>  <\/p>\n<p>So when it comes to insertion with the COPY command, there&#8217;s room for optimization yet! Also, it would be great to teach postgres_fdw to use batch mode to modify and delete rows, not just read and insert.<\/p>\n<p>  <a name=\"commit_f13b2088\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3879\/\">Modernizing the GUC infrastructure<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/f13b2088\">f13b2088<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/3057465a\">3057465a<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/407b50f2\">407b50f2<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/9c911ec0\">9c911ec0<\/a><\/p>\n<p>  <\/p>\n<p>This series of commits optimizes storage and speeds up access to configuration parameters, including user-generated ones.<\/p>\n<p>  <\/p>\n<p>The optimization is most evident in the example that Tom Lane gave in the letter that started the discussion:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">do $$     begin         for i in 1..10000 loop         perform set_config('foo.bar' || i::text, i::text, false);     end loop; end $$;<\/code><\/pre>\n<p>  <\/p>\n<p>On my computer, creating ten thousand user parameters in PostgreSQL 15 took about six seconds, and after applying the patches, the time was reduced to ~ 30 milliseconds.<\/p>\n<p>  <a name=\"commit_e09d7a12\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/38\/3635\/\">Hash index build optimization<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/e09d7a12\">e09d7a12<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/d09dbeb9\">d09dbeb9<\/a><\/p>\n<p>  <\/p>\n<p>When building hash indexes, the values were sorted only by the bucket number. If you additionally sort by value, then inserting subsequent values is faster.<\/p>\n<p>  <\/p>\n<p>The first commit was made in July, and the second in November. By now, the hash index build speed increased by 5-15%.<\/p>\n<p>  <a name=\"commit_60684dd8\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/41\/4055\/\">MAINTAIN \u2015 a new privilege for table maintenance<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/60684dd8\">60684dd8<\/a><\/p>\n<p>  <\/p>\n<p>A number of maintenance actions for tables and materialized views are not regulated by privileges and are usually available only to the object owner and the superuser.<\/p>\n<p>  <\/p>\n<p>PostgreSQL 16 introduces the MAINTAIN privilege, which can be granted on materialized views and tables, including system ones:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">GRANT MAINTAIN ON pg_class, pg_attribute, pg_type TO alice;<\/code><\/pre>\n<p>  <\/p>\n<p>The \\dp output uses the m character for this privilege:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\\dp pg_catalog.pg_class                                      Access privileges    Schema   |   Name   | Type  |     Access privileges      | Column privileges | Policies ------------+----------+-------+----------------------------+-------------------+----------  pg_catalog | pg_class | table | postgres=arwdDxtm\/postgres+|                   |             |          |       | =r\/postgres               +|                   |             |          |       | alice=m\/postgres           |                   |<\/code><\/pre>\n<p>  <\/p>\n<p>What actions are granted by this privilege? These include executing the commands ANALYZE, VACUUM (including VACUUM FULL), CLUSTER, REINDEX, REFRESH MATERIALIZED VIEW and LOCK TABLE.<\/p>\n<p>  <\/p>\n<p>In addition, a predefined pg_maintain role has been added. Membership in this role grants the MAINTAIN privilege on all relations in the database. This allows you to grant maintenance privileges to a regular role that does not have the rights to perform DDL and DML operations in the database otherwise.<\/p>\n<p>  <\/p>\n<p>The initial patch proposed the addition of two privileges for VACUUM and ANALYZE, but eventually the community settled on the MAINTAIN privilege with more extensive maintenance capabilities.<\/p>\n<p>  <a name=\"commit_3d14e171\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3868\/\">SET ROLE: better role change management<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/3d14e171\">3d14e171<\/a><\/p>\n<p>  <\/p>\n<p>This patch continues the effort to build a more robust roles and privileges management system. The previous article talked about <a href=\"https:\/\/postgrespro.com\/blog\/pgsql\/5969859#commit_ce6b672e\">granting membership in roles<\/a> and <a href=\"https:\/\/postgrespro.com\/blog\/pgsql\/5969859#commit_e3ce2de0\">inheriting privileges<\/a>.<\/p>\n<p>  <\/p>\n<p>The new patch introduces switching to another role with the SET ROLE command. Suppose we decide to include the alice role into pg_read_all_data with privilege inheritance enabled:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">postgres=# GRANT pg_read_all_data TO alice WITH INHERIT TRUE;<\/code><\/pre>\n<p>  <\/p>\n<p>The alice role can now use pg_read_all_data privileges. But nothing is stopping alice from switching role to pg_read_all_data and starting to create objects on its behalf:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">postgres=# \\c - alice<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">You are now connected to database \"postgres\" as user \"alice\".<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"pgsql\">alice=> CREATE TABLE t (id int);<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">CREATE TABLE<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"pgsql\">alice=> \\dt t<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">            List of relations  Schema | Name | Type  |      Owner        --------+------+-------+------------------  public | t    | table | pg_read_all_data<\/code><\/pre>\n<p>  <\/p>\n<p>Actually, there is. To create objects, the pg_read_all_data role must have the CREATE privilege in some schema, such as in public. And starting from PostgreSQL 15, the pseudo-role public no longer has this privilege. As for the example above, I had to run the following command in advance:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">postgres=# GRANT CREATE ON SCHEMA public TO public;<\/code><\/pre>\n<p>  <\/p>\n<p>Nevertheless, switching to another role may be undesirable in certain situations. If we provided membership in a role with INHERIT TRUE, then why switch at all? In the new version, this can be prohibited by the same GRANT command:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">postgres=# GRANT pg_read_all_data TO alice WITH INHERIT TRUE, SET FALSE;<\/code><\/pre>\n<p>  <\/p>\n<p>Alice can now use pg_read_all_data privileges, but will not be able to switch to it.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">alice=> SET ROLE pg_read_all_data;<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">ERROR:  permission denied to set role \"pg_read_all_data\"<\/code><\/pre>\n<p>  <\/p>\n<p>The ability to switch to a role is stored in the set_option column of the pg_auth_members table, next to inherit_option and admin_option.<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SELECT roleid::regrole, member::regrole, grantor::regrole,        admin_option, inherit_option, set_option FROM pg_auth_members WHERE member = 'alice'::regrole\\gx<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">-[ RECORD 1 ]--+----------------- roleid         | pg_read_all_data member         | alice grantor        | postgres admin_option   | f inherit_option | t set_option     | f<\/code><\/pre>\n<p>  <a name=\"commit_a54b658c\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3558\/\">Support for file inclusion directives in pg_hba.conf and pg_ident.conf<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/a54b658c\">a54b658c<\/a><\/p>\n<p>  <\/p>\n<p>The configuration files pg_hba.conf and pg_ident.conf, as well as postgresql.conf, now support the directives to include other files: include, include_if_exists, include_dir.<\/p>\n<p>  <\/p>\n<p>Columns containing the file name and rule\/map number have been added to pg_hba_file_rules and pg_ident_file_mappings:<\/p>\n<p>  <\/p>\n<pre><code class=\"pgsql\">SELECT * FROM pg_hba_file_rules WHERE file_name LIKE '%hba_ident_test.conf' \\gx<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">-[ RECORD 1 ]--------------------------------- rule_number | 1 file_name   | \/home\/pal\/pg\/hba_ident_test.conf line_number | 1 type        | local database    | {all} user_name   | {alice} address     | netmask     | auth_method | peer options     | {map=m1} error       |  ```PGSQL SELECT * FROM pg_ident_file_mappings WHERE file_name LIKE '%ident_test.conf' \\gx<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">-[ RECORD 1 ]----------------------------- map_number  | 1 file_name   | \/home\/pal\/pg\/ident_test.conf line_number | 1 map_name    | m1 sys_name    | student pg_username | alice error       |<\/code><\/pre>\n<p>  <a name=\"commit_8fea8683\"><\/a>  <\/p>\n<p><strong><a href=\"https:\/\/commitfest.postgresql.org\/40\/3824\/\">Regular expressions support in pg_hba.conf<\/a><\/strong><br \/>  commit: <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/8fea8683\">8fea8683<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/a9039713\">a9039713<\/a>, <a href=\"https:\/\/github.com\/postgres\/postgres\/commit\/fc579e11\">fc579e11<\/a><\/p>\n<p>  <\/p>\n<p>pg_hba.conf supports regular expressions for the user name and the database name. If any of these fields starts with a slash (\/), then the value is considered a regular expression.<\/p>\n<p>  <\/p>\n<hr\/>\n<p>  <\/p>\n<p>This is all for now. Looking forward to the results of the <a href=\"https:\/\/commitfest.postgresql.org\/41\/\">January CommitFest<\/a>!<\/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\/708082\/\"> https:\/\/habr.com\/ru\/articles\/708082\/<\/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\/3g\/bg\/we\/3gbgwemx8w9bejtzmrdle2jweze.png\" alt=\"image\" data-src=\"https:\/\/habrastorage.org\/webt\/3g\/bg\/we\/3gbgwemx8w9bejtzmrdle2jweze.png\"\/><\/p>\n<p>  <\/p>\n<p>We continue to follow the news of the upcoming PostgreSQL 16. The third CommitFest concluded in early December. Let&#8217;s look at the results.<\/p>\n<p>  <\/p>\n<p>If you missed the previous CommitFests, check out our reviews: <a href=\"https:\/\/habr.com\/ru\/company\/postgrespro\/blog\/699610\/\">2022-07<\/a>, <a href=\"https:\/\/habr.com\/ru\/company\/postgrespro\/blog\/696816\/\">2022-09<\/a>.<\/p>\n<p>  <\/p>\n<p>Here are the patches I want to talk about:<\/p>\n<p>  <\/p>\n<p><a href=\"#commit_e6927270\">meson: a new source code build system<\/a><br \/>  <a href=\"#commit_66bc9d2d\">Documentation: a new chapter on transaction processing<\/a><br \/>  <a href=\"#commit_bd95816f\">psql: \\d+ indicates foreign partitions in a partitioned table<\/a><br \/>  <a href=\"#commit_5b66de34\">psql: extended query protocol support<\/a><br \/>  <a href=\"#commit_43351557\">Predicate locks on materialized views<\/a><br \/>  <a href=\"#commit_c0374718\">Tracking last scan time of indexes and tables<\/a><br \/>  <a href=\"#commit_2589434a\">pg_buffercache: a new function pg_buffercache_summary<\/a><br \/>  <a href=\"#commit_af205152\">walsender displays the database name in the process status<\/a><br \/>  <a href=\"#commit_9e540599\">Reducing the WAL overhead of freezing tuples<\/a><br \/>  <a href=\"#commit_cd4329d9\">Reduced power consumption when idle<\/a><br \/>  <a href=\"#commit_97da4824\">postgres_fdw: batch mode for COPY<\/a><br \/>  <a href=\"#commit_f13b2088\">Modernizing the GUC infrastructure<\/a><br \/>  <a href=\"#commit_e09d7a12\">Hash index build optimization<\/a><br \/>  <a href=\"#commit_60684dd8\">MAINTAIN \u2015 a new privilege for table maintenance<\/a><br \/>  <a href=\"#commit_3d14e171\">SET ROLE: better role change management<\/a><br \/>  <a href=\"#commit_a54b658c\">Support for file inclusion directives in pg_hba.conf and pg_ident.conf<\/a><br \/>  <a href=\"#commit_8fea8683\">Regular expressions support in pg_hba.conf<\/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-415820","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/415820","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=415820"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/415820\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=415820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=415820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=415820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}