{"id":33,"date":"2007-05-15T23:43:15","date_gmt":"2007-05-16T07:43:15","guid":{"rendered":"http:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/"},"modified":"2017-03-08T14:50:18","modified_gmt":"2017-03-08T22:50:18","slug":"partitioning-fun-in-postgresql","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/","title":{"rendered":"Partitioning Fun in PostgreSQL"},"content":{"rendered":"<p>Last week I learned a few things (the hard way) about PostgreSQL (pgsql) partitioning:<\/p>\n<ul>\n<li>You really have to <a href=\"http:\/\/www.postgresql.org\/docs\/8.1\/static\/ddl-partitioning.html#DDL-PARTITIONING-CONSTRAINT-EXCLUSION\">read the &#8220;caveats&#8221; part of the manual<\/a> (scroll down, very bottom)<\/li>\n<li>Server config matters (<kbd>SET constraint_exclusion = on;<\/kbd>) if you want to avoid unnecessarily checking out-of-bounds partitions<\/li>\n<li>Child tables don&#8217;t inherit permissions, so owning the parent table won&#8217;t automagically grant you access to child tables &#8212; which in this case prevented me from setting up my explicit indexes.<\/li>\n<li>Foreign key constraints on a parent table are not inherited.    This is actually a bug in pgsql.  They <a href=\"http:\/\/developer.postgresql.org\/index.php\/Todo:WishlistFor83#likely\">plan on changing &#8220;CREATE TABLE LIKE&#8221;  in pgsql 8.3<\/a> but fixing this for INHERIT statements is a bit different since it means inheriting for the lifetime of the parent-&gt;child relationship (instead of one-time-only during creation).  For more, read <a href=\"http:\/\/archives.postgresql.org\/pgsql-patches\/2007-03\/msg00120.php\">chizu&#8217;s thread on the issue<\/a> &#8212; he actually submitted a patch that fixed things for table creation.  \ud83d\ude42<\/li>\n<\/ul>\n<p>Long story short, partitioning is tricky business.  For more, see <a href=\"http:\/\/benjamin.smedbergs.us\/blog\/2007-05-12\/when-partitioning-database-tables-explain-your-queries\/\">bsmedberg&#8217;s blog<\/a>, where he talks about query performance in queries spanning multiple partitions and his battle with the postgresql query planner.<\/p>\n<p>From the very beginning, even before you start messing with the query planner, I think it&#8217;s important to understand the pitfalls of inheritance in pgsql and how it will affect your use of partitions.<\/p>\n<p>So just be extra careful when you read the manual and make sure you&#8217;re aware of these issues when you plan your schema.  If you&#8217;re not, it&#8217;ll come back to bite you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week I learned a few things (the hard way) about PostgreSQL (pgsql) partitioning: You really have to read the &#8220;caveats&#8221; part of the manual (scroll down, very bottom) Server config matters (SET constraint_exclusion = on;) if you want to &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/\">Continue reading<\/a><\/p>\n","protected":false},"author":24,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[],"coauthors":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Partitioning Fun in PostgreSQL - Mozilla Web Development<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mike Morgan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/\",\"url\":\"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/\",\"name\":\"Partitioning Fun in PostgreSQL - Mozilla Web Development\",\"isPartOf\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#website\"},\"datePublished\":\"2007-05-16T07:43:15+00:00\",\"dateModified\":\"2017-03-08T22:50:18+00:00\",\"author\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/373fd84922ef95d8d5171d1a72770d4f\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog.mozilla.org\/webdev\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Partitioning Fun in PostgreSQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#website\",\"url\":\"https:\/\/blog.mozilla.org\/webdev\/\",\"name\":\"Mozilla Web Development\",\"description\":\"For make benefit of glorious tubes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.mozilla.org\/webdev\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/373fd84922ef95d8d5171d1a72770d4f\",\"name\":\"Mike Morgan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/image\/1d6151e93e27d281a7fc06534ee8eae0\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ff5890a3252cd74f006ee33360e71c76?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ff5890a3252cd74f006ee33360e71c76?s=96&d=mm&r=g\",\"caption\":\"Mike Morgan\"},\"description\":\"Mike Morgan is the former Director of Web Development for the Mozilla Corporation.\",\"url\":\"https:\/\/blog.mozilla.org\/webdev\/author\/morgamicmozillacom\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Partitioning Fun in PostgreSQL - Mozilla Web Development","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/","twitter_misc":{"Written by":"Mike Morgan","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/","url":"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/","name":"Partitioning Fun in PostgreSQL - Mozilla Web Development","isPartOf":{"@id":"https:\/\/blog.mozilla.org\/webdev\/#website"},"datePublished":"2007-05-16T07:43:15+00:00","dateModified":"2017-03-08T22:50:18+00:00","author":{"@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/373fd84922ef95d8d5171d1a72770d4f"},"breadcrumb":{"@id":"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.mozilla.org\/webdev\/2007\/05\/15\/partitioning-fun-in-postgresql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.mozilla.org\/webdev\/"},{"@type":"ListItem","position":2,"name":"Partitioning Fun in PostgreSQL"}]},{"@type":"WebSite","@id":"https:\/\/blog.mozilla.org\/webdev\/#website","url":"https:\/\/blog.mozilla.org\/webdev\/","name":"Mozilla Web Development","description":"For make benefit of glorious tubes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.mozilla.org\/webdev\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/373fd84922ef95d8d5171d1a72770d4f","name":"Mike Morgan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.mozilla.org\/webdev\/#\/schema\/person\/image\/1d6151e93e27d281a7fc06534ee8eae0","url":"https:\/\/secure.gravatar.com\/avatar\/ff5890a3252cd74f006ee33360e71c76?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ff5890a3252cd74f006ee33360e71c76?s=96&d=mm&r=g","caption":"Mike Morgan"},"description":"Mike Morgan is the former Director of Web Development for the Mozilla Corporation.","url":"https:\/\/blog.mozilla.org\/webdev\/author\/morgamicmozillacom\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts\/33"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/comments?post=33"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/posts\/33\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/media?parent=33"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/categories?post=33"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/tags?post=33"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.mozilla.org\/webdev\/wp-json\/wp\/v2\/coauthors?post=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}