PostgreSQL wire protocol
If a node is started with postgres support enabled it will bind to port 5432
by default. To use a custom port, set the corresponding Ports in the .
However, even though connecting PostgreSQL tools and client libraries is supported, the actual SQL statements have to be supported by CrateDB’s SQL dialect. A notable difference is that CrateDB doesn’t support transactions, which is why clients should generally enable autocommit
.
Note
In order to use setFetchSize
in JDBC it is possible to set autocommit to false.
The client will utilize the fetchSize on SELECT statements and only load up to fetchSize rows into memory.
See the PostgreSQL JDBC Query docs for more information.
Write operations will still behave as if autocommit was enabled and commit or rollback calls are ignored.
CrateDB emulates PostgreSQL server version 10.5
.
SSL Support
SSL can be configured using .
Authentication methods can be configured using Host-Based Authentication (HBA).
ParameterStatus
After the authentication has succeeded the server has the possibility to send multiple ParameterStatus
messages to the client. These are used to communicate information like server_version
(emulates PostgreSQL 9.5) or server_encoding
.
CrateDB
also sends a message containing the crate_version
parameter. This contains the current CrateDB
version number.
This information is useful for clients to detect that they’re connecting to CrateDB
instead of a PostgreSQL instance.
Database selection
Since CrateDB uses schemas instead of databases, the database
parameter sets the default schema name for future queries. If no schema is specified, the schema doc
will be used as default. Additionally, the only supported charset is UTF8
.
Query Modes
Simple query
The protocol mode is fully implemented.
The PostgreSQL extended query protocol mode is implemented with the following limitations:
The
ParameterDescription
message works for the most common use cases except for DDL statements.To optimize the execution of bulk operations the execution of statements is delayed until the
Sync
message is received
Copy operations
CrateDB does not support the COPY
sub-protocol.
Function call
The sub-protocol is not supported since it’s a legacy feature.
Operations can be cancelled using the KILL
statement, hence the message is unsupported. Consequently, the server won’t send a BackendKeyData
message during connection initialization.
For improved compatibility, the pg_catalog
schema is implemented containing following tables:
Some clients require the pg_catalog.pg_type
in order to be able to stream arrays or other non-primitive types.
For compatibility reasons, there is a trimmed down pg_type table available in CrateDB:
Note
This is just a snapshot of the table. Check table to get information for all supported columns.
Object identifiers are used internally by PostgreSQL for various system tables. The oid
type is currently mapped to the integer data type.
The oid
type might have the following type aliases:
Note
Currently, casting a string or integer literal to the regproc
type wouldn’t result in a lookup. Instead, casting the string literal to the regproc
type results in an object of the regproc
type that has a name that corresponds to the string literal and the oid
hash of the literal as oid
. Casting an integer literal to the regproc
type results in an object of the regproc
type that has a name that corresponds to the string representation of the literal and the literal value as oid
.
For compatibility with JDBC the SHOW TRANSACTION ISOLATION LEVEL
statement is implemented:
CrateDB will silently ignore the COMMIT
, , and START
TRANSACTION statements and all respective parameters.
pgjdbc JDBC drivers version 9.4.1209
and above are compatible.
Limitations
reflection methods like
conn.getMetaData().getTables(...)
won’t work since the required tables are unavailable in CrateDB.As a workaround it’s possible to use
SHOW TABLES
or query theinformation_schema
tables manually usingSELECT
statements.OBJECT
andGEO_SHAPE
columns can be streamed asJSON
but require version9.4.1210
or newer.Multidimensional arrays will be streamed as
JSON
encoded string to avoid a protocol limitation where all sub-arrays are required to have the same length.The behavior of
PreparedStatement.executeBatch
in error cases depends on in which stage an error occurs: ABatchUpdateException
is thrown if no processing has been done yet, whereas single operations failing after the processing started are indicated by anEXECUTE_FAILED
(-3) return value.Transaction limitations as described above.
Connection failover and load balancing is supported as described here: PostgreSQL JDBC connection failover.
Note
It is not recommended to use the targetServerType parameter since CrateDB has no concept of master-replica nodes.
The PostgreSQL Wire Protocol makes it easy to use many PostgreSQL compatible tools and libraries directly with CrateDB. However, many of these tools assume that they are talking to PostgreSQL specifically, and thus rely on SQL extensions and idioms that are unique to PostgreSQL. Because of this, some tools or libraries may not work with other SQL databases such as CrateDB.
CrateDB’s SQL query engine enables real-time search & aggregations for online analytic processing (OLAP) and business intelligence (BI) with the benefit of the ability to scale horizontally. The use-cases of CrateDB are different than those of PostgreSQL, as CrateDB’s specialized storage schema and query execution engine address different requirements (see ).
The listed features below cover the main differences in implementation and dialect between CrateDB and PostgreSQL. A detailed comparison between CrateDB’s SQL dialect and standard SQL is defined in SQL compatibility.
COPY
CrateDB does not support the distinct sub-protocol that is used to serve COPY
operations and provides another implementation for transferring bulk data using the and COPY TO statements.
The definition of structured values by using JSON
types, composite types or HSTORE
are not supported. CrateDB alternatively allows the definition of nested documents (of type ) that store fieldscontaining any CrateDB supported data type, including nested object types.
CrateDB accepts the Type conversion syntax for conversion of one data type to another.
See also
Arrays
Declaration of arrays
While multidimensional arrays in PostgreSQL must have matching extends for each dimension, CrateDB allows different length nested arrays as this example shows:
Accessing arrays
Fetching arbitrary rectangular slices of an array using in the array subscript is not supported.
See also
Text search functions and operators
The and operators provided by PostgreSQL for (see PostgreSQL Fulltext Search) are not compatible with those provided by CrateDB.
If you are missing features, functions or dialect improvements and have a great use case for it, let us know on . We’re always improving and extending CrateDB and we love to hear feedback.