0

I have a small all based on web.py and peewee. Deployment to heroku goes fine and I have a DB running, but how do I configure peewee to use the heroku postgress db?

The peewee documentation doesn't reveal anything useful http://peewee.readthedocs.org/en/latest/peewee/api.html#PostgresqlDatabase

I have tried

db = PostgresqlDatabase('database', user='user', password='password', host='host')

Forgot the log snippet from "heroku logs"

2013-04-15T17:11:21.093479+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/peewee.py", line 1639, in connect
2013-04-15T17:11:21.093255+00:00 app[web.1]:   File "/app/myapp.py", line 5, in <module>
2013-04-15T17:11:21.093479+00:00 app[web.1]:     self.__local.conn = self._connect(self.database, **self.connect_kwargs)

Update I tried to change the postgresql settings to

db = PostgresqlDatabase("dbname='template1' user='dbuser' host='localhost' password='dbpass'")

now I am getting

2013-04-16T19:11:02.345227+00:00 app[web.1]:     db.connect()
2013-04-16T19:11:02.345227+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/peewee.py", line 1639, in connect
2013-04-16T19:11:02.345227+00:00 app[web.1]:     self.__local.conn = self._connect(self.database, **self.connect_kwargs)
2013-04-16T19:11:02.345227+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/peewee.py", line 1810, in _connect
2013-04-16T19:11:02.345582+00:00 app[web.1]:     return psycopg2.connect(database=database, **kwargs)
2013-04-16T19:11:02.345582+00:00 app[web.1]:     conn = _connect(dsn, connection_factory=connection_factory, async=async)
2013-04-16T19:11:02.345582+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
2013-04-16T19:11:02.345582+00:00 app[web.1]: psycopg2.OperationalError: could not connect to server: No such file or directory
2013-04-16T19:11:02.345582+00:00 app[web.1]:    Is the server running locally and accepting
2013-04-16T19:11:02.345582+00:00 app[web.1]:    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
kristian nissen
  • 2,809
  • 5
  • 44
  • 68

2 Answers2

1

I found the answer here http://initd.org/psycopg/docs/module.html, after several hours of googling and testing, the correct way to connect is

db = PostgresqlDatabase(
    database='',
    user='',
    password='',
    host='',
    port='5432'
  )

this lets peewee connect to postgresql on Heroku

kristian nissen
  • 2,809
  • 5
  • 44
  • 68
-1

If you do not know your database's configuration when the interpreter starts up, you can "defer" initializaiton and set the database connection parameters at run-time:

http://peewee.readthedocs.org/en/latest/peewee/cookbook.html#deferring-initialization

coleifer
  • 24,887
  • 6
  • 60
  • 75