{"id":17196398,"url":"https://github.com/darold/pg_statement_rollbackv2","last_synced_at":"2025-03-25T08:15:02.021Z","repository":{"id":145546299,"uuid":"315000255","full_name":"darold/pg_statement_rollbackv2","owner":"darold","description":"[POC] PostgreSQL full server side statement-level rollback (require command-start-finish-hook-v1.patch on PostgreSQL sources)","archived":false,"fork":false,"pushed_at":"2021-08-10T08:30:58.000Z","size":32,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-30T07:29:16.636Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darold.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-22T09:21:23.000Z","updated_at":"2023-07-25T14:41:04.000Z","dependencies_parsed_at":"2023-04-12T15:32:00.955Z","dependency_job_id":null,"html_url":"https://github.com/darold/pg_statement_rollbackv2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Fpg_statement_rollbackv2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Fpg_statement_rollbackv2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Fpg_statement_rollbackv2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darold%2Fpg_statement_rollbackv2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darold","download_url":"https://codeload.github.com/darold/pg_statement_rollbackv2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245423251,"owners_count":20612749,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-10-15T01:53:06.667Z","updated_at":"2025-03-25T08:15:01.970Z","avatar_url":"https://github.com/darold.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## [POC] Full server side rollback at statement level for PostgreSQL\n\n```\n ^  Require that patch command-start-hook-v5.patch be applied to PostgreSQL source\n/!\\ code to add the necessary hooks. This is a proof od concept extension to show\n--- the utility of these hooks.\n```\n\n* [Description](#description)\n* [Installation](#installation)\n* [Configuration](#configuration)\n* [Use of the extension](#use-of-the-extension)\n* [Performances](#performances)\n* [Authors](#authors)\n* [License](#license)\n\n### [Description](#description)\n\npg_statement_rollback is a PostgreSQL extension to add server side\ntransaction with rollback at statement level like in Oracle or DB2.\n\nIf at any time during execution a SQL statement causes an error, all\neffects of the statement are rolled back. The effect of the rollback\nis as if that statement had never been run. This operation is called\nstatement-level rollback and has the following characteristics:\n\n- A SQL statement that does not succeed causes the loss only of work\n  it would have performed itself. The unsuccessful statement does\n  not cause the loss of any work that preceded it in the current\n  transaction.\n- The effect of the rollback is as if the statement had never been\n  run.\n\nIn PostgreSQL the transaction cannot continue when you encounter\nan error and the entire work done in the transaction is rolled back.\nOracle or DB2 have implicit savepoint before each statement execution\nwhich allow a rollback to the state just before the statement failure.\n\nThe pg_statement_rollback extension execute the automatic savepoint at\nserver side which adds a very limited penalty to the performances\n(see \"Performances\" chapter below). The rollback to the last successful\nstatement state is entirely driven at server side, the client doesn't\nhave to take care of the rolling back.\n\n    BEGIN;\n    CREATE TABLE savepoint_test(id integer);\n    INSERT INTO savepoint_test SELECT 1;\n    SELECT COUNT( * ) FROM savepoint_test; -- return 1\n    INSERT INTO savepoint_test SELECT 'wrong 1'; -- generate an error\n    SELECT COUNT( * ) FROM savepoint_test; -- still return 1\n    COMMIT;\n\nWithout the extension everything will be cancelled and statement after\nthe error on INSERT will return:\n\n    ERROR:  current transaction is aborted, commands ignored until end of transaction block\n\nHere is the output of the test with statement-level rollback enabled:\n\n    BEGIN\n    CREATE TABLE\n    INSERT 0 1\n     count \n    -------\n         1\n    (1 row)\n    \n    psql:toto.sql:9: ERROR:  invalid input syntax for type integer: \"wrong 1\"\n    LINE 1: INSERT INTO savepoint_test SELECT 'wrong 1';\n                                              ^\n     count \n    -------\n         1\n    (1 row)\n    \n    COMMIT\n\n\n### [Installation](#installation)\n\nTo install the pg_statement_rollback extension you need at least a\nPostgreSQL version 14. Untar the pg_statement_rollback tarball\nanywhere you want then you'll need to compile it with PGXS.  The\n`pg_config` tool must be in your path.\n\nDepending on your installation, you may need to install some devel\npackage. Once `pg_config` is in your path, do\n\n    make\n    sudo make install\n\nTo run test execute the following command as superuser:\n\n    make installcheck\n\n### [Configuration](#configuration)\n\n#### Server side automatic savepoint\n\n- *pg_statement_rollback.enabled*\n\nThe extension can be enable / disable using this GUC, default is\nenabled. To disable the extension use:\n\n    SET pg_statement_rollback.enabled TO off;\n\nYou can disable or enable the extension at any moment in a session.\n\n### [Use of the extension](#use-of-the-extension)\n\nIn all session where you want to use pg_statement_rollback transaction with\nrollback at statement level you will have to load the extension using:\n\n* LOAD 'pg_statement_rollback.so';\n* SET pg_statement_rollback.enabled TO on;\n\nThen when an error is encountered in a transaction the extension will\nautomatically rollback to the state of the last successfull statement\ninstead of rolling back the entire transaction and will continue the\nrunning transaction just like if there was no error.\n\nIf you want to generalize the use of the extension modify your postgresql.conf\nfile to set\n\n    session_preload_libraries = 'pg_statement_rollback'\n\nand add\n\n    pg_statement_rollback.enabled = on\n\nat end of the file.\n\nSee files in test/sql/ for some examples of use.\n\n\n### [Performances](performances)\n\nTo see the real overhead of loading the extension here is some pgbench\nin tpcb-like scenario, best of three runs.\n\n* Without loading the extension\n\n```\n$ pgbench -h localhost bench -c 20 -j 8 -T 30\nstarting vacuum...end.\ntransaction type: \u003cbuiltin: TPC-B (sort of)\u003e\nscaling factor: 1\nquery mode: simple\nnumber of clients: 20\nnumber of threads: 8\nduration: 30 s\nnumber of transactions actually processed: 20454\nlatency average = 29.366 ms\ntps = 681.067975 (including connections establishing)\ntps = 681.146941 (excluding connections establishing)\n```\n\n* With the use of the extension\n\n```\n$ pgbench -h localhost bench -c 20 -j 8 -T 30\nstarting vacuum...end.\ntransaction type: \u003cbuiltin: TPC-B (sort of)\u003e\nscaling factor: 1\nquery mode: simple\nnumber of clients: 20\nnumber of threads: 8\nduration: 30 s\nnumber of transactions actually processed: 19716\nlatency average = 30.464 ms\ntps = 656.514964 (including connections establishing)\ntps = 656.586600 (excluding connections establishing)\n```\n\n### [Authors](#authors)\n\n- Julien Rouhaud\n- Dave Sharpe\n- Gilles Darold\n\n\n### [License](#license)\n\nThis extension is free software distributed under the PostgreSQL\nLicense.\n\n    Copyright (c) 2020 LzLabs, GmbH\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarold%2Fpg_statement_rollbackv2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarold%2Fpg_statement_rollbackv2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarold%2Fpg_statement_rollbackv2/lists"}