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

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

  1. Open Superset and go to Settings → Database Connections → + Database.
  2. Select PostgreSQL as the database type.
  3. 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
  4. 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

Related Articles

A.M. Rinas

Written by A.M. Rinas

Full-Stack Software Engineer working on web applications, DevOps automation, and databases. More about me on the about page, or say hi through the contact page and LinkedIn.

← Back to all articles