title: 'PostgreSQL Data Connector'
sidebar_label: 'PostgreSQL Data Connector'
description: 'PostgreSQL Data Connector Documentation'
PostgreSQL is an advanced open-source relational database management system known for its robustness, extensibility, and support for SQL compliance.
The PostgreSQL Server Data Connector enables federated/accelerated SQL queries on data stored in PostgreSQL databases.
Configuration
from
The from field takes the form postgres:my_table where my_table is the table identifer in the PostgreSQL server to read from.
The fully-qualified table name (database.schema.table) can also be used in the from field.
name
The dataset name. This will be used as the table name within Spice.
Example:
params
The connection to PostgreSQL can be configured by providing the following params:
| Parameter Name | Description |
|---|
pg_host | The hostname of the PostgreSQL server. |
pg_port | The port of the PostgreSQL server. |
pg_db | The name of the database to connect to. |
pg_user | The username to connect with. |
pg_pass | The password to connect with. Use the secret replacement syntax to load the password from a secret store, e.g. ${secrets:my_pg_pass}. |
pg_sslmode | Optional. Specifies the SSL/TLS behavior for the connection, supported values: verify-full: (default) This mode requires an SSL connection, a valid root certificate, and the server host name to match the one specified in the certificate.verify-ca: This mode requires a TLS connection and a valid root certificate.require: This mode requires a TLS connection.prefer: This mode will try to establish a secure TLS connection if possible, but will connect insecurely if the server does not support TLS.disable: This mode will not attempt to use a TLS connection, even if the server supports it. |
Types
The table below shows the PostgreSQL data types supported, along with the type mapping to Apache Arrow types in Spice.
| PostgreSQL Type | Arrow Type |
|---|
int2 | Int16 |
int4 | Int32 |
int8 | Int64 |
money | Int64 |
float4 | Float32 |
float8 | Float64 |
numeric | Decimal128 |
text | Utf8 |
varchar | |
:::info
The Postgres federated queries may result in unexpected result types due to the difference in DataFusion and Postgres size increase rules. Please explicitly specify the expected output type of aggregation functions when writing query involving Postgres table in Spice. For example, rewrite SUM(int_col) into CAST (SUM(int_col) as BIGINT.
:::
Examples
Connecting using Username/Password
Connect using SSL
Separate dataset/accelerator secrets
Specify different secrets for a PostgreSQL source and acceleration:
Secrets
Spice integrates with multiple secret stores to help manage sensitive data securely. For detailed information on supported secret stores, refer to the secret stores documentation. Additionally, learn how to use referenced secrets in component parameters by visiting the using referenced secrets guide.
Cookbook