{"id":40502803,"url":"https://github.com/rodo/postgresql-data-historization","last_synced_at":"2026-01-20T19:11:30.728Z","repository":{"id":261400548,"uuid":"880800821","full_name":"rodo/postgresql-data-historization","owner":"rodo","description":"PLPGSQL Script to historize data in partitionned table","archived":false,"fork":false,"pushed_at":"2024-12-17T16:12:52.000Z","size":109,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-17T16:36:06.222Z","etag":null,"topics":["postgresql"],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rodo.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-30T11:39:48.000Z","updated_at":"2024-12-17T16:02:33.000Z","dependencies_parsed_at":"2024-11-06T11:38:38.257Z","dependency_job_id":"4d551e02-2160-4866-b1b2-28c31693924c","html_url":"https://github.com/rodo/postgresql-data-historization","commit_stats":null,"previous_names":["rodo/postgresql-data-historization"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/rodo/postgresql-data-historization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodo%2Fpostgresql-data-historization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodo%2Fpostgresql-data-historization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodo%2Fpostgresql-data-historization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodo%2Fpostgresql-data-historization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodo","download_url":"https://codeload.github.com/rodo/postgresql-data-historization/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodo%2Fpostgresql-data-historization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28609872,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T18:56:40.769Z","status":"ssl_error","status_checked_at":"2026-01-20T18:54:26.653Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["postgresql"],"created_at":"2026-01-20T19:11:30.364Z","updated_at":"2026-01-20T19:11:30.679Z","avatar_url":"https://github.com/rodo.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postgresql-data-historization\nPLPGSQL Script to historize data in partitionned table\n\n\n## How to historize a table\n\nData historization process needs 2 steps, a first one to initialize, this\nstep will create the necessary objects. The second step launch the\nhistorization by setting up the triggers.\n\n\n### Initialize the historization\n\nThe following function will set up all necessary object to historize\ndata on a table, no data will be stored after this step\n\n```sql\nSELECT historize_table_init('public','alpha');\n```\n\n### Start the historization\n\nThe function will set up trigger on the source table, once the `start` step is done data will be collected in the table suffix with `_log`\n\n```sql\nSELECT historize_table_start('public','alpha');\n```\n\n### Stop the historization\n\nThe function will remove trigger dans function and stop to store changes in log table\n\n```sql\nSELECT historize_table_stop('public','alpha');\n```\n\n### Reset the historization\n\nThe function will remove the cron entries and columns created on source tablr\n\n```sql\nSELECT historize_table_reset('public','alpha');\n```\n\n### Clean the historization\n\nThe function will remove the table log, after this step there is no trace of the historization\n\n```sql\nSELECT historize_table_clean('public','alpha');\n```\n\n\n## Creating the partitions\n\n```sql\nSELECT historize_create_partition('public', 'alpha_log', 0);\n```\n\n## Dropping the partitions\n\n```sql\nSELECT historize_drop_partition('public', 'alpha_log', 0);\n```\n\n## Create partition manually with pg_cron\n\nThe data are stored in a partitioned table to ease the removal of old\ndata, be sure to create enough partition.\n\nIf you want to automatically create partition with [pg_cron](https://github.com/citusdata/pg_cron) you can add\nthe following commands\n\n\n```sql\nSELECT cron.schedule_in_database(\n  'create-part_1', '00 08 * * *',\n  $$SELECT historize_create_partition('my_table', generate_series(1, 4) )$$,\n  'my_database');\n\nSELECT cron.schedule_in_database(\n  'create-part_1', '00 08 * * *',\n  $$SELECT historize_drop_partition('my_table', generate_series(-8, -4) )$$,\n  'my_database');\n```\n\n## Create foreign server\n\nIn case of the extension pg_cron is installed in another database you\ncan automaticcaly create the entries through foreign data wrapper.\n\nBe aware of adding the right `search_path` option if the pg_cron extension is not set in public schema. By default pg_cron is installed in the schema named `cron`\n\n```sql\nCREATE EXTENSION dblink;\nCREATE EXTENSION postgres_fdw;\n\nCREATE SERVER historize_foreign_cron\n        FOREIGN DATA WRAPPER dblink_fdw\n        OPTIONS (host 'localhost', port '5432', dbname 'postgres', options '-csearch_path=cron');\n\nCREATE USER MAPPING FOR local_user\n        SERVER historize_foreign_cron\n        OPTIONS (user 'foreign_user', password 'password');\n```\n\n## Update the extension on AWS RDS with pg_tle\n\nIn this example we will upgrade the extension from version 1.0.0 to 1.0.1\n\nRun the upgrade script in your instance and do an ALTER EXTENSION\n\n```sql\nuser@database=\u003e \\i pgtle.data_historization-1.0.0--1.0.1.sql\n install_update_path\n---------------------\n t\n(1 row)\n\nuser@database=\u003e ALTER EXTENSION data_historization UPDATE TO \"1.0.1\";\nALTER EXTENSION\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodo%2Fpostgresql-data-historization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodo%2Fpostgresql-data-historization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodo%2Fpostgresql-data-historization/lists"}