-
Notifications
You must be signed in to change notification settings - Fork 279
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
Change already implemented PSQL 11 Native Partitioning from Monthly to Daily? #248
Comments
I have tested this by updating the table
|
Dynamically changing the interval isn't really something that is built into the extension as it is right now. I'd really have to review things to see what else needs to change, but I also know the other thing that needs to be updated would be the datetime_string field in the config. Problem with that, though, is that it expects to find an existing partition with that format for its suffix. So you're likely going to have to create a new child table with a daily suffix as well for things to work. Another problem with that again is with native partitioning you can't create two child tables that have overlapping constraints. So you'd have to do some juggling of data around. So having said all that and probably just confusing you more, at this time, you're probably better unpartitioning your data and repartitioning it. There are procedures (if you're on PG11+) or scripts (for older versions) to help you do this. Since you're only keeping 7 days of data, hopefully it's not too much data and you could manually delete any data older than 7 days now before doing it to help it go quicker. |
Thank you Keith for your quick response. I am currently running PostgreSQL version 11 thus I will look at the procedures you mentioned. 👍 |
If you have any problems with the procedures, please let me know. Or also even let me know if they work well for you. I haven't gotten much chance to put them to use in real-world work (no clients on PG11 yet), only really in my testing framework. So any feedback on how good/bad they are would be appreciated. |
@keithf4 , I have conceptually outlined the steps below after having tested this on my DEV Zabbix instance (~1/100 the size). Would you be able to clarify whether this is appropriate or if there is a faster, more efficient way? Objective: changing the following table (plus 4 other tables ~10GGB each) from monthly to daily partitions while minimizing downtime and data loss.
Procedure:
Then run
to set up partitions for the data to be inserted. Since I only keep data less than 7 days using a 1 month +/2 partition is perfectly reasonable or I can break it up into days too if you suggest differently.
What would be the ideal
This outputs the following:
This appeared to work with very little data loss in my DEV instance; but again it was 1/100 the size. Is there any way of performing this with zero data loss and transparent to the applications connected to the Zabbix database? What would you suggest is done to simplify the procedure? Thank you for your help thus far; I truly appreciate your time and effort. |
Those steps look good and data loss should be zero as far as I know. And if it's working properly in your testing it should work fine on any sized table. The However, doing this with transparency to the application with native partitioning is really tricky and would involve a lot more steps than this. The old trigger-based methods you could just move all the data to the parent and back out again, but that's no longer possible. Could possibly use the default partition feature in PG11, but even that's tricky as well (see #230). I actually need to sit down at some point and really plan it out myself to get the feature added to pg_partman, so don't want to get into too much speculation on the steps involved right now since even I'm not 100% sure the ideas I have in mind will actually work. |
One thing I will caution you on with partitioning/unpartitioning the tables is that, if there is a lot of data, it can cause a HUGE spike in WAL traffic which in turn causes a huge spike in disk usage wherever your |
@keithf4 , thank you for the details. Setting The transparency to the applications is definitely a challenge, especially on a high read/write DB such as the Zabbix DB. What I will need to do is temporarily set a maintenance window and shut down the Server and Web instance. I could use a Proxy as well (pgbouncer for e.g.) or branch out to HA solutions with a replicated, delayed DB in the meantime so there are ways to work around this. Either way this works well for my current needs and I look forward to more improvements in the future. Feel free to close this as you see fit 💪 . |
I am currently using PostgreSQL Native Range partitioning together with pg_partman on a Zabbix Database.
I recently implemented 'monthly' partitioning for history* tables but later realized that 'daily' partitions will work much better as I'd like to drop the partitions after 7 days.
Is there a way to initiate this change without the need of using sub-partitions?
The text was updated successfully, but these errors were encountered: