PostgreSQL 18 compatible

In-memory PostgreSQL
for Java testing

No Docker, no external processes, no native binaries. Add the dependency, write tests against real PostgreSQL SQL.


com.memgres:memgres-junit5:0.1.0 Copied!
9,500+
Passing tests
200+
Built-in functions
80+
System catalog tables
0
External processes
MyTest.java
@MemgresTest
class MyTest {

    @Test
    void insertAndQuery(Connection conn) throws SQLException {
        conn.createStatement().execute(
            "CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT NOT NULL)");
        conn.createStatement().execute(
            "INSERT INTO users (name) VALUES ('Alice'), ('Bob')");

        ResultSet rs = conn.createStatement().executeQuery(
            "SELECT name FROM users ORDER BY id");
        rs.next();
        assertEquals("Alice", rs.getString(1));
    }
}
Real PostgreSQL, in-process
Implements the PostgreSQL wire protocol v3. Your tests run the same SQL that runs in production.
Q

Full Query Support

JOINs, CTEs (recursive), window functions, GROUPING SETS, DISTINCT ON, LATERAL, subqueries, set operations.

T

40+ Data Types

Numeric, text, boolean, date/time, UUID, JSON/JSONB, arrays, enums, composites, ranges, geometric, network, XML.

F

200+ Functions

String, math, date/time, JSON, array, full-text search, geometric, network, range, XML, and aggregate functions.

P

PL/pgSQL

Stored procedures, DO blocks, control flow, exception handling, cursors, RAISE, GET DIAGNOSTICS, IN/OUT parameters.

D

pg_dump Compatible

Works with real pg_dump and pg_restore. Custom, directory, plain, and tar formats. Full round-trip data integrity.

X

Transactions & Locking

BEGIN/COMMIT/ROLLBACK, savepoints, 3 isolation levels, SELECT FOR UPDATE/SHARE, SKIP LOCKED, deadlock detection.

S

Security

Roles, GRANT/REVOKE, ALTER DEFAULT PRIVILEGES, row-level security policies.

C

System Catalogs

80+ pg_catalog tables and 13+ information_schema views. Compatible with ORMs, Flyway, Liquibase, and introspection tools.

M

Multiple Databases

CREATE, DROP, ALTER DATABASE with full isolation. DROP WITH (FORCE), RENAME TO, auto-create on connect, configurable defaults.

N

LISTEN / NOTIFY

Channel-based notifications with full transaction semantics. Deferred until COMMIT, discarded on ROLLBACK.

A PostgreSQL server in three lines
Start a full PostgreSQL-compatible server from plain Java. Connect with psql, DBeaver, your app — anything that speaks PostgreSQL.
Standalone.java
try (Memgres db = Memgres.builder().port(5432).build().start()) {
    System.out.println(db.getJdbcUrl());  // jdbc:postgresql://localhost:5432/memgres
    Thread.currentThread().join();         // keep running
}
How Memgres compares
Choose Memgres when you want fast, zero-dependency PostgreSQL tests. Choose Testcontainers when you need 100% fidelity.
Memgres Testcontainers H2 (PG mode) embedded-postgres
Docker required No Yes No No
Native binary No No No Downloads PG
Startup time Milliseconds Seconds Milliseconds Seconds
Wire protocol Real PG v3 Real PG H2 protocol Real PG
pg_dump compatible Yes Yes No Yes
SQL fidelity PG 18 subset Full PG Partial Full PG
System catalogs 80+ tables Full PG Limited Full PG
PL/pgSQL Yes Yes No Yes
CI-friendly No deps Needs Docker No deps Needs network
What Memgres does not support
Memgres is designed for testing, not production. These PostgreSQL features are not implemented.
No persistence — fully in-memory by design
Btree indexes only (no GiST, GIN, BRIN)
Extensions parsed but not loaded (no PostGIS, pg_trgm)
No replication (WAL, streaming, or logical)
No foreign data wrappers or foreign tables
No tablespaces
No SSL/TLS connections
pg_stat_* tables are stubs (no real statistics)
No parallel query execution
Parallel pg_dump/pg_restore not yet supported
Basic collation only (no ICU)
No cross-database queries (same as PostgreSQL)
Up and running in 60 seconds
Add the dependency, annotate your test class, and go.
pom.xml
<dependency>
    <groupId>com.memgres</groupId>
    <artifactId>memgres-junit5</artifactId>
    <version>0.1.0</version>
    <scope>test</scope>
</dependency>
Requires Java 8+ and the PostgreSQL JDBC driver on the test classpath.