pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
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
Re: pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Sat, Oct 31, 2026 at 7:58 PM Roman Khapov wrote: > So the attached patch keeps PERMANENT, when partitioning is in use, for > exactly two tables: pgbench_accounts and pgbench_branches. Thanks for the report and patch! Users who specify --unlogged-tables would expect all data tables to be unlogged, so keeping pgbench_branches logged seems undesirable to me. When using --partitions, --unlogged-tables, and --foreign-keys together, users would expect partitioned accounts, unlogged data tables, and working foreign keys, as documented. So, isn't it better to keep all data tables unlogged and define the foreign key from each accounts partition to pgbench_branches instead of from the partitioned parent? Regards, -- Fujii Masao
Re: pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
Hi! Thanks for review! > So, isn't it better to keep > all data tables unlogged and define the foreign key from each accounts > partition to pgbench_branches instead of from the partitioned parent? > Yes, it is... There is no point in keeping the patch simpler at the cost of the option's meaning, so I did V2 that does: - keep the PERMANENT exception for pgbench_accounts only: it cannot be unlogged when partitioned - accounts -> branches FKs are now created on the partitions (pgbench_accounts_%) if the unlogged option is on and there are partitions -- Best regards, Roman Khapov
Re: pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Hello!
I also sent a patch for this in [1].
But I think the issue is more than this, as I described there,
currently the following snippet works, and I don't think it should,
even outside pgbench:
CREATE TABLE pk (a int PRIMARY KEY) PARTITION BY RANGE (a);
CREATE UNLOGGED TABLE pk1 PARTITION OF pk FOR VALUES FROM (0) TO (100);
CREATE TABLE fk (x int REFERENCES pk);
There in 0002 I fixed this by adding additional check to the last
create table statement, preventing fk from being created, but now
reading e2bab2d7920 properly we might have to revise that and
completely prevent the creation of an unlogged partition itself in
this case.
[1]: https://www.postgresql.org/message-id/CAN4CZFMsEnA0TbYLHjicUn4MTjsJthCOmNvpWoTJb4_sm4F-aA%40mail.gmail.com
Re: pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Mon, Nov 2, 2026 at 6:12 PM Roman Khapov wrote:
> Yes, it is... There is no point in keeping the patch simpler at the
> cost of the option's meaning, so I did V2 that does:
> - keep the PERMANENT exception for pgbench_accounts only: it cannot
> be unlogged when partitioned
> - accounts -> branches FKs are now created on the partitions
> (pgbench_accounts_%) if the unlogged option is on and there are
> partitions
Thanks for updating the patch!
+ if (unlogged_tables && partition_method != PART_NONE)
+ {
+ initPQExpBuffer(&query);
+
+ for (int p = 1; p <= partitions; p++)
This code seems to create foreign keys based on the options specified
in the current pgbench run. IOW, it assumes that --unlogged-tables and
--partitions are specified when creating the foreign keys. But,
that's not necessarily the case. For example, users can create unlogged
partitions and foreign keys separately using -I:
pgbench -i -I dtp --unlogged-tables --partitions=2
pgbench -i -I f
The patch doesn't seem to handle this case. Shouldn't pgbench create
foreign keys based on the actual table persistence and partition list
rather than the current command-line options?
BTW, one concern about the current approach is that creating separate
foreign keys adds one UPDATE trigger on branches for each accounts
partition. The executions of these triggers might affect the benchmark
performance as the partition count grows...
I'm not sure how significant this overhead would be, but I think
it might be better to at least document it. Thought?
Regards,
--
Fujii Masao
Re: pgbench --unlogged-tables silently ignored for branches/tellers/history when --partitions is used
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Tue, Nov 3, 2026 at 5:01 PM Zsolt Parragi wrote: > I also sent a patch for this in [1]. I've sent review comments on your 0002 patch in that thread. Your 0001 looks similar to Roman's v1. Anyway, the server-side fix to reject foreign keys referencing unlogged partitions and the pgbench changes seem separable enough to develop in parallel, so I'm thinking to continue reviewing Roman's patch for pgbench. Regards, -- Fujii Masao