So recently, I moved home for this blog. It used to be on AWS EC2 and is now on Digital Ocean. I wanted to start from scratch so I started on a blank new Ubuntu 14.04 and later rsync'ed over all the data bit by bit (no pun intended).
When I moved this site I copied the
/etc/uwsgi/apps-enabled/peterbecom.ini file and started it with
/etc/init.d/uwsgi start peterbecom. The settings were the same as before:
# this is /etc/uwsgi/apps-enabled/peterbecom.ini [uwsgi] virtualenv = /var/lib/django/django-peterbecom/venv pythonpath = /var/lib/django/django-peterbecom user = django master = true processes = 3 env = DJANGO_SETTINGS_MODULE=peterbecom.settings module = django_wsgi2:application
But I kept getting this error:
Traceback (most recent call last): ... File "/var/lib/django/django-peterbecom/venv/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 182, in _cursor self.connection = Database.connect(**conn_params) File "/var/lib/django/django-peterbecom/venv/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) psycopg2.OperationalError: FATAL: Peer authentication failed for user "django"
What the heck! I thought. I was able to connect perfectly fine with the same config on the old server and here on the new server I was able to do this:
django@peterbecom:~/django-peterbecom$ source venv/bin/activate (venv)django@peterbecom:~/django-peterbecom$ ./manage.py shell Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from peterbecom.apps.plog.models import * >>> BlogItem.objects.all().count() 1040
Clearly I've set the right password in the
settings/local.py file. In fact, I haven't changed anything and I
pg_dump'ed the data over from the old server as is.
I edit edited the file
psycopg2/__init__.py and added a
print "DSN=", dsn and those details were indeed correct.
I'm running the uwsgi app as user
django and I'm connecting to Postgres as user
Anyway, what I needed to do to make it work was the following change:
# this is /etc/uwsgi/apps-enabled/peterbecom.ini [uwsgi] virtualenv = /var/lib/django/django-peterbecom/venv pythonpath = /var/lib/django/django-peterbecom user = django uid = django # THIS IS ADDED master = true processes = 3 env = DJANGO_SETTINGS_MODULE=peterbecom.settings module = django_wsgi2:application
The difference here is the added
uid = django.
I guess by moving across (I'm currently on
220.127.116.11-debian) I get a newer version of
uwsgi or something that simply can't just take the
user directive but needs the
uid directive too. That or something else complicated to do with the users and permissions that I don't understand.
Hopefully, by having blogged about this other people might find it and get themselves a little productivity boost.