Tuesday, December 28, 2010

Making sphinx work with postgresql

On my MacPro, PostgreSQL is installed in /Library/PostgreSQL/8.4/. To install sphinx and have it work with PostgreSQL, I need to configure it in the following way:

./configure --with-mysql --with-prefix=/usr/local/sphinx --with-pgsql --with-pgsql-includes=/Library/PostgreSQL/8.4/include/ --with-pgsql-libs=/Library/PostgreSQL/8.4/lib/


Friday, December 24, 2010

Getting postgis to work with django (and sphinx)

The django-sphinx package does not recognize the postgis backend; one needs to modify the /path/to/djangosphinx/utils/config.py and reinstall it to make the two work together. Add the following to _get_database_engine() in the config.py file:

def _get_database_engine():
...
elif 'postgis' in settings.DATABASES['default']['ENGINE']:
return 'pgsql'

If you are creating a database as the default superuser postgres but you will be connecting to the database as a different user (say chineseblade), it is necessary to grant the privileges to the user. Sadly, if you use template_postgis as a template in creating the database, you will need to grant accesses to the tables geometry_columns and spatial_ref_sys individually, in addition to granting privileges on the database itself. The procedure is

Log on to the database template_postgis as the superuser postgres, and issue commands:

grant select on table spatial_ref_sys to chineseblade;
grant all on table geometry_columns to chineseblade;

Log out, then log on the master database postgres, and create the database using the template:

create database mydb with template=template_postgis;
grant all privileges on database mydb to chineseblade;

Now in the settings.py in your project, set the database engine to 'django.contrib.gis.db.backends.postgis'. You are ready to go!