Postgres Drivers and Compatibility
XTDB supports the Postgres wire protocol and is therefore compatible with several Postgres tools. However, XTDB is not designed to support drop-in replacement with Postgres and full compatibility with Postgres is not a goal for XTDB.
More specifically, whilst XTDB offers some level of compatibility with Postgres’ actual SQL dialect, there are many syntactic and functional capabilities which Postgres offers that are not supported in XTDB, and users should generally always refer to XTDB’s SQL documentation.
The advantage of embracing wire protocol compatibility is that many PostgreSQL clients or drivers are able to connect to XTDB seamlessly and run many useful queries without issue. There will always be exceptions and this page will document them as comprehensively as possible.
Usage examples
This example uses the Psycopg 3 database adapter.
This example uses the postgres
package.
- Go
- Rust
- Want to help? Get in touch: hello@xtdb.com or feel free to open an issue!
Recommended third party tools
The following list of third party tools includes drivers, clients or utility CLIs/GUIs that our team has tested. Picking an item from it will help us to ensure that your code will work reliably with XTDB.
We recognize that our community might value some features more than others and we encourage you to open an issue on GitHub if you think we are missing something important for your language or workflow.
CLIs
GUIs
- VSCode’s SQLTools extension
Libraries / Programmatic clients
-
Postgres.js - explicit parameter typing is required for now due to how the library is designed (by default it places the burden of calculating all type information onto the database)
Drivers
Compatibility
Supported types
The definitive list of types and Postgres OIDs supported are available alongside other information in the pg_catalog
metadata schema:
Main caveats
- You can use
BEGIN
andCOMMIT
/ROLLBACK
to execute multiple statements in a single atomic transaction, however write-transactions are fundamentally non-interactive (see How XTDB works for details). Reads back to the client must take place in separate transactions. - JSON-ification of results - generic Postgres drivers can’t comprehensively handle the ‘polymorphic’ and nested types that XTDB supports internally, so many complex structures will be return using JSON columns.
Given the lack of DDL functionality present in XTDB currently (we’re working on it), it is therefore important that you control the data you insert into a given column if you want to avoid a monomorphic (simple) type being unexpectedly later returned as a JSON string because the type definition was inadvertently widened by an errant INSERT for an unrelated row. For example, if you INSERT row X with a number for column
foo
and then query it back you will see that same number, however if you then INSERT row Y with a string for columnfoo
now row X will now always return columnfoo
as string (i.e. it’s now JSON). This widening behaviour cannot be undone using the supported XTDB APIs. Please get in touch if you run into difficulties: hello@xtdb.com - Lack of
SHOW
and SQL ‘window functions’ precludes various tools from working. - Certain classes of error messages may be opaque to the client - it may therefore be best to debug queries using the HTTP API during the development workflow for now.
pg_catalog
is partially implemented but is only intended for interoperability with specific supported tools, please use the SQL standardinformation_schema
instead- Drivers which do not supply proper parameter type information for prepared statements (e.g.
node-postgres
) may not be suitable for production usage.
List of supported connection properties
Name | Example | Description |
---|---|---|
user | ignored_user | XTDB does not support users currently, but many clients require specifying a user - provide a dummy string |
password | ignored_password | XTDB does not support users currently (or their passwords), but many clients require specifying a password - provide a dummy string |