I'm using demo from facebook's tornado
But I don't want to use MySQL and trying to replace it with PG So I went ahead and modified like this :
define("port", default=8888, help="run on the given port", type=int)
define("pgsql_host", default="127.0.0.1:5432", help="blog database host")
define("pgsql_database", default="pgdb", help="blog database name")
define("pgsql_user", default="admin", help="blog database user")
define("pgsql_password", default="pgpass", help="blog database password")
and
# Have one global connection to the blog DB across all handlers
self.db = tornado.database.Connection(
host=options.pgsql_host, database=options.pgsql_database,
user=options.pgsql_user, password=options.pgsql_password)
But app just hangs when I run it, how to properly migrate it to PG?
Actually I get error after some time:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado-2.4.1-py2.7.egg/tornado/database.py", line 84, in __init__
self.reconnect()
File "/usr/local/lib/python2.7/dist-packages/tornado-2.4.1-py2.7.egg/tornado/database.py", line 101, in reconnect
self._db = MySQLdb.connect(**self._db_args)
File "/usr/lib/pymodules/python2.7/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 0")
Why is it connecting to MySQL?
import torndband the error is after you have defined in lines 61-63torndb.Connection(). See the Source code for torndb, it only uses MySQL, no Postgres. You have to rewrite that part (the whole torndb module, probably creating a new "torndbpostgres" module) to connect to Postgres instead of MySQL. – ypercube Dec 1 '12 at 21:12