{"id":505,"date":"2026-02-11T05:46:22","date_gmt":"2026-02-11T05:46:22","guid":{"rendered":"http:\/\/77interactive.com\/?p=505"},"modified":"2026-02-11T05:56:10","modified_gmt":"2026-02-11T05:56:10","slug":"partition-2","status":"publish","type":"post","link":"http:\/\/77interactive.com\/?p=505","title":{"rendered":"Partition 2"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>CREATE TABLE sales.orders_new3 (\n  created_at  timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,\n  order_id    uuid NOT NULL DEFAULT gen_random_uuid(),\n  customer_id bigint NOT NULL,\n  amount      numeric(12,2) NOT NULL,\n\n  PRIMARY KEY (created_at, order_id)\n) PARTITION BY RANGE (created_at);\n\n-- Helpful for point lookups by order_id\nCREATE INDEX ON sales.orders_new3 (order_id);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Create past and future partitions\nDO $$\nDECLARE\n  start_ts timestamp(3) := '2023-01-01 00:00:00';\n  -- create through next Sunday + 2 weeks for breathing room\n  end_ts   timestamp(3) := (\n              date_trunc('day', now())  -- today at midnight (local server time, but it's timestamp)\n              - (extract(dow from now())::int) * interval '1 day'  -- go back to Sunday 00:00\n              + interval '3 weeks'  -- this Sunday + 3 weeks (i.e., two weeks ahead from next boundary)\n            )::timestamp(3);\n\n  cur      timestamp(3);\n  nxt      timestamp(3);\n  partname text;\nBEGIN\n  cur := start_ts;\n\n  WHILE cur &lt; end_ts LOOP\n    nxt := (cur + interval '1 week')::timestamp(3);\n\n    -- partitions named like orders_new3_p20230101, orders_new_p20230108, ...\n    partname := format('orders_new3_p%s', to_char(cur, 'YYYYMMDD'));\n\n    EXECUTE format(\n      'CREATE TABLE IF NOT EXISTS sales.%I\n         PARTITION OF sales.orders_new3\n         FOR VALUES FROM (%L) TO (%L);',\n      partname, cur, nxt\n    );\n\n    cur := nxt;\n  END LOOP;\nEND $$;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Add the job to add new partitions\nSELECT partman.create_parent(\n  p_parent_table := 'sales.orders_new3',\n  p_control      := 'created_at',\n  p_type         := 'range',\n  p_interval     := '1 week'\n);\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Verify the partitions\nSELECT\n  child.relname AS partition,\n  pg_get_expr(child.relpartbound, child.oid) AS bound\nFROM pg_inherits i\nJOIN pg_class parent ON parent.oid = i.inhparent\nJOIN pg_class child  ON child.oid  = i.inhrelid\nWHERE parent.oid = 'sales.orders_new3'::regclass\nORDER BY child.relname;<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":510,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[17,18],"class_list":["post-505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","tag-postgres","tag-postgresql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Partition 2 - 77 Interactive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/77interactive.com\/?p=505\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Partition 2 - 77 Interactive\" \/>\n<meta property=\"og:url\" content=\"http:\/\/77interactive.com\/?p=505\" \/>\n<meta property=\"og:site_name\" content=\"77 Interactive\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-11T05:46:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-11T05:56:10+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002-683x1024.png\" \/>\n\t<meta property=\"og:image:width\" content=\"683\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Rudy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rudy\" \/>\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\":\"Article\",\"@id\":\"http:\/\/77interactive.com\/?p=505#article\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/?p=505\"},\"author\":{\"name\":\"Rudy\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"headline\":\"Partition 2\",\"datePublished\":\"2026-02-11T05:46:22+00:00\",\"dateModified\":\"2026-02-11T05:56:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=505\"},\"wordCount\":1,\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=505#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png\",\"keywords\":[\"postgres\",\"postgresql\"],\"articleSection\":[\"PostgreSQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/77interactive.com\/?p=505\",\"url\":\"http:\/\/77interactive.com\/?p=505\",\"name\":\"Partition 2 - 77 Interactive\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=505#primaryimage\"},\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=505#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png\",\"datePublished\":\"2026-02-11T05:46:22+00:00\",\"dateModified\":\"2026-02-11T05:56:10+00:00\",\"author\":{\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"breadcrumb\":{\"@id\":\"http:\/\/77interactive.com\/?p=505#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/77interactive.com\/?p=505\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/?p=505#primaryimage\",\"url\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png\",\"contentUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png\",\"width\":1024,\"height\":1536,\"caption\":\"waterfall night\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/77interactive.com\/?p=505#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/77interactive.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Partition 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/77interactive.com\/#website\",\"url\":\"http:\/\/77interactive.com\/\",\"name\":\"77 Interactive\",\"description\":\"Rudy&#039;s Code snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/77interactive.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\",\"name\":\"Rudy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"caption\":\"Rudy\"},\"url\":\"http:\/\/77interactive.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Partition 2 - 77 Interactive","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":"http:\/\/77interactive.com\/?p=505","og_locale":"en_US","og_type":"article","og_title":"Partition 2 - 77 Interactive","og_url":"http:\/\/77interactive.com\/?p=505","og_site_name":"77 Interactive","article_published_time":"2026-02-11T05:46:22+00:00","article_modified_time":"2026-02-11T05:56:10+00:00","og_image":[{"width":683,"height":1024,"url":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002-683x1024.png","type":"image\/png"}],"author":"Rudy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rudy","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/77interactive.com\/?p=505#article","isPartOf":{"@id":"http:\/\/77interactive.com\/?p=505"},"author":{"name":"Rudy","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"headline":"Partition 2","datePublished":"2026-02-11T05:46:22+00:00","dateModified":"2026-02-11T05:56:10+00:00","mainEntityOfPage":{"@id":"http:\/\/77interactive.com\/?p=505"},"wordCount":1,"image":{"@id":"http:\/\/77interactive.com\/?p=505#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png","keywords":["postgres","postgresql"],"articleSection":["PostgreSQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/77interactive.com\/?p=505","url":"http:\/\/77interactive.com\/?p=505","name":"Partition 2 - 77 Interactive","isPartOf":{"@id":"http:\/\/77interactive.com\/#website"},"primaryImageOfPage":{"@id":"http:\/\/77interactive.com\/?p=505#primaryimage"},"image":{"@id":"http:\/\/77interactive.com\/?p=505#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png","datePublished":"2026-02-11T05:46:22+00:00","dateModified":"2026-02-11T05:56:10+00:00","author":{"@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"breadcrumb":{"@id":"http:\/\/77interactive.com\/?p=505#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/77interactive.com\/?p=505"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/?p=505#primaryimage","url":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png","contentUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_002.png","width":1024,"height":1536,"caption":"waterfall night"},{"@type":"BreadcrumbList","@id":"http:\/\/77interactive.com\/?p=505#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/77interactive.com\/"},{"@type":"ListItem","position":2,"name":"Partition 2"}]},{"@type":"WebSite","@id":"http:\/\/77interactive.com\/#website","url":"http:\/\/77interactive.com\/","name":"77 Interactive","description":"Rudy&#039;s Code snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/77interactive.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9","name":"Rudy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","caption":"Rudy"},"url":"http:\/\/77interactive.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=505"}],"version-history":[{"count":1,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/505\/revisions"}],"predecessor-version":[{"id":506,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/505\/revisions\/506"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/media\/510"}],"wp:attachment":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=505"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}