{"id":507,"date":"2026-02-11T05:54:03","date_gmt":"2026-02-11T05:54:03","guid":{"rendered":"http:\/\/77interactive.com\/?p=507"},"modified":"2026-02-15T03:48:56","modified_gmt":"2026-02-15T03:48:56","slug":"pg_cron-and-more","status":"publish","type":"post","link":"http:\/\/77interactive.com\/?p=507","title":{"rendered":"pg_cron and more"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">0) What you\u2019ll end up with<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>pg_cron enabled<\/strong> at the instance level (via <code>shared_preload_libraries<\/code>) and installed in a database<\/li>\n\n\n\n<li><strong>pg_partman installed<\/strong> in <code>sales<\/code> (schema <code>partman<\/code>)<\/li>\n\n\n\n<li>A <strong>pg_cron job<\/strong> that periodically runs <strong>pg_partman maintenance<\/strong> (partition creation\/retention)<\/li>\n<\/ul>\n\n\n\n<p>AWS confirms:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>pg_cron<\/code> requires adding <code>pg_cron<\/code> to <code>shared_preload_libraries<\/code> and restarting.<\/li>\n\n\n\n<li><code>pg_partman<\/code> is supported on RDS and is enabled per database via <code>CREATE EXTENSION \u2026<\/code>.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1) Create &amp; attach a custom DB parameter group (required for pg_cron)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">In the AWS Console<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>RDS \u2192 Parameter groups \u2192 Create parameter group<\/strong>\n<ul class=\"wp-block-list\">\n<li><strong>Parameter group family<\/strong>: <code>postgres15<\/code><\/li>\n\n\n\n<li>Type: <strong>DB Parameter Group<\/strong><\/li>\n\n\n\n<li>Name: e.g. <code>pg15-cron-partman<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Open your new parameter group and edit:<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Parameters to set<\/h3>\n\n\n\n<p><strong>A) shared_preload_libraries<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add <code>pg_cron<\/code> to the list.<\/li>\n\n\n\n<li>Keep what\u2019s already there (commonly <code>pg_stat_statements<\/code>).<\/li>\n\n\n\n<li>Example final value:\n<ul class=\"wp-block-list\">\n<li><code>pg_stat_statements,pg_cron<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>AWS explicitly requires adding <code>pg_cron<\/code> to <code>shared_preload_libraries<\/code>.<\/p>\n\n\n\n<p><strong>B) cron.database_name (choose where pg_cron stores its metadata)<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Default is typically the <code>postgres<\/code> database, and AWS notes the scheduler is set there by default.<\/li>\n\n\n\n<li>Since you want to operate in <code>sales<\/code>, I recommend setting:\n<ul class=\"wp-block-list\">\n<li><code>cron.database_name = sales<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>This makes pg_cron\u2019s metadata tables live in <code>sales<\/code>, which is usually what you want for a single-app DB.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Note: changing these static params requires a <strong>DB reboot<\/strong> to take effect.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">Attach the parameter group to the DB instance<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>RDS \u2192 Databases \u2192 your instance \u2192 <strong>Modify<\/strong><\/li>\n\n\n\n<li>Set <strong>DB parameter group<\/strong> = <code>pg15-cron-partman<\/code><\/li>\n\n\n\n<li>Apply (immediate is fine, but it won\u2019t take effect until reboot)<\/li>\n\n\n\n<li><strong>Reboot<\/strong> the DB instance<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2) Install pg_cron in the correct database<\/h2>\n\n\n\n<p>Because you set <code>cron.database_name = sales<\/code>, connect to <strong>sales<\/strong> as your master user (commonly <code>postgres<\/code>) and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Connect to sales\nCREATE EXTENSION pg_cron;\n<\/code><\/pre>\n\n\n\n<p>AWS documents that creating the extension requires an account with <code>rds_superuser<\/code> privileges (your master user typically has what you need).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Quick verification<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT extname, extversion\nFROM pg_extension\nWHERE extname = 'pg_cron';\n\nSELECT * FROM cron.job LIMIT 5;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3) Grant pg_cron usage to an application role (optional but recommended)<\/h2>\n\n\n\n<p>If you want a non-master role to schedule jobs, AWS recommends granting access to the <code>cron<\/code> schema.<\/p>\n\n\n\n<p>Example (adjust role name):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- As master user \/ rds_superuser\nGRANT USAGE ON SCHEMA cron TO sales_app;\n\n-- Optional: allow viewing job run history (least privilege is your call)\nGRANT SELECT ON ALL TABLES IN SCHEMA cron TO sales_app;\nALTER DEFAULT PRIVILEGES IN SCHEMA cron GRANT SELECT ON TABLES TO sales_app;\n<\/code><\/pre>\n\n\n\n<p>Important: the job will still fail if that role doesn\u2019t have permissions on the objects it tries to touch.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4) Install pg_partman in the <code>sales<\/code> database<\/h2>\n\n\n\n<p>AWS\u2019s RDS guide recommends creating a <code>partman<\/code> schema and installing the extension there.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Connect to sales\nCREATE SCHEMA IF NOT EXISTS partman;\n\nCREATE EXTENSION pg_partman WITH SCHEMA partman;\n<\/code><\/pre>\n\n\n\n<p>If you hit a permissions error, AWS notes you need <code>rds_superuser<\/code> or grant it to the role performing the install.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Verification<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT extname, extversion\nFROM pg_extension\nWHERE extname = 'pg_partman';<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>-- Display the age of each table in transactions along with its total size\nselect\n c.oid,\n age(c.relfrozenxid) as age_in_transactions,\n , pg_size_pretty(pg_total_relation_size(c.oid)) as total_size\nfrom  pg_class as c\njoin pg_namespace as n on c.relnamespace = n.oid\nwhere c.relkind in ('r','t','m')\n  and n.nspname not in ('pg_catalog', 'information_schema')\n  and c.relname not like 'pg_%_toast'\norder by age_in_transactions desc\n\n-- Display the age of the database in transactions along with the autovacuum freeze max age setting\nselect datname,\n       age(datfrozenxid) as age_in_transactions,\n       current_setting('autovacuum_freeze_max_age')::int as autovacuum_freeze_max_age\nfrom pg_database\norder by age_in_transactions desc;\n\nwith max_age as (\n    select 2000000000 as max_old_xid,\n    setting as autovacuum_freeze_max_age\n    from pg_settings\n    where name = 'autovacuum_freeze_max_age' )\n, per_database_stats as (\n    select datname,\n        age(datfrozenxid) as oldest_current_xid,\n        datfrozenxid,\n        max_old_xid::int,\n        autovacuum_freeze_max_age::int\n    from pg_database\n    join max_age on (true)\n    where datallowconn )\nselect max(oldest_current_xid) as oldest_current_xid,\n       max(round(100.0*(oldest_current_xid\/max_old_xid)::numeric, 2)) as percent_toward_wraparound,\n       max(round(100.0*(oldest_current_xid\/autovacuum_freeze_max_age)::numeric, 2)) as percent_toward_autovacuum_freeze_max_age\nfrom per_database_stats;       <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>0) What you\u2019ll end up with AWS confirms: 1) Create &amp; attach a custom DB parameter group (required for pg_cron) In the AWS Console Parameters to set A) shared_preload_libraries AWS explicitly requires adding pg_cron to shared_preload_libraries. B) cron.database_name (choose where pg_cron stores its metadata) This makes pg_cron\u2019s metadata tables live in sales, which is usually [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":508,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[42,17,18],"class_list":["post-507","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","tag-linux","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>pg_cron and more - 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=507\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"pg_cron and more - 77 Interactive\" \/>\n<meta property=\"og:description\" content=\"0) What you\u2019ll end up with AWS confirms: 1) Create &amp; attach a custom DB parameter group (required for pg_cron) In the AWS Console Parameters to set A) shared_preload_libraries AWS explicitly requires adding pg_cron to shared_preload_libraries. B) cron.database_name (choose where pg_cron stores its metadata) This makes pg_cron\u2019s metadata tables live in sales, which is usually [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/77interactive.com\/?p=507\" \/>\n<meta property=\"og:site_name\" content=\"77 Interactive\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-11T05:54:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-15T03:48:56+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001-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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/77interactive.com\/?p=507#article\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/?p=507\"},\"author\":{\"name\":\"Rudy\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"headline\":\"pg_cron and more\",\"datePublished\":\"2026-02-11T05:54:03+00:00\",\"dateModified\":\"2026-02-15T03:48:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=507\"},\"wordCount\":352,\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=507#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png\",\"keywords\":[\"Linux\",\"postgres\",\"postgresql\"],\"articleSection\":[\"PostgreSQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/77interactive.com\/?p=507\",\"url\":\"http:\/\/77interactive.com\/?p=507\",\"name\":\"pg_cron and more - 77 Interactive\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=507#primaryimage\"},\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=507#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png\",\"datePublished\":\"2026-02-11T05:54:03+00:00\",\"dateModified\":\"2026-02-15T03:48:56+00:00\",\"author\":{\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"breadcrumb\":{\"@id\":\"http:\/\/77interactive.com\/?p=507#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/77interactive.com\/?p=507\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/?p=507#primaryimage\",\"url\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png\",\"contentUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png\",\"width\":1024,\"height\":1536,\"caption\":\"waterfall\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/77interactive.com\/?p=507#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/77interactive.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"pg_cron and more\"}]},{\"@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":"pg_cron and more - 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=507","og_locale":"en_US","og_type":"article","og_title":"pg_cron and more - 77 Interactive","og_description":"0) What you\u2019ll end up with AWS confirms: 1) Create &amp; attach a custom DB parameter group (required for pg_cron) In the AWS Console Parameters to set A) shared_preload_libraries AWS explicitly requires adding pg_cron to shared_preload_libraries. B) cron.database_name (choose where pg_cron stores its metadata) This makes pg_cron\u2019s metadata tables live in sales, which is usually [&hellip;]","og_url":"http:\/\/77interactive.com\/?p=507","og_site_name":"77 Interactive","article_published_time":"2026-02-11T05:54:03+00:00","article_modified_time":"2026-02-15T03:48:56+00:00","og_image":[{"width":683,"height":1024,"url":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001-683x1024.png","type":"image\/png"}],"author":"Rudy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rudy","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/77interactive.com\/?p=507#article","isPartOf":{"@id":"http:\/\/77interactive.com\/?p=507"},"author":{"name":"Rudy","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"headline":"pg_cron and more","datePublished":"2026-02-11T05:54:03+00:00","dateModified":"2026-02-15T03:48:56+00:00","mainEntityOfPage":{"@id":"http:\/\/77interactive.com\/?p=507"},"wordCount":352,"image":{"@id":"http:\/\/77interactive.com\/?p=507#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png","keywords":["Linux","postgres","postgresql"],"articleSection":["PostgreSQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/77interactive.com\/?p=507","url":"http:\/\/77interactive.com\/?p=507","name":"pg_cron and more - 77 Interactive","isPartOf":{"@id":"http:\/\/77interactive.com\/#website"},"primaryImageOfPage":{"@id":"http:\/\/77interactive.com\/?p=507#primaryimage"},"image":{"@id":"http:\/\/77interactive.com\/?p=507#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png","datePublished":"2026-02-11T05:54:03+00:00","dateModified":"2026-02-15T03:48:56+00:00","author":{"@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"breadcrumb":{"@id":"http:\/\/77interactive.com\/?p=507#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/77interactive.com\/?p=507"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/?p=507#primaryimage","url":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png","contentUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/water_fall_001.png","width":1024,"height":1536,"caption":"waterfall"},{"@type":"BreadcrumbList","@id":"http:\/\/77interactive.com\/?p=507#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/77interactive.com\/"},{"@type":"ListItem","position":2,"name":"pg_cron and more"}]},{"@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\/507","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=507"}],"version-history":[{"count":2,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":511,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/507\/revisions\/511"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/media\/508"}],"wp:attachment":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}