Skip to main content

pgTAP Review

CategoryDatabase TestingFirst ReleasedNot statedOfficial SiteDeploymentSelf-hosted
Licensing Model
Free & Open Source
  • PostgreSQL licence (per PGXN)
  • No paid edition
  • pg_prove is a separate Perl tool
  • Installed as a database extension
Free Plan
Free
  • Everything is free
  • PostgreSQL 9.1 or newer
  • Tested on PostgreSQL 9.1 to 18
  • Available on Supabase
Maintainer
David E. Wheeler
  • Author and copyright holder, 2008โ€“2026
  • Community contributors on GitHub
  • Latest: v1.3.4, 4 Oct 2025
  • Distributed on PGXN and apt
Ratings
  • GitHub stars1.2K
  • G2N/A
  • GartnerN/A

Overview

pgTAP is a free, open-source unit testing framework for PostgreSQL, written in PL/pgSQL by David E. Wheeler. It adds a set of database functions that write test results in TAP (Test Anything Protocol) format, so tests can run inside the database itself and check views, functions, procedures, triggers and schema objects directly, without fetching results into application code first.

Tests are either SQL scripts wrapped in BEGIN and ROLLBACK with a plan() and finish(), or xUnit-style test functions run by runtests(), each in its own transaction that is rolled back. Assertions cover values (is, ok, matches), queries (results_eq, set_eq, throws_ok, performs_ok), the schema (has_table, col_type_is, tables_are) and privileges and row-level security policies (table_privs_are, policies_are). The pg_prove command-line tool runs whole test suites, including in parallel.

pgTAP fits PostgreSQL teams who keep logic or security rules in the database, including Supabase users testing row-level security. Buyers should note that it works only with PostgreSQL, that it must be installed on the database server by a superuser (it can't be installed remotely), that pg_prove needs Perl from CPAN, and that releases are infrequent: v1.3.4 came out in October 2025, with more changes waiting in the main branch.

Key Featuresโ€‹

Value and Query Assertionsโ€‹

Basic assertions include ok(), is(), isnt(), matches(), alike() and cmp_ok(). Query assertions include results_eq(), set_eq(), bag_eq(), row_eq(), is_empty(), throws_ok() and lives_ok().

Performance Assertionsโ€‹

performs_ok() and performs_within() fail a test when a query runs slower than a set time.

Schema Testsโ€‹

Existence functions such as has_table(), has_column(), has_pk(), has_fk() and col_type_is() check single objects, and contents functions such as tables_are(), columns_are() and functions_are() check that a schema has exactly the expected objects, listing any extra or missing.

Privilege and Policy Testsโ€‹

table_privs_are() checks grants. policies_are() checks that a table has exactly the expected row-level security policies, policy_roles_are() checks which roles a policy applies to, and policy_cmd_is() checks its command (SELECT, INSERT, UPDATE, DELETE or ALL).

xUnit-Style Testsโ€‹

Test functions return SETOF TEXT and are found and run by runtests(), with setup, teardown, startup and shutdown functions. Each test runs in its own transaction and is rolled back.

pg_proveโ€‹

pg_prove runs many test scripts or xUnit functions, filters them by schema or name pattern, runs jobs in parallel with --jobs, and can shuffle script order.

Best Selling Pointsโ€‹

  • Tests live in the database, next to the SQL they test.
  • Schema, privilege and row-level security assertions are built in.
  • Each test is rolled back, so test data doesn't leak.
  • Standard TAP output that many test harnesses read.
  • Free and installable from apt or PGXN.
  • Documented by Supabase for testing RLS policies.

Supported Integrationsโ€‹

Running Tests

  • pg_prove (CPAN)
  • psql
  • runtests()
  • TAP harnesses

Installation

  • PGXN
  • apt (Debian, Ubuntu, Linux Mint)
  • make install from source
  • Supabase extension

pgTAP is a community open-source project and doesn't publish a user list. Supabase documents it as an extension that can be enabled in its dashboard.

Supported Databasesโ€‹

pgTAP runs inside PostgreSQL.

  • PostgreSQL 11 and up: full
  • PostgreSQL 9.1 to 10: partial
  • Supabase

Database Detailsโ€‹

  • PostgreSQL only.
  • PostgreSQL 11 and up: everything works.
  • PostgreSQL 10 and below: no stored-procedure tests; 9.6 and below also lack partition tests; 9.4 and below don't trap ASSERT_FAILURE.
  • PostgreSQL 9.0 and below: no longer supported.
  • Tested range: v1.3.4 was tested on PostgreSQL 9.1 to 18, and the main branch has been tested on PostgreSQL 19 since June 2026.

How Tests Runโ€‹

  • Install: on the database server, install the package (for example sudo apt-get install pgtap, or make install from PGXN), then run CREATE EXTENSION pgtap; as a superuser in each database.
  • Script style: write SQL files that call plan(), the assertions and finish() inside a transaction that is rolled back, and run them with psql or pg_prove -d mydb tests/*.sql.
  • xUnit style: write test functions and run pg_prove -d mydb --runtests.
  • In CI: connect pg_prove with -d, -U, -h and -p or the standard PG* environment variables.
  • Example test:
BEGIN;
SELECT plan(3);

SELECT has_table('public', 'orders', 'orders table exists');
SELECT col_type_is('public', 'orders', 'total', 'numeric', 'total is numeric');
SELECT policies_are('public', 'orders', ARRAY['owner can read']);

SELECT * FROM finish();
ROLLBACK;

Reportingโ€‹

Key Reporting Featuresโ€‹

  • TAP output with one line per test and diagnostics on failure.
  • pg_prove --verbose shows each test's description.
  • pg_prove --archive saves raw TAP to a .tar or .tar.gz file.
  • Output formatting through pg_prove --formatter.

Security & Complianceโ€‹

pgTAP runs inside your own PostgreSQL database, so test data stays there. Installing the extension needs superuser rights, and it must be installed on the database host, not remotely. Its privilege and policy assertions help test access rules themselves. The project publishes no certifications.

Pricingโ€‹

pgTAP is free.

ComponentPriceLicence
pgTAP extension$0PostgreSQL licence (per PGXN)
pg_prove (TAP::Parser::SourceHandler::pgTAP)$0Open source, on CPAN
  • Your only costs are the database and CI compute.

Strengthsโ€‹

  • The standard unit testing tool for PostgreSQL.
  • Deep schema, privilege and RLS assertions.
  • Tests roll back automatically.
  • Works on a very wide range of PostgreSQL versions.
  • Simple TAP output.
  • Free, with a permissive licence.

Limitationsโ€‹

  • PostgreSQL only.
  • Needs superuser rights and installation on the database host.
  • pg_prove needs Perl and CPAN.
  • Infrequent releases: v1.3.4 (October 2025) is the latest, and later fixes wait in the main branch.
  • Effectively maintained by one main developer.
  • JUnit XML output isn't described in the pgTAP or pg_prove docs we read.

Best Fit Scenariosโ€‹

  • Teams with business logic in PostgreSQL functions, procedures and triggers.
  • Supabase and multi-tenant apps that rely on row-level security policies.
  • Teams that want to lock down schemas with exact tables_are-style checks.
  • DBAs checking grants and privileges in CI.
  • Projects testing migrations against a real PostgreSQL database.
  • Teams already using TAP-based test harnesses.