1

I've added heroku postgres addon.

The DATABASE_URL is something like postgres://xxxxxxxxx:[email protected]:5432/ddo2ahvosfggq

I want the database name to be like my_app_database. I want to rename ddo2ahvosfggq to my_app_database.

How can I do that?

Can I use ALTER DATABASE? http://www.postgresql.org/docs/9.1/static/sql-alterdatabase.html

There is already a question in StackOverflow How to rename database in Heroku?

But the answers is to rename the app. I don't know how renaming app will work?

If my_app is the name of my heroku app. Will the below DATABASE_URL work?

postgres://xxxxxxxxx:[email protected]:5432/my_app

7
  • What is the use case? Commented Jul 22, 2015 at 11:32
  • @RAJ Want to have user friendly name for my database Commented Jul 22, 2015 at 11:35
  • This is the syntax to rename the database ALTER DATABASE current_name RENAME TO my_app_database Commented Jul 22, 2015 at 11:40
  • Don't understand what is the motive of the custom db name. Just FYI, you can use constant to refer to your database on heroku i.e. DATABASE_URL Commented Jul 22, 2015 at 12:05
  • 1
    @SamuelAlexander Heroku don't use your settings mentioned in database.yml for production. It automatically generate required things. You can remove production section from your database.yml and push to heroku. Still heroku will work fine. Commented Jul 23, 2015 at 5:29

2 Answers 2

4

You can't. It's a Database-as-a-Service (DBaaS) and database name is not customizable there. You just get it from the service and use. Since it's not a user-facing detail for web applications, pretty names are of no use. So why bother?

Most actions you can do with your database are listed on Heroku Postgres website. You can:

  • regenerate credentials (that don't include database name, only username and password)
  • wipe the database (that doesn't rename the database as well, just drops the tables)
  • create one more database (but it will be named randomly, just as all the others)
Sign up to request clarification or add additional context in comments.

Comments

2

You don't ever really need to type in the name of the production database on Heroku.

Heroku has a post commit hook which writes the production DB details into /config/database.yml.

If you ever really need to to query the database without a model you would establish a connection by:

ActiveRecord::Base.establish_connection
query = ActiveRecord::Base.connection.execute('SELECT * FROM foo;')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.