Working on a rails app locally with a remote Postgres connection?
Below are the steps to access Heroku db from local development:
Login to your heroku account.
Navigate to this URL https://postgres.heroku.com/databases/ OR you can get heroku db url by running this command in the terminal:
heroku pg:credentials:url
Select your application database.
You will able to see your heroku pg credentials:
Host xxxxxxxxx.77777.amazonaws.comDatabase 42feddfddeee Username 44444444444Port xxxxPassword 777sfsadferwefsdferwefsdf
collect above details and put in your databse.yml file development evn:
adapter: postgresql host: < host > # HOST port: < port > # Port database: < database name > # Database Name username: < user_name > # User Name password: '< password >' # Password
Restart you application,
Best of luck..!!
I am not a postgres user but this should work. You can alter your database.yml
to include host
and port
production: adapter: postgresql encoding: unicode database: di_production pool: 5 username: user password: host: heroku.host.name port: <postgres listen port>
And of course, you should allow connection on the server side, both at the firewall level and database level.
A simple hack to see contents of #{Rails.root}/config/database.yml
is to write code to load this yml into an object, then print it out on the UI
DB_CONFIG = YAML.load(File.read("#{Rails.root}/config/database.yml", __FILE__))puts DB_CONFIG["production"].inspect # or what ever method you want to print it
I am a bit of a newbie and may have misunderstood your question - but. Developed a ROR application using postgress database. Then uploaded to Heroku. I ran DB/Migrate/schema.rb
to set up the remote Postgresql database.
From memory heroku run rake db:init
(but I could be wrong). Whenver I update the database in develpment to get update in Heroku I have to promote code and run heroku run rake db:migrate
From my config/dtabase.yml
development: adapter: postgresql encoding: unicode database: di_development pool: 5 username: davidlee password:test: adapter: postgresql encoding: unicode database: di_test pool: 5 username: davidlee password:production: adapter: postgresql encoding: unicode database: di_production pool: 5 username: user password:
- and it works. I can't remember doing anything else.
Pierre