PostgreSQL compatibility
RasterizedDB speaks the PostgreSQL wire protocol and a large part of PostgreSQL's SQL, so most applications, drivers and ORMs written for PostgreSQL connect to it unchanged. This page says what to expect when you point an existing PostgreSQL application at RasterizedDB: what works, what is accepted but has no effect, what behaves differently, and what is not available.
What a PostgreSQL client gets
The PostgreSQL listener is off by default. Start the server with --protocol pgwire or --protocol both, then connect with any PostgreSQL client. See Connecting for ports, TLS and connection strings.
| Area | What the server provides |
|---|---|
| Protocol | Protocol version 3: the simple query protocol (several statements in one string) and the extended query protocol (Parse/Bind/Describe/Execute), with parameters and results in text or binary format. |
| Batches | Several extended-protocol statements sent with one Sync, as Npgsql batches them. An error skips the rest of the batch, as in PostgreSQL. |
| Fetching in pages | An Execute with a row limit returns that many rows and suspends the portal, so JDBC fetchSize and tokio-postgres portals fetch large results in pieces. |
| Cancelling | Cancel requests stop the running statement (57014). See Cancelling a statement. |
| Logins | SCRAM-SHA-256 (default), MD5, cleartext password, peer on unix sockets, and TLS. See Security. |
| COPY | COPY … FROM STDIN and COPY … TO STDOUT in text, CSV and binary format. See Modifying data. |
| Notifications | LISTEN, UNLISTEN, NOTIFY and pg_notify(). See Notifications. |
| Errors | PostgreSQL's SQLSTATE codes. An integrity error names the constraint it broke, and an error about an unknown name carries its position in the statement. |
| Result metadata | Each result column is described with its PostgreSQL type OID and modifier, and, for a column read straight from a table, with that table and column, as drivers expect. |
| Catalogues | information_schema and the pg_catalog relations drivers, ORMs and psql read. See Listing what a database holds. |
At connect time the server reports these values, and SHOW returns the same:
| Parameter | Value |
|---|---|
server_version | 16.3 |
server_version_num | 160003 |
server_encoding, client_encoding | UTF8 |
TimeZone | UTC |
DateStyle | ISO, MDY |
IntervalStyle | postgres |
standard_conforming_strings | on |
integer_datetimes | on |
lc_collate, lc_ctype | C |
max_identifier_length | 63 |
Clients tested against the server
These clients are part of the server's own test suite. Other PostgreSQL clients use the same protocol and usually work too, but they are not tested.
| Client | What is tested |
|---|---|
psql | Statements, and \d and \d+ on tables. |
| sqlx (Rust) | Queries with bound parameters, transactions and savepoints, typed decoding of results, lock waits and timeouts. |
| tokio-postgres (Rust) | The same, plus portals fetched in pages, cancel requests, binary COPY, LISTEN/NOTIFY. |
| SeaORM (Rust) | Find by id, filtered and ordered queries, paging, inserts and updates including NULL, related-entity loads through joins. |
| pgjdbc 42.x (Java) | Its default prepareThreshold=5 switch to a named server-side statement, binary transfer, and re-preparing after a table is altered. |
| Npgsql 8 (.NET) | Batches with one Sync, automatic preparation, an error inside a batch. |
pg_dump and pg_restore | Dumping a RasterizedDB database for a restore into PostgreSQL or RasterizedDB. See Going the other way: pg_dump. |
MySQL and SQL Server clients can connect too, through their own front ends. See MySQL and SQL Server clients.
Moving an application over
-
Start the server with the PostgreSQL listener on:
shrasterizeddb --location /var/lib/rasterizeddb --protocol both -
Point the application's connection string at it. The listener requires TLS by default, so use
sslmode=require(or--pg-tls preferon the server for clients that cannot encrypt):textpostgres://rasterized:secret@127.0.0.1:5432/postgres?sslmode=require -
Run your migrations. Most DDL is transactional, so a migration that fails part-way leaves the schema as it was. A few statements are refused inside a transaction block; see DDL inside transactions.
-
Check the lists below, Not supported and Known differences, against what your application uses.
-
Handle
40001and40P01with a retry, as you would on PostgreSQL. See Write conflicts and retries.
To move existing data from a PostgreSQL server, see Import from PostgreSQL.
Prepared statements after a schema change
When another session alters a table after a driver has prepared and described a statement over it, the statement's result columns may no longer match what the driver cached. The session setting rdb.shape_change decides what the server does:
| Value | What the client gets |
|---|---|
auto (default) | The first stale execution fails with PostgreSQL's 0A000 cached plan must not change result type, which pgjdbc, Npgsql and psycopg answer by preparing again. If the client executes the same statement again without preparing it, the server sends the new column description before the rows from then on. |
error | Always 0A000, as PostgreSQL does. |
rowdescription | Never an error: the new column description is sent before the rows. |
Set it per session, in the startup options (options=-c rdb.shape_change=error), or per role with ALTER ROLE … SET. See Session settings.
Notifications: LISTEN and NOTIFY
Sessions of the same database can signal each other as on PostgreSQL:
-- session 1
LISTEN jobs;
-- session 2
NOTIFY jobs, 'job 17 is ready';
SELECT pg_notify('jobs', 'job 18 is ready');- A notification is delivered when the transaction that sent it commits, at once outside a block. A block that rolls back sends none.
- Within one transaction, the same payload on the same channel is delivered once.
- The sending session receives its own notifications if it listens on the channel.
- Notifications reach sessions of the same database only.
- A payload is limited to 8000 bytes (
22023above that). UNLISTEN channelstops one channel,UNLISTEN *all of them.
EXPLAIN
EXPLAIN and EXPLAIN ANALYZE return one QUERY PLAN text column, as on PostgreSQL, but the plan is RasterizedDB's own description of what it will do: the relations it scans, the filters pushed into each scan, hash joins and their keys, then grouping, sorting and the limit. It does not show PostgreSQL's node names, cost estimates or which index a scan will use. See Is my index used?.
EXPLAIN ANALYZEruns the statement, writes included, and adds the rows returned and the execution time.EXPLAIN (ANALYZE, VERBOSE)and the optionsCOSTS,BUFFERS,TIMING,SUMMARY,SETTINGS,WAL,SERIALIZE,MEMORYandGENERIC_PLANare accepted; the last group changes nothing.FORMAT JSON,FORMAT XMLandFORMAT YAMLare refused with0A000.
Session settings
SET, SET LOCAL, RESET, SHOW, current_setting() and set_config() work. What happens to a value depends on the parameter:
- A parameter the server acts on, such as
statement_timeout,lock_timeout,synchronous_commitor the transaction isolation level, takes effect. See Session settings and Transactions. - A parameter that describes how the server reads and writes values (
TimeZone,DateStyle,IntervalStyle,client_encoding,extra_float_digits,bytea_output) is accepted, butSHOWkeeps reporting what the server actually does. The session time zone is always UTC and text is always UTF-8. - Any other parameter, including
application_name,search_pathand custom names such asmyapp.tenant, is stored for the session, soSHOWandcurrent_setting()read back what you set.SET LOCALlasts until the end of the block;RESETandDISCARD ALLclear it.
search_path is reported but not followed: a database has one namespace, so an unqualified name always means the same object. See Schemas.
Accepted without effect
These statements and clauses succeed so that migrations and pg_dump output run, but they change nothing. The extension, schema, COMMENT ON, ANALYZE and unbuilt index statements are logged at info level as accepted without acting, so you can find them in the server log.
| Statement or clause | Why it has no effect |
|---|---|
CREATE EXTENSION, DROP EXTENSION | There is no extension mechanism. Functions such as gen_random_uuid() are built in; see Functions and operators. |
CREATE SCHEMA, DROP SCHEMA | A database has one namespace; a schema prefix on a name is ignored. |
COMMENT ON … | Comments are not stored; obj_description() and col_description() return NULL. |
ANALYZE | Statistics are kept automatically. A table that does not exist is still reported (42P01). |
CREATE INDEX … WHERE … (not unique), and expression indexes other than a JSON path or to_tsvector | Accepted and not built. See Indexes. |
CONCURRENTLY, INCLUDE, TABLESPACE, operator classes, ASC/DESC on an index | Accepted; the index orders by the engine's own comparison. |
ALTER TABLE … SET SCHEMA, SET TABLESPACE, SET LOGGED, SET UNLOGGED | Nothing to change. |
CREATE UNLOGGED TABLE | Creates an ordinary, logged table. |
DEFERRABLE, INITIALLY DEFERRED on a foreign key | Foreign keys are checked at each statement. |
SERIALIZABLE | Runs as REPEATABLE READ. See Isolation levels. |
Not supported
These are not available. A statement that uses one fails with an error, most often SQLSTATE 0A000: a function PostgreSQL has but RasterizedDB does not is refused with 0A000, and a function PostgreSQL does not have either is 42883, as on PostgreSQL.
Schema and DDL
- More than one namespace per database: two schemas cannot hold objects with the same name. Use separate databases where you need separation.
- Table inheritance (
INHERITS),CREATE TABLE … (LIKE …), andPARTITION BY RANGEorLIST. Tables partition by hash only; see Partitioning. UNIQUE NULLS NOT DISTINCT.- Composite and range types made with
CREATE TYPE, and multirange types. Enums and domains work. - Updatable views,
WITH CHECK OPTION,INSTEAD OFtriggers, andREFRESH MATERIALIZED VIEW CONCURRENTLY. - Functions in languages other than
sqlandplpgsql; function overloads that differ only in argument types; parameter defaults andOUT,INOUTandVARIADICparameters;ALTER FUNCTION. REINDEX.- A
tsvectorortsquerycolumn type.
Queries
- SQL cursors (
DECLARE … CURSOR,FETCH,CLOSE). Drivers that fetch in pages through the protocol work. FETCH … WITH TIES,TABLESAMPLE … REPEATABLE, and theSEARCHandCYCLEclauses of a recursive CTE.- Some forms of
LATERALand of correlated subqueries; see Querying data. EXPLAINformats other than text.
Functions and types
- SQL/JSON path (
jsonpath,@?,jsonb_path_*), thejsonbdelete operators-and#-,json_object_agg/jsonb_object_agg, and the SQL-standardJSON_TABLE,JSON_VALUE,JSON_QUERY,JSON_EXISTS,JSON_OBJECTandJSON_ARRAY. See JSON and JSONB. regexp_match,regexp_matches,regexp_instr,regexp_split_to_table, and regular-expression back-references and look-around. See Functions and operators.ts_rank_cd,ts_headlineandsetweight.row_to_json,to_number,date_bin,bit_and,bit_or, and the XML functions.- Advisory locks (
pg_advisory_lockand the rest) and large objects (lo_*). - NUMERIC
NaNand infinity, and NUMERIC values of more than 38 significant digits.
Server features
- PostgreSQL's replication protocol, logical decoding, publications and subscriptions. RasterizedDB has its own replication.
COPYto or from a file or program on the server. UseSTDINandSTDOUT.pg_stat_activity,pg_locks,pg_stat_user_indexesand the otherpg_stat_*views exceptpg_stat_user_tablesandpg_stat_statements. See Monitoring.- Two-phase commit (
PREPARE TRANSACTION). - A transaction or query across two databases.
Known differences
These work, but not exactly as on PostgreSQL. Each page linked has the details.
Names
- Unquoted names fold to lowercase and quoted names keep their case, as on PostgreSQL. Unlike PostgreSQL, a name also finds a table spelled in another case when no exact match exists, so two tables whose names differ only in case cannot both exist (
42P07). - Tables whose names begin with two underscores are left out of the catalogues, and some such prefixes are reserved for the server's own tables; do not use them. Column names beginning with
__null_are reserved. See Tables and data types.
Types and values
- Text compares and sorts by its bytes, which is PostgreSQL's
Ccollation, not the locale order a PostgreSQL server often defaults to. For case- or accent-insensitive comparison, declare a collation on the column; see Collations. - The session time zone is always UTC. A
timestamptzis shown with+00. See Dates and times. NUMERICis an exact fixed-point number of at most 38 significant digits. A result that needs more is refused rather than rounded. See Numbers.moneyis stored as anumericand shown as a plain number (12.5, not$12.50).- An enum column is sent to clients as
text, andinformation_schemareports it astext. A cast to a domain is typed as the domain's base type, andpg_typelists no domains. See Enum types and Domains.
Transactions and locking
SERIALIZABLEdoes not detect write skew; it runs asREPEATABLE READ.- A plain
SETinside a block that is rolled back is not undone.SET LOCALdoes end with its block. - A locking read (
FOR UPDATEand the others) waits at most 10 seconds for a row lock. - An
UPDATEorDELETEthat finds a row already locked byFOR UPDATEwhen it starts fails with55P03instead of waiting. - Concurrent upserts on one key can fail with
40001or40P01where PostgreSQL would wait. Retry them. - See Transactions.
Queries and writes
- CTEs are always computed once, in full, before the statement that reads them. A recursive CTE stops after 10,000 rounds or 10,000,000 rows.
- Joins run in memory within a budget (1024 MB by default); a join over it fails with
53200. - In set operations, a
datecolumn against atimestampcolumn, and an untyped string constant in the first branch beside a typed column in a later one, are refused. Add a cast. UPDATE … FROMandDELETE … USINGneed aWHEREand a target with a primary key or unique column.MERGE'sUPDATEandDELETEactions need a primary key on the target.- See Querying data and Modifying data.
Schema objects
- Comments are not stored, and triggers do not appear in
pg_trigger. - Triggers must use a
plpgsqlfunction. On a table with triggers,INSERT … ON CONFLICT,UPDATE … FROMandDELETE … USINGare refused. - PL/pgSQL covers a subset of the language. See PL/pgSQL statements.
- A serial or identity counter restarts above the largest value stored in its column after a restart.
pg_dumpdoes not dump functions, procedures, triggers, domains, grants or column collations.- See Schemas, views and other objects.
Indexes and full-text search
EXPLAINdoes not name the index a scan will use.bytea, array,interval,timetz, geometric and range columns cannot be indexed.- Only the
englishandsimpletext search configurations exist; any other name, such asgerman, is treated asenglishwithout an error. - The full-text word splitter is simpler than PostgreSQL's, so a few documents produce slightly different lexemes.
- See Indexes and Full-text search and collations.
Since 1.1.0 the server has row-level security (CREATE POLICY, ENABLE ROW LEVEL SECURITY), SECURITY DEFINER functions, and a wider set of operations on columns with case- or accent-insensitive collations (joins, GROUP BY, DISTINCT, min/max, set operations, foreign keys). In 1.0.1, CREATE POLICY is not available, SECURITY DEFINER is accepted and ignored, and those collation operations are refused with 0A000. See Row-level security and Collations.