Skip to main content

PostgreSQL JDBC Catalog

Doris JDBC Catalog supports connecting to PostgreSQL databases via the standard JDBC interface. This document describes how to configure a PostgreSQL database connection.

For an overview of JDBC Catalog, please refer to: JDBC Catalog Overview

Usage Notes​

To connect to a PostgreSQL database, you need

  • PostgreSQL 11.x or higher

  • JDBC driver for PostgreSQL database, which you can download the latest or specified version from Maven Repository. It is recommended to use PostgreSQL JDBC Driver version 42.5.x or above.

  • Network connection between each FE and BE node of Doris and the PostgreSQL server, with the default port being 5432.

Connecting to PostgreSQL​

CREATE CATALOG postgresql_catalog PROPERTIES (
'type' = 'jdbc',
'user' = 'username',
'password' = 'pwd',
'jdbc_url' = 'jdbc:postgresql://host:5432/postgres',
'driver_url' = 'postgresql-42.5.6.jar',
'driver_class' = 'org.postgresql.Driver'
);

jdbc_url defines the connection information and parameters to be passed to the PostgreSQL JDBC driver. Supported URL parameters can be found in the PostgreSQL JDBC Driver Documentation.

Connection Security​

If you have configured TLS with a globally trusted certificate installed on the data source, you can enable TLS between the cluster and the data source by appending parameters to the JDBC connection string set in the jdbc_url property.

For example, for version 42 of the PostgreSQL JDBC driver, enable TLS by adding the ssl=true parameter to the jdbc_url configuration property:

"jdbc_url"="jdbc:postgresql://example.net:5432/database?ssl=true"

For more information on TLS configuration options, please refer to the PostgreSQL JDBC Driver Documentation.

Hierarchical Mapping​

When mapping PostgreSQL, a Database in Doris corresponds to a Schema under a specified database in PostgreSQL (as in the example jdbc_url parameter under postgres). A Table under a Database in Doris corresponds to Tables under that Schema in PostgreSQL. The mapping relationship is as follows:

DorisPostgreSQL
CatalogDatabase
DatabaseSchema
TableTable

Column Type Mapping​

PostgreSQL TypeDoris Type
booleanboolean
smallint/int2smallint
integer/int4int
bigint/int8bigint
decimal/numericdecimal(P, S) / stringNumeric without precision will be mapped to string type, and needs to be converted to decimal type for numerical calculations, and does not support write-back.
real/float4float
doubledouble
smallserialsmallint
serialint
bigserialbigint
char(N)char(N)
varchar/textstring
timestamp(S)/timestampz(S)datetime(S)
datedate
json/jsonbstringFor better reading and computing performance balance, Doris maps JSON type to STRING type.
timestringDoris does not support time type, time type will be mapped to string.
intervalstring
point/line/lseg/box/path/polygon/circlestring
cidr/inet/macaddrstring
uuidstring
bitboolean / stringDoris does not support bit type, bit type will be mapped to boolean when bit(1), otherwise mapped to string.
otherUNSUPPORTED

Appendix​

Time Zone Issues​

Since Doris does not support timestamp types with time zones, when reading the timestampz type from PostgreSQL, Doris will map it to DATETIME type and convert it to local time zone time when reading.

And because when reading data from JDBC type Catalog, the Java part of BE uses the JVM time zone. The JVM time zone defaults to the time zone of the BE deployment machine, which affects the time zone conversion when JDBC reads data.

To ensure time zone consistency, it is recommended to set the JVM time zone in JAVA_OPTS of be.conf to be consistent with the time_zone of Doris session.