Closed sdhull closed 2 years ago
Hey @sdhull,
For 1, that's my understanding. For Postgres < 12, it's not possible for foreign keys to reference partitioned tables. For Postgres 12+, I think swap
and unswap
could be updated to handle this if someone wants to submit a PR. For swap
, I think the order could be:
NOT VALID
on the intermediate table and drop on the soon-to-be retired tableNOT VALID
foreign keysFor 2 and 3, I think it's simplest to break dev-prod parity here.
Thanks for the reply @ankane! If we get around to partitioning any tables in our live DB I may circle back around to this and work on a PR for ya, but for now I'm just working on partitioning a table that isn't used yet so I think I'm going to just do it destructively 😈 and use pg_partman
for partition management.
But this issue may be useful for future travelers so thanks for weighing in 😄
@ankane Regarding your scenario, where would I specify NOT VALID
? Thank you
Ran through the steps outlined in readme to partition by
day
, created 30 past and 5 future partitions. Randb:structure:dump
and thendb:test:prepare
to get schema loaded in test env, then ran specs and found a bunch of failures like this:"OK" I figured, "I just need to drop the
retired
table." So I did that, but then got one failing spec:So this leaves me with a few questions:
swap
be updated to remove fks to theretired
table?pgslice
in the spec helper suite setup, but that feels kinda grossstructure.sql
exactly matching production schema. It's a bit gross to have 30+ partitions in there, but also it will be out of date after one day. What do you recommend here?