-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It should be possible to specify tablespace for table partitions #609
Comments
Hmm... as of PostgresSQL 12, it should be getting the tablespace from the parent table. This had been a template table feature before that, but was fixed to just let PG handle this natively in version 4.3. Nothing should have changed for that in 5.0 as far as I know. Is it working in a prior version for you? So you should be able to set the tablespace you want on the parent table before you run Can you provide an example that shows tablespace inheritance not working? |
@keithf4 you're right, PostgreSQL 12+ gets the tablespace from the parent table, but only if we use pg_partman, on the other hand, creates partition in two steps:
The correct command to create a new table (which pg_partman will attach later as partition) should be: And this is how we can get the tablespace name of the parent table: |
Example
After execution you can see few partitions like:
Current result: TABLESPACE pg_default is specified for all partitions Environment information
|
I can't say, because we started using pg_partman since version 5.0.0. |
Thanks for finding that! I'll try and work on a fix for the next release |
So looks like I was handling this differently in versions older than 5.x and tablespace inheritance was working then. Looks like I missed carrying that method forward into 5.0. So will have a fix for this in 5.1 but thankfully don't need to backpatch this for 4.x. |
If you're able to test, I do have a beta PR up with a fix for the tablespace issue if you want to give it a try |
@keithf4, I tried applying the 1. create_partition_idThe following error was generated
I corrected it this way (added a semicolon)
2. create_partition_timeSame error as above, same fix
3. dump_partitioned_table_definition
The following error was generated
I corrected it this way (added a comma after
Everything else updated with no problems. |
After that, I re-executed the script with the test table
After execution I saw few partitions, as expected:
For partitions BUT for |
I hadn't had time to get to writing a unit test for this one yet, so apologies for the syntax errors. Thank you for testing and the corrections! I'll get an update pushed up when I have a moment |
No worries, happy to help. BTW, I tested changing the behavior of |
I've pushed an update to the 5.1.0 branch that should fix the missing comma and also properly set the tablespace on the default table. Thanks again! |
@keithf4 , I've just checked on the 5.1.0-beta branch, now all partitions have the expected tablespace. I'm looking forward to the 5.1 release ) |
BTW, I had trouble running the update scripts again 1. create_partition_idThe following error was generated
I corrected it this way (added a semicolon)
2. create_partition_timeSame error as above, same fix
|
Thanks again! |
I've updated the PR with your suggested fixes and I also added some unit tests for this feature as well. Will hopefully be able to do the final release in the near future |
@keithf4, I just checked the upgrade script There is no schema declaration in the creation instructions, so this function is created in the Here's how the function is created now
And here's how the function should be created (with
|
Thanks for letting me know! |
This has been fixed |
Just checked again - works as expected! Thank you! I'm looking forward to the 5.1 release ) |
Version 5.1 has been released. Thank you again for all your help with testing! |
The current pg_partman implementation (5.0.0) does not support specifying tablespace for table partitions and also ignores tablespace specified for parent/template tables. As a result, partitions always fall into the default tablespace. I believe this is not expected behavior.
It should be possible:
create_parent
functionMost likely using the tablespace of the parent table would be the most expected behavior.
The text was updated successfully, but these errors were encountered: