electric-sql / pglite

Lightweight WASM Postgres with real-time, reactive bindings.
https://pglite.dev
Apache License 2.0
8.32k stars 164 forks source link

Validate that dbdata dir is of the correct PG version when starting. #12

Open nbbaier opened 7 months ago

nbbaier commented 7 months ago

I have a data directory that I initialized with initdb. When I try to run the example connecting to that data directory, the Promise returned by db.query(...) never resolves. Here's the code:

import { PGlite } from "@electric-sql/pglite";

const db = new PGlite("./pgdata");

await db.waitReady;

const result = await db.query("select 'Hello world' as message;");

console.log(result);

await db.close();

EDIT: I just realized that this is most likely because there is a difference in the version of postgres that created the dbs:

// created by installed initdb command on my machine
PostgreSQL 16.0 on aarch64-apple-darwin21.6.0, compiled by Apple clang version 14.0.0 (clang-1400.0.29.102), 64-bit

// created by pglite
PostgreSQL 15devel on aarch64-apple-darwin22.6.0, compiled by emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.25 (febd44b21ecaca86e2cb2a25ef3ed4a0a2076365), 32-bit

It would be nice to include an error for this type of thing. Are there plans for this to be resolved?

samwillis commented 7 months ago

Hey, yep, PGlite is using v15 and there is no compatibility between major pg versions data stores. We need to improve error handling in this situation.

thanks for the report.