Apache Superset With Postgresql

Zeeshan Tariq
4 min readMay 21, 2021

--

Superset:

Apache Superset is an open-source software cloud-native application for data exploration and data visualization able to handle data at petabyte scale. The application started as a hack-a-thon project by Maxime Beauchemin while working at Airbnb and entered the Apache Incubator program in 2017.

Install and Deploy Superset Locally with Docker:

Step 1: Clone Superset’s repo in your terminal with the following command:

$ git clone https://github.com/apache/superset.git

Step 2: Launch Superset Through Docker Compose:

Navigate to the folder you created in step 1:

$ cd superset

Then, run the following command:

$ docker-compose -f docker-compose-non-dev.yml up

You should see a wall of logging output from the containers being launched on your machine. Once this output slows, you should have a running instance of Superset on your local machine!

Note: This will bring up superset in a non-dev mode, changes to the codebase will not be reflected. If you would like to run superset in dev mode to test local changes, simply replace the previous command with: docker-compose up, and wait for the superset_node container to finish building the assets.

Configuring Docker Compose

The following is for users who want to configure how Superset starts up in Docker Compose; otherwise, you can skip to the next section.

You can configure the Docker Compose settings for dev and non-dev mode with docker/.env and docker/.env-non-dev respectively. These environment files set the environment for most containers in the Docker Compose setup, and some variables affect multiple containers and others only single ones.

One important variable is SUPERSET_LOAD_EXAMPLES which determines whether the superset_init container will load example data and visualizations into the database and Superset. Thiese examples are quite helpful for most people, but probably unnecessary for experienced users. The loading process can sometimes take a few minutes and a good amount of CPU, so you may want to disable it on a resource-constrained device.

Log in to Superset

Your local Superset instance also includes a Postgres server to store your data and is already pre-loaded with some example datasets that ship with Superset. You can access Superset now via your web browser by visiting http://localhost:8088. Note that many browsers now default to https - if yours is one of them, please make sure it uses http.

Username:admin

Password:admin

Connecting to Postgresql Container:

Docker makes it very easy to spin up a PostgreSQL database management system. With the following command it is possible to start your PostgreSQL Docker container on your server or local machine:

$ docker run -d -p 5433:5432 — name my-postgres -e POSTGRES_PASSWORD=mysecretpassword postgres

This command will start a PostgreSQL database and map ports using the following pattern: -p <host_port>:<container_port>.
Port 5432 of our container will be mapped on port 5432 of our host or server.

Access the container on your host or server. We will create a database inside our PostgreSQL container.

docker exec -it my-postgres bash

Now you are ‘inside’ your container. We can access postgres and create the database.

root@cb9222b1f718:/# psql -U postgres
psql (10.3 (Debian 10.3-1.pgdg90+1))
Type "help" for help.postgres=# CREATE DATABASE mydb;
CREATE DATABASE
postgres=#\q

We are finished. You can exit your container (\q) and go to your local machine. Here you need some PostgreSQL Client tool installed.

$ psql -h localhost -p 5433 -U postgres -W                       Password for user postgres:                       
psql (9.5.5, server 10.3 (Debian 10.3-1.pgdg90+1)) WARNING: psql major version 9.5, server major version 10. Some psql features might not work.
Type "help" for help.

Connect Your Database with Superset:

Step 1: Login to the Superset.

Step 2: Click on the Data in Main Menu and Click Database.

Step 3: Click on the Database to add new database in Superset.

Step 4: Add your Database Credentials.

Step:4 Test the Connection . In return if you get “Connection looks good”. then the connection with your database is established.In Case of error check the credentials again.

In the Database Section you will see your list of database connection to your Superset app.

--

--

Zeeshan Tariq
Zeeshan Tariq

Written by Zeeshan Tariq

More than 4 years of experience in Back-end Software Development with leading globally distributed software development teams. Working on Azure and Google Cloud

No responses yet