pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used

From: Roman Khapov <rkhapov(at)yandex-team(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: michael(at)paquier(dot)xyz, reshkekirill(at)gmail(dot)com
Subject: pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
Date: 2026-10-31 10:57:50
Message-ID: ADE01102-B866-422B-9DF9-55882F68B4B6@yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers!

While testing pgbench initialization on current master with Kirill,
we noticed that the --unlogged-tables tweak from [0] with
--partitions=N silently downgrades not only pgbench_accounts'
partitioned parent, but also the plain tables pgbench_branches,
pgbench_tellers and pgbench_history to PERMANENT. So
the option's documented meaning silently depends on an unrelated
option:

$ pgbench -i -I dt --unlogged-tables --partitions=2 -s 1 pq
$ psql -d pq -tc "select relname, relpersistence from pg_class
where relname like 'pgbench_%' order by relname"
pgbench_accounts | p
pgbench_accounts_1 | u
pgbench_accounts_2 | u
pgbench_branches | p <- three plain tables should be unlogged
pgbench_tellers | p <-
pgbench_history | p <-

The obvious fix - restrict the PART_NONE exception to pgbench_accounts
- is however incomplete: it makes pgbench_branches unlogged, while the
accounts foreign key is declared on the permanent partitioned parent,
and "constraints on permanent tables may reference only permanent
tables". The combination --unlogged-tables --partitions --foreign-keys
then fails.

So the attached patch keeps PERMANENT, when partitioning is in use, for
exactly two tables: pgbench_accounts and pgbench_branches. Seems like
making the branches exception conditional on --foreign-keys would brake
separately-runnable init steps ('... -I dt' then '... -I f')..

[0] - https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=e2bab2d7920

--
Best regards,
Roman Khapov

Attachment Content-Type Size
0001-pgbench-honor-unlogged-tables-for-non-partitioned-ta.patch application/octet-stream 1.8 KB

Browse pgsql-hackers by date

  From Date Subject
Previous Message ZizhuanLiu X-MAN 2026-10-31 10:55:46 Re: Optimize MCV stats for sortable types and utilize sorted-order properties