12

I have a Rails app running on a postgres database. I'm setting up a background task queue running on the database, and I need to specify the database URL.

The various permutations I've tried and would expect all return FATAL: database "database-name" does not exist.

Is there a command that will print this URL?

Or, what should the URL look like if my database.yml looks like this

development:
    adapter: postgresql
    encoding: unicode
    database: db/database-name

Thanks for suggestions.

3
  • The classic approach is to inspect the postgres logfile, just to see what the frontend attempted. Commented May 17, 2012 at 9:41
  • And what is the name of the database in PostgreSQL? Commented May 17, 2012 at 9:43
  • John D, but it smells as sweet as a horse by any other name Commented May 17, 2012 at 11:51

2 Answers 2

12

The format appears to be

postgres://username:password@host/database

You have a / in your database name and (apparently) postgres will accept / in database names, so you need to use either

postgres:///db/database-name

or

postgres:///db%2Fdatabase-name

Feel free to take out the db/ part of your database name - it's only warranted for databases like SQLite that store the db in a local file and need a filename.

Sign up to request clarification or add additional context in comments.

1 Comment

The db path was the problem. I was hoping for a way around this, as I already had data in the database. In the end I dropped, recreated without db in the name, and imported a backup. Works perfectly. Thanks!
0

Not sure how you're attempting to access the database, but if you are attempting to create a script that uses the same database as rails but is run separately, consider using a script that runs in rails. In unix/linux, if you add this line:

#! script/rails runner

to the first line of your script and then make it executable with:

chmod +x myscript

then you can simply run it with

./myscript

and it can use your model classes just like your controller and view code in rails. Then there is no need to access the database manually.

2 Comments

thanks michael, no i just need the connection path to the database. I'm trying to incorporate queue_classic into my app github.com/ryandotsmith/queue_classic.
the problem I'm facing is my database.yml defines the path db/database-name but the error is FATAL: database "dbdatabase-name" does not exist - note no slash separator after the db. So I'm looking for a way to interrogate and work out what path Rails is using. Any ideas?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.