Connecting Cube.js to Superset (PostgreSQL SQL API)
Goal
Connect Apache Superset to Cube.js using Cube's PostgreSQL SQL API on port 15432, allowing Superset to query Cube.js pre-aggregated data.
Prerequisites
- Cube.js project configured to expose the PostgreSQL SQL API
- Superset installed in a Python virtual environment
- PostgreSQL driver (
psycopg2) installed in Superset's environment
1. Cube.js Configuration
In your .env file for Cube.js, enable the SQL API and point it at your source database:
CUBEJS_PG_SQL_PORT=15432
CUBEJS_DB_TYPE=postgres
CUBEJS_DB_HOST=localhost
CUBEJS_DB_PORT=5432
CUBEJS_DB_NAME=demodb
CUBEJS_DB_USER=postgres
CUBEJS_DB_PASS=password
CUBEJS_DB_SCHEMA=demodata
The SQL API implements the PostgreSQL wire protocol, so any PostgreSQL client — including Superset — can connect to Cube.js as if it were a database. Queries written against your Cube data model are then answered using pre-aggregations.
2. Connect Superset to the SQL API
- Open Superset and go to Settings → Database Connections → + Database.
- Select PostgreSQL as the database type.
- Fill in the connection details:
- Host: the machine running Cube.js (e.g.,
localhost) - Port:
15432(the SQL API port) - Database name: your Cube.js database name
- Username / Password: the Cube.js credentials your project defines
- Host: the machine running Cube.js (e.g.,
- Click Test Connection to verify, then save.
3. Verify from the Command Line
Before touching Superset, confirm the API responds like a PostgreSQL server:
psql -h localhost -p 15432 -U <DB_USER> -d <DB_NAME>
If psql connects and \dt lists tables from your Cube
data model, Superset will be able to query the same endpoint.
Troubleshooting
- Connection refused on 15432: the SQL API is not enabled or the server was started before you set
CUBEJS_PG_SQL_PORT— restart Cube.js after editing.env. - Authentication errors in Superset: the SQL API uses your Cube.js credentials, not the PostgreSQL database credentials.
- Empty table list in Superset: make sure the schema shown is the one your data model uses, then click Edit → refresh metadata.