{"id":13647648,"url":"https://github.com/wasmerio/wasmer-postgres","last_synced_at":"2025-06-25T14:05:14.021Z","repository":{"id":45374189,"uuid":"191937949","full_name":"wasmerio/wasmer-postgres","owner":"wasmerio","description":"💽🕸 Postgres library to run WebAssembly binaries.","archived":false,"fork":false,"pushed_at":"2020-12-10T00:53:20.000Z","size":86,"stargazers_count":419,"open_issues_count":3,"forks_count":16,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-06-22T06:15:24.799Z","etag":null,"topics":["postgres","postgresql","postgresql-extension","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://medium.com/wasmer/announcing-the-first-postgres-extension-to-run-webassembly-561af2cfcb1","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wasmerio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-14T12:17:30.000Z","updated_at":"2025-06-16T01:40:38.000Z","dependencies_parsed_at":"2022-07-20T05:00:18.962Z","dependency_job_id":null,"html_url":"https://github.com/wasmerio/wasmer-postgres","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/wasmerio/wasmer-postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasmerio","download_url":"https://codeload.github.com/wasmerio/wasmer-postgres/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-postgres/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261888088,"owners_count":23225138,"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":["postgres","postgresql","postgresql-extension","wasm","webassembly"],"created_at":"2024-08-02T01:03:41.271Z","updated_at":"2025-06-25T14:05:13.999Z","avatar_url":"https://github.com/wasmerio.png","language":"Rust","readme":"# \u003cimg height=\"48\" src=\"https://wasmer.io/images/icons/favicon-96x96.png\" alt=\"Wasmer logo\" valign=\"middle\"\u003e Wasmer Postgres [![Wasmer Slack Channel](https://img.shields.io/static/v1?label=chat\u0026message=on%20Slack\u0026color=green)](https://slack.wasmer.io)\n\n\nA complete and mature WebAssembly runtime for Postgres based on [Wasmer](https://wasmer.io).\nIt's an original way to extend your favorite database capabilities.\n\nFeatures:\n\n  * **Easy to use**: The `wasmer` API mimics the standard WebAssembly API,\n  * **Fast**: `wasmer` executes the WebAssembly modules as fast as\n    possible, close to **native speed**,\n  * **Safe**: All calls to WebAssembly will be fast, but more\n    importantly, completely safe and sandboxed.\n\n\u003e Note: The project is still in heavy development. This is a\n0.1.0 version. Some API are missing and are under implementation. But\nit's fun to play with it.\n\n# Installation\n\nThe project comes in two parts:\n\n  1. A shared library, and\n  2. A PL/pgSQL extension.\n  \nTo compile the former, run `just build` (Postgres server headers are\nrequired, see `pg_config --includedir-server`). To install the latter,\nrun `just install`. After that, run `CREATE EXTENSION wasm` in a\nPostgres shell. A new function will appear: `wasm_init`; it must be\ncalled with the absolute path to the shared library. It looks like\nthis:\n\n```shell\n$ # Build the shared library.\n$ just build\n\n$ # Install the extension in the Postgres tree.\n$ just install\n\n$ # Activate and initialize the extension.\n$ just host=$host database=$database activate\n```\n\nAnd you are ready to go!\n\n*Note*: On macOS, the shared library extension is `.dylib`, on Windows,\nit is `.dll`, and on other distributions, it is `.so`.\n\n*Note 2*: Yes, you need [`just`][just].\n\n## Supported Postgres versions\n\nSo far, the extension works on Postgres 10 only. It doesn't work with\nPostgres 11 _yet_ ([follow this issue if you want to learn\nmore][pg-extend-rs-issue-49]). Any help is welcomed!\n\n[just]: https://github.com/casey/just/\n[pg-extend-rs-issue-49]: https://github.com/bluejekyll/pg-extend-rs/issues/49\n\n# Usage \u0026 documentation\n\nConsider the `examples/simple.rs` program:\n\n```rust\n#[no_mangle]\npub extern fn sum(x: i32, y: i32) -\u003e i32 {\n    x + y\n}\n```\n\nOnce compiled to WebAssembly, one obtains a similar WebAssembly binary\nto `examples/simple.wasm` ([download it][download-simple-wasm]). To\nuse the `sum` exported function, first, create a new instance of the\nWebAssembly module, and second, call the `sum` function.\n\nTo instantiate a WebAssembly module, the `wasm_new_instance` function\nmust be used. It has two arguments:\n\n  1. The absolute path to the WebAssembly module, and\n  2. A namespace used to prefix exported functions in SQL.\n\nFor instance, calling\n`wasm_new_instance('/path/to/simple.wasm', 'ns')` will create the\n`ns_sum` function that is a direct call to the `sum` exported function\nof the WebAssembly instance. Thus:\n\n```sql\n-- New instance of the `simple.wasm` WebAssembly module.\nSELECT wasm_new_instance('/absolute/path/to/simple.wasm', 'ns');\n\n-- Call a WebAssembly exported function!\nSELECT ns_sum(1, 2);\n\n--  ns_sum\n-- --------\n--       3\n-- (1 row)\n```\n\nIsn't it awesome? Calling Rust from Postgres through WebAssembly!\n\nLet's inspect a little bit further the `ns_sum` function:\n\n```sql\n\\x\n\\df+ ns_sum\nSchema              | public\nName                | ns_sum\nResult data type    | integer\nArgument data types | integer, integer\nType                | normal\nVolatility          | volatile\nParallel            | unsafe\nOwner               | …\nSecurity            | invoker\nAccess privileges   |\nLanguage            | plpgsql\nSource code         | …\nDescription         |\n```\n\nThe Postgres `ns_sum` signature is `(integer, integer) -\u003e integer`,\nwhich maps the Rust `sum` signature `(i32, i32) -\u003e i32`.\n\nSo far, only the WebAssembly types `i32`, `i64` and `v128` are\nsupported; they respectively map to `integer`, `bigint` and `decimal`\nin Postgres. Floats are partly implemented for the moment.\n\n[download-simple-wasm]: https://github.com/wasmerio/postgres-ext-wasm/blob/master/examples/simple.wasm\n\n## Inspect a WebAssembly instance\n\nThe extension provides two foreign data wrappers, gathered together in\nthe `wasm` foreign schema:\n\n  * `wasm.instances` is a table with the `id` and `wasm_file` columns,\n    respectively for the instance ID, and the path of the WebAssembly\n    module,\n  * `wasm.exported_functions` is a table with the `instance_id`,\n    `name`, `inputs` and `output` columns, respectively for the\n    instance ID of the exported function, its name, its input types\n    (already formatted for Postgres), and its output types (already\n    formatted for Postgres).\n\nLet's see:\n\n```sql\n-- Select all WebAssembly instances.\nSELECT * FROM wasm.instances;\n\n--                   id                  |          wasm_file\n-- --------------------------------------+-------------------------------\n--  426e17af-c32f-5027-ad73-239e5450dd91 | /absolute/path/to/simple.wasm\n-- (1 row)\n\n-- Select all exported functions for a specific instance.\nSELECT\n    name,\n    inputs,\n    outputs\nFROM\n    wasm.exported_functions\nWHERE\n    instance_id = '426e17af-c32f-5027-ad73-239e5450dd91';\n\n--   name  |     inputs      | outputs\n-- --------+-----------------+---------\n--  ns_sum | integer,integer | integer\n-- (1 row)\n```\n\n# Benchmarks\n\nBenchmarks are useless most of the time, but it shows that WebAssembly\ncan be a credible alternative to procedural languages such as\nPL/pgSQL. Please, don't take those numbers for granted, it can change\nat any time, but it shows promising results:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eBenchmark\u003c/th\u003e\n      \u003cth\u003eRuntime\u003c/th\u003e\n      \u003cth align=\"right\"\u003eTime (ms)\u003c/th\u003e\n      \u003cth align=\"right\"\u003eRatio\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd rowspan=\"2\"\u003eFibonacci (n = 50)\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003epostgres-ext-wasm\u003c/code\u003e\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e0.206\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e1×\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ePL/pgSQL\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e0.431\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e2×\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd rowspan=\"2\"\u003eFibonacci (n = 500)\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003epostgres-ext-wasm\u003c/code\u003e\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e0.217\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e1×\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ePL/pgSQL\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e2.189\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e10×\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd rowspan=\"2\"\u003eFibonacci (n = 5000)\u003c/td\u003e\n      \u003ctd\u003e\u003ccode\u003epostgres-ext-wasm\u003c/code\u003e\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e0.257\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e1×\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ePL/pgSQL\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e18.643\u003c/td\u003e\n      \u003ctd align=\"right\"\u003e73×\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n# Test\n\nOnce the library is built, run the following commands:\n\n```shell\n$ just pg-start\n$ just test\n```\n\n# License\n\nThe entire project is under the MIT License. Please read [the `LICENSE` file][license].\n\n[license]: https://github.com/wasmerio/wasmer/blob/master/LICENSE\n","funding_links":[],"categories":["Rust","WASM","\u003ca name=\"Rust\"\u003e\u003c/a\u003eRust"],"sub_categories":["Logical Replication"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Fwasmer-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasmerio%2Fwasmer-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Fwasmer-postgres/lists"}