具有数千个分区的 Postgres table

Postgres table with thousands of partition

我有一个 postgres table(在 postgres12 中),在不久的将来应该有数千个分区(至少 200k)。

这是我创建 parent table:

的方式
create table if not exists content (
    key varchar(20) not NULL,
    value json not null default '[]'::json
) PARTITION BY LIST(key)

然后添加任何给定的 child table 如:

create table if not exists content_123 PARTITION OF content for VALUES in ('123');

我还在 child table 之上添加了一个索引以便快速访问(因为我将直接访问 child table):

create index if not exists content_123_idx on content_123 using btree(key) 

这是我的问题:我过去从未在 postgres 中管理过这么多分区 table 所以我只是想知道我正在做的事情是否有任何缺点?另外,(如上所述)我不会直接从 parent table 查询,而是直接从个人 child tables.

读取

有了这些 table 定义,索引就完全没用了。

200000 个分区,查询计划将变得慢得无法忍受,每个SQL 语句将需要非常多的锁和打开的文件。这不会很好地工作。

将几个键集中到一个分区中(然后索引 可能 有意义)。