I am using Postgres 13.
I have a table (accounts) with around 100 million records, that is (hash) partitioned in to 50 tables (based on the user_id)
This is then further (range) partitioned into 14 tables each, based on the day of transaction.
Every day, I need to create partitioned tables for the hash partitioned tables account_1, account_2, etc - for the 15th day in advance. So in total 50 tables each day.
The process though needs to lock the main parent table accounts (access exclusive) - for it to be able to create a table. This process though takes ~30 seconds - meaning no transactions will be stored during that period. Although the tables would be empty then, it is probably the checks that it needs to do with the current entries in accounts table before it creates the (empty) partitions - that is taking time?
Is there a way I could make the process faster, such that the downtime is minimum? Can I lock the individual hash partitioned tables say accounts_1 and accounts_2 instead of the parent accounts table?
Another way I could think of is to create the table first with the constraint, and then attach the partition (expecting this to be faster). Is that a viable solution or are there other ways?