Connecting to Database

We will be using JupyterHub based environment to master Postgresql. Let us go through the steps involved to get started using JupyterHub environment.

  • We will use Python Kernel with sql magic command and for that we need to first load the sql extension.

  • Create environment variable DATABASE_URL using SQL Alchemy format.

  • Write a simple query to get data from information schema table to validate database connectivity.

  • Here is the information you can leverage to connect to the database.

    • User Name: YOUR_OS_USER_sms_user

    • Database Name: YOUR_OS_USER_sms_db

    • Password: Your lab password provided by us

%load_ext sql

Copy to clipboard

%env DATABASE_URL=postgresql://itversity_sms_user:sms_password@localhost:5432/itversity_sms_db

Copy to clipboard

%sql SELECT * FROM information_schema.tables LIMIT 10