Postgres SQL Setup

Postgres SQL Setup

Install

  • Go to the PostgreSQL download page and choose the version compatible with your operating system.
  • Follow the installation instructions specific to your OS. During installation, you will set up a password for the postgres user, which is the default superuser.

DB Initialization

Search for SQL Shell (psql) to open the console and login (by default) using the superuser credential. Then create a database, remember the ;

CREATE DATABASE XXX;

Then using \l command you should see a list of available databases.

Another way to manage the database is to search for pdAdmin4, and a GUI is available.

Working in SQLAlchemy

This requires two packages:

pip install sqlalchemy psycopg2-binary

Then an engine can be setup with,

from sqlalchemy import create_engine

engine = create_engine('postgresql+psycopg2://postgres:151678@localhost:5432/consumerloandb')

The url follows //username:password@localhost:portnumber/dbname.

Yiming Zhang
Yiming Zhang
Quantitative Researcher Associate, JP Morgan