Pgslice: Postgres partitioning as easy as pie
github.com
github.com
If you don't mind me asking, for how long?
I've found using EXECUTE in insert triggers to be very problematic - it consumes a txid, AIUI, and every 200m inserts, a bunch of anti-wraparound autovacuums have to to scan allofthethings. My insert triggers have big blocks of IF/ELSIF branches (although it's straightforward enough to construct those in pl/pgsql, just requires an extra level of indirection when preparing the partitioning).
My insert triggers have big blocks of IF/ELSIF branches
It's best to start here: https://github.com/fiksu/partitioned/blob/master/PARTITIONIN...
for an overview.
the examples should prove its use.
Also, how does it compare with pg_partman[1] which also has similar goals?
I have no association with the linked project, but here are some reasons why I might take the same approach:
1. Source control. Code at the level of PG/SQL into source control isn't as easily deployed and managed as, say, Java code.
2. Not being strongly tied to a single software. It's true that this is currently directly intended to be used for PG, but keeping it separate would make it easier to re-adapt for another database software in the future.
3. Lack of expertise with PG internals. This one is just a reason, not a justification.
Note that I'm not defending any software design decisions here, just speculating in a way I find reasonable. I also have the same questions and would be curious to hear the author(s)'s responses.
(Edited for formatting issues with the numbered list - and then again for spelling errors)
Why not?
Application code that touches the file system is still deployed along with the application code.
You might commit schema.sql into your application repository, but that's not the state of your database.
Schema usually is needed for application that will be using a database. I also don't understand the scare about using schema. Schema is FAR FAR FAR simpler to deploy than a Java application.
Not entirely true, PG extensions can be versioned/packaged and deployed just like any versioned code. Just deploy the new version of the extension and ```drop extension foo; create extension foo``` to update to the new version.
It's not as slick and greasy as ```git push heroku master```, but still, not so bad.
(I'm not the author, but I have written a non-trivial Pl/PgSQL extension)
I think an external tool is a bit friendlier for people who aren't super comfortable with installing Postgres extensions. Also, it doesn't require a restart.
I'm optimistic that Postgres will make all of this trivial at some point.
Edit: changed "more features" to "different features". One of the main goals is the ability to partition existing production tables without downtime, which seems different than pg_partman.
There's considerable ongoing work towards that. If you're interested in helping out, consider testing and reviewing the patchset. That doesn't necessarily require a lot of postgres internals knowledge, user interface feedback after trying is very welcome.
We took a similar approach using a ruby library to manage partitions at gilt groupe starting many years ago (2009?). It worked quite well and is still in use today.
Since then have also used the referenced https://github.com/keithf4/pg_partman on RDS - and it works great! Very happy to have all the partition management in the core database vs. in other languages, and many of the features Keith provides in pg_partman just work. He's done a great job with the project and would encourage folks to take a serious look at his work.
If you are interested in details of how we applied pg_partment to RDS w/out requiring extensions, take a look at:
https://github.com/flowcommerce/lib-postgresql/blob/master/R...
We created a simple process to load the scripts directly into the database similar to any one of our other migrations. We then create higher level wrappers for our teams to use to apply consistent use.
I assume so.
Currently there's one big log table and a uniqueness constraint on the GUID field. I'd love to partition the table out but until I can identify a clean route to satisfying that requirement I'm keeping one large log.
Though, now that I think about it, maybe partitioning on the first character of the GUID string is feasible, as we can ensure uniqueness per-table then