> -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Ryan Steele > Sent: 15 August 2011 12:58 > To: [email protected] > Subject: Re: [Trac] Re: Migrating from SQLite to PostgreSQL > > Thanks for the reply - responses inline below: > > Cooke, Mark wrote: > >> Ryan Steele wrote: > >>> I'm working on migrating an installation from SQLite to > PostgreSQL, but > >>> the sqlite2pg script seems to fail, even with all the > pre- requisite > >>> packages installed: > >>> > >>> ii python-psycopg2 2.0.13-2ubuntu2 > Python module for > >>> PostgreSQL ii python-psycopg2-dbg > 2.0.13-2ubuntu2 Python > >>> module for PostgreSQL (debug extension) ii > python-psycopg2-testsuite > >>> 2.0.13-2ubuntu2 Python module for PostgreSQL ii python > 2.6.5-0ubuntu1 > >>> An interactive high-level object- oriented language > (default version) ii > >>> postgresql-9.0 9.0.4-1~lucid1 > object-relational SQL > >>> database, version 9.0 server ii postgresql-client-9.0 > 9.0.4-1~lucid1 > >>> front-end programs for PostgreSQL 9.0 > >>> > >>> > >>> > >>> root@host:~# ./sqlite2pg.py -e /path/to/trac -p 'postgres:// > >>> user:pass@localhost:5432/trac' Traceback (most recent > call last): File > >>> "./sqlite2pg.py", line 335, in <module> > sys.exit(main(sys.argv[1:])) File > >>> "./sqlite2pg.py", line 331, in main Main(opts) File > "./sqlite2pg.py", > >>> line 244, in Main pgenv = getPostgreSQLEnvironment(opts) File > >>> "./sqlite2pg.py", line 209, in getPostgreSQLEnvironment cnx = > >>> env.get_db_cnx() File > "/usr/lib/python2.6/dist-packages/trac/env.py", > >>> line 285, in get_db_cnx return > DatabaseManager(self).get_connection() > >>> File "/usr/lib/python2.6/dist-packages/trac/db/api.py", > >> line 90, in > >>> get_connection connector, args = self._get_connector() File > >>> "/usr/lib/python2.6/dist-packages/trac/db/api.py", > >> line 131, in > >>> _get_connector raise TracError('Unsupported database type > "%s"' % scheme) > >>> trac.core.TracError: Unsupported database type "postgres" > >>> > >>> I know that the PG backend is supported, because the > >>> TracEnvironment#DatabaseConnectionStrings wiki page says > so (this is > >>> version 0.11.7), and all of the necessary files exist underneath > >>> $PYTHONPATH (e.g., postgres_backend.py), so I'm a little > confused as to > >>> what the problem is. If it helps, the relevant part of > _get_connector > >>> is: > >>> > >>> def _get_connector(self): ### FIXME: Make it public? > scheme, args = > >>> _parse_db_str(self.connection_uri) candidates = [ > (priority, connector) > >>> for connector in self.connectors for scheme_, priority in > >> connector.get_supported_schemes() > >>> if scheme_ == scheme ] if not candidates: raise > TracError('Unsupported > >>> database type > >> "%s"' % scheme) > >>> Also, the connectors are defined like so in the > >> DatabaseManager class: > >>> class DatabaseManager(Component): connectors = > >>> ExtensionPoint(IDatabaseConnector) > >>> > >>> The IDatabaseConnector class is what has the > get_connection method, and > >>> in postgres_backend.py, I can see that the > PostgreSQLConnector class > >>> implements IDatabaseConnector: > >>> > >>> class PostgreSQLConnector(Component): > implements(IDatabaseConnector) > >>> > >>> > >>> So, the error provided doesn't make a whole lot of sense > to me. I would > >>> tend to think it's an installation-specific problem > (e.g., something > >>> nothing being in $PYTHONPATH), but I don't see evidence > of that here. > >>> Any help is most appreciated, and more detail can be provided if > >>> requested. > >>> > >>> Cheers, Ryan > >> -----Original Message----- From: [email protected] > >> [mailto:[email protected]] On Behalf Of Ryan > Steele Sent: 12 > >> August 2011 19:43 To: Trac Users Subject: [Trac] Re: > Migrating from SQLite > >> to PostgreSQL > >> > >> Just for kicks, I decided to print out the list of > connectors right before > >> it tries to validate what is passed in: > >> > >> def _get_connector(self): ### FIXME: Make it public? scheme, args = > >> _parse_db_str(self.connection_uri) print self.connectors > candidates = [ > >> (priority, connector) for connector in self.connectors for scheme_, > >> priority in connector.get_supported_schemes() if scheme_ > == scheme ] if not > >> candidates: raise TracError('Unsupported database type > "%s"' % scheme) > >> > >> > >> The root of the problem here is that the list only shows the SQLite > >> connector: > >> > >> root@host:~# ./sqlite2pg.py --tracenv /path/to/trac -p > >> 'postgres://user:pass@localhost:5432/trac' > >> > >> [<trac.db.sqlite_backend.SQLiteConnector object at 0x2ee4cd0>] > >> > >> Why exactly that is, I'm not sure yet, as the connectors > (sqlite, mysql, > >> postgres) are all in the same directory. Gonna keep > digging, but open to > >> suggestions. > >> > >> Cheers, Ryan > >> > > I am guessing but... if that error is coming from the > script and your trac > > works OK (have you tried just creating a new, empty trac > using PostgreSQL as > > the backend to make sure?) > > > I was able to create a brand new Trac environment with > initenv when testing > using PG as the backend, so functionally that works. The > only problem is with > the migration script not finding anything but the default > SQLite connector, even > though the paths and such appear to be correct. > > > > then perhaps it is to do with the way trac is configured... > > > But it's not even getting to that point - it's literally > failing because the > database type "postgres" isn't recognized, due to the fact > that the PostgreSQL > connector isn't being found and thus isn't in the list of > valid candidates. > > > > Is it in some sort of python virtualenv which would mean > when you _run_ the > > script (instead of www-user etc) does not see the postgresql code? > > > I tried running it as the webserver just for kicks, even > though I was pretty > sure that wasn't the problem, and I still see the same issue > - the only > connector candidate found is the default SQLite connector: > > >> def _get_connector(self): ### FIXME: Make it public? > >> scheme, args = _parse_db_str(self.connection_uri) > >> print self.connectors ### ADDED BY ME TO PRINT LIST OF > CONNECTORS > >> candidates = [ > >> (priority, connector) > >> for connector in self.connectors > >> for scheme_, priority in connector.get_supported_schemes() > >> if scheme_ == scheme > >> ] > >> if not candidates: > >> raise TracError('Unsupported database type "%s"' % scheme) > > >> root@host:~# ./sqlite2pg.py --tracenv /path/to/trac -p > >> 'postgres://user:pass@localhost:5432/trac' > >> > >> [<trac.db.sqlite_backend.SQLiteConnector object at 0x2ee4cd0>] > > I also added some debugging to determine whether or not the > psycopg2 libs were > properly detected, and they are. This is from the top of > postgres_backend.py: > > > has_psycopg = False > has_pgsql = False > PGSchemaError = None > try: > import psycopg2 as psycopg > import psycopg2.extensions > from psycopg2 import ProgrammingError as PGSchemaError > psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) > has_psycopg = True > except ImportError: > try: > from pyPgSQL import PgSQL > from pyPgSQL.libpq import OperationalError as PGSchemaError > has_pgsql = True > except ImportError: > pass > > print "HAS PSYCOPG:" > print has_psycopg > > ...and, the output I get is: > > HAS PSYCOPG: > True > > But alas, I still get: > > Traceback (most recent call last): > File "./sqlite2pg.py", line 337, in <module> > sys.exit(main(sys.argv[1:])) > File "./sqlite2pg.py", line 333, in main > Main(opts) > File "./sqlite2pg.py", line 246, in Main > pgenv = getPostgreSQLEnvironment(opts) > File "./sqlite2pg.py", line 210, in getPostgreSQLEnvironment > cnx = env.get_db_cnx() > File "/usr/lib/python2.6/dist-packages/trac/env.py", line > 285, in get_db_cnx > return DatabaseManager(self).get_connection() > File "/usr/lib/python2.6/dist-packages/trac/db/api.py", > line 90, in get_connection > connector, args = self._get_connector() > File "/usr/lib/python2.6/dist-packages/trac/db/api.py", line 138, in > _get_connector > raise TracError('Unsupported database type "%s"' % scheme) > trac.core.TracError: Unsupported database type "postgres" > > > Maybe wiser minds have a better perspective on the situation, > but it still looks > to me like the problem is the PostgreSQL connector not being > loaded. As to why > that is... not sure yet. Open to opinions, though :) > > Cheers, > Ryan > Seeing as you sound like someone capable of tinkering with code, what happens if you try to use pyscopg2 directly from a python prompt to access the backend dB you setup with that new project earlier? Lets take Trac and the script out of this until we know that pyscopg2 works for your user OK...
~ mark c -- You received this message because you are subscribed to the Google Groups "Trac Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/trac-users?hl=en.
