git_fdw
git_fdw · PostgreSQL Git Foreign Data Wrapper
Overview
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
git_fdw exposes commits from a local Git repository as a read-only PostgreSQL foreign table. It uses libgit2 and returns commit identity/message/timestamp plus insertion, deletion, and changed-file counts for a selected branch.
Core Workflow
Create the wrapper and an option-free server, then import a repository schema on PostgreSQL 9.5 or later:
On PostgreSQL 9.4, define the documented foreign-table columns manually. One foreign table addresses one repository/branch; combine multiple tables with views.
Options and Columns
path(required): repository path on the PostgreSQL server’s filesystem.branch(required): full Git reference to scan.git_search_path(optional): helps libgit2 locate its configuration.prefixapplies when importing the generated table name.- Commit columns include
sha1,message, authorname/email,commit_date,insertions,deletions, andfiles_changed.
Caveats
The PostgreSQL server account needs filesystem access to the repository; the FDW does not clone a remote URL or use a user mapping for credentials. Treat repository contents and commit metadata as server-side data, and expose the foreign table only to roles allowed to read them.
IMPORT FOREIGN SCHEMA does not support LIMIT TO or EXCEPT. Version 1.1.0 targets libgit2 through 0.27 and old PostgreSQL versions, so current libgit2/PostgreSQL compatibility must be validated from the actual package. Queries walk repository history and compute diff statistics; use limits and measure cost on large histories.