Reputation: 1311
Set up a node.js app with postgreSQL db, all works in production environment.
I have used the CLI heroku pg:pull ...
which was successful. Am running postgres 9.4.X locally, but on starting my application locally (foreman start) I am getting an error: "Error error: relation "test_table" does not exist". I have followed instructions here: https://devcenter.heroku.com/articles/heroku-postgresql#local-setup but still I cannot seem to access my DB when running locally.
bash_profile:
export PATH="/usr/local/heroku/bin:$PATH"
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
export PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH:$PATH"
Console error log:
15:39:48 web.1 | started with pid 18779
15:39:48 web.1 | Node app is running on port 5000
15:39:52 web.1 | { [error: relation "test_table" does not exist]
15:39:52 web.1 | name: 'error',
15:39:52 web.1 | length: 101,
15:39:52 web.1 | severity: 'ERROR',
15:39:52 web.1 | code: '42P01',
15:39:52 web.1 | detail: undefined,
15:39:52 web.1 | hint: undefined,
15:39:52 web.1 | position: '15',
15:39:52 web.1 | internalPosition: undefined,
15:39:52 web.1 | internalQuery: undefined,
15:39:52 web.1 | where: undefined,
15:39:52 web.1 | schema: undefined,
15:39:52 web.1 | table: undefined,
15:39:52 web.1 | column: undefined,
15:39:52 web.1 | dataType: undefined,
15:39:52 web.1 | constraint: undefined,
15:39:52 web.1 | file: 'parse_relation.c',
15:39:52 web.1 | line: '986',
15:39:52 web.1 | routine: 'parserOpenTable' }
Upvotes: 1
Views: 1537
Reputation: 30587
According to the heroku docs the second argument you give to pg:pull
is the name of the database that will be created locally to contain a copy of your application's data. If you used the example given on the heroku web site:
heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb --app sushi
then the data would be dumped into a local database with the name 'mylocaldb'.
According to the comments, your application is using the contents of the environment variable DATABASE_URL as the connection string.
Since you say pg:pull
worked, but your application cannot find the tables that should exist in the database, I am guessing that your application is connecting to the wrong database. If you were blindly following the heroku documentation you might have done this:
export DATABASE_URL=postgres:///$(whoami)
That connection string would connect you to a database named the same as your user name. Probably this is not the name you used in the pg:pull
command.
To identify what the correct database name is, either look back through your command history to find the name used in pg:pull
, or use the \l
command in psql
to list all the available databases. Then update the environment variable to
export DATABASE_URL=postgres:///dbname
where dbname would be the actual name.
There are a lot of other possible parameters that can be used in a postgresql connection string (and in fact multiple different formats you can use). For more information on these, see the postgresql manual.
Upvotes: 2