When should we use table partitioning in Postgresql?
No, there is no real row number threshold. If you only have queries that select rows by primary key, the size of the table doesn't really matter.
Partitioning is also primarily a management tool to quickly remove no longer needed rows, not so much a performance tool.
It can be used to improve performance, but only if you have queries that only need a (small) subset of all the rows. If all queries (or at least all performance critical one) do contain the partitioning key, then partitioning can help with performance.
You also need to choose the partitioning key based on then number of partitions this results in. With Postgres 12 or later &quot;thousands&quot; of partitions are feasible (I have heard of users using ~20000 partitions successfully, but I think that's already a stretch). An excessive amount of partitions will most probably be not practical as it will make the planning of the queries a lot slower.
You should also take the fact into account, that a partitioned tables is limited in what the primary key can be - it has to include the partition key. So if you have foreign keys referencing the partitioned table, this might get complicated.