Search code examples
postgresqlmacos-sierra

Running PostgreSQL commands from anywhere on the terminal


First off, let me say that I'm new to both using Mac and PostgreSQL. I just installed Postgres using their installer and it was installed in /Library/Postgres/... when I tried running createdb from the terminal it returned an error createdb: command not found. I ended up using /library/postgresql/9.6/bin/createdb before I coud get it to work. Here's my question, how do I set it so that I don't have to type in the full path again to use the createdb command. I'd love a detailed explanation. Thanks


Solution

  • First you need to execute the psql command to get into the postgresql interacive shell.

    In your terminal:

    psql
    

    Postgresql interactive shell should start. In this shell

    > createdb yourdatabasename;
    

    Btw: If psql is not found you will probably need to add it to your path and restart your terminal, something like this with the path matching your machine:

    export PATH=/Library/PostgreSQL/9.5/bin:$PATH