Reputation: 9570
I am running a Ruby on Rails app on Heroku. It uses a Postgres database. I want to connect to the database from some scripts I am writing and running locally.
Using ENV['DATABASE_URL'] I found my connection url to be:
postgres://zugzagcaht:[email protected]/zugzagcaht
(I modified the characters so this is not the real string!)
Now I am running a Python script that should connect to the database, but am finding a timeout in the connection:
import psycopg2
DB_NAME = 'zugzagcaht'
DB_USER = 'zugzagcaht'
DB_HOST = 'ec2-25-25-209-55.compute-1.amazonaws.com'
DB_PASSWORD = 'h-HebaxOz1_H-5uq_Olv'
TIMEOUT = 5 # seconds
conn = None
try:
conn = psycopg2.connect("connect_timeout=%i dbname='%s' user='%s' host='%s' password='%s'" % (TIMEOUT, DB_NAME, DB_USER, DB_HOST, DB_PASSWORD))
except:
print "I am unable to connect to the database"
if conn:
cur = conn.cursor()
cur.execute("SELECT datname from pg_database")
rows = cur.fetchall()
print "Here's the databases:\n"
for row in rows:
print " ", row[0]
Any idea why this isn't working?
Upvotes: 3
Views: 1454
Reputation: 37507
You can't connect to Heroku shared database instances however they recently launched a new development instance which permits ingress - read more at https://postgres.heroku.com/blog/past/2012/4/26/heroku_postgres_development_plan/ - I suspect this is the problem.
Upvotes: 2