Search code examples
postgresqlherokuheroku-postgres

How to connect to heroku pg from local machine?


This document says to set DATABASE_URL=postgres://$(whoami) this to maintain parity between local and pro dbs. But what should I replace "whoami" with?

I have installed PostGreSql on my machine. How to I perform CRUD operations?


Solution

  • That whoami will return username of the current user when invoked. As the documentation said, you just need to type the below in command prompt (no need to replace whoami), depends on your OS:

    1. Linux / Mac:

      export DATABASE_URL=postgres://$(whoami)
      
    2. Windows:

      set DATABASE_URL=postgres://$(whoami)
      

    After set up Postgres, you can use psql client to access the database. As you asked in comment regarding how to run .sql file, here's the steps:

    1. In command prompt, type "psql". You are now connected to your database.

    2. Inside psql, type "\i your_sql_file.sql". This execute the your_sql_file.sql file.