Can't access database with normal Ubuntu Terminal user

127 views
Skip to first unread message

Gchorn

unread,
Apr 17, 2012, 2:07:51 AM4/17/12
to django...@googlegroups.com
I'm not totally sure if this qualifies as a Django question, but it's impeding my ability to make a website with Django so I thought I'd ask here.  I'm working with Django in Ubuntu 11.10, where I've set up PostgreSQL to make and manage databases for my Django-powered website.  Unfortunately, when working with Django in the Terminal, I need to first switch over to the user "postgres" (the user I created when installing PostgreSQL) in order to do anything with PostgreSQL or its databases.  This becomes a problem when I need to simultaneously access my database and the local file system, since my local filesystem is only accessible to my normal Ubuntu Terminal user, "guillaume."

I already have the correct user and passwords entered in my settings.py file for my database, but this doesn't seem to help--I still need to switch over to "posgres" in the Terminal to access my databases.  I'm guessing I need to either a) give "guillaume" access to my databases (which I've tried reading up on in the PostgreSQL docs, but am still not sure how to do...part of it is I'm not sure how to tell apart Ubuntu users, Unix users, and Postgres users), or I need to b) give "postgres" access to my local file system.  Can anyone tell me which is the better route to follow, and how to achieve it?

Guillaume Chorn

unread,
Apr 17, 2012, 2:50:22 AM4/17/12
to django...@googlegroups.com
Something more specific in case it helps: as an example, when I try to access my admin view while logged in as my regular user ("guillaume") instead of "postgres", I get the following error:

OperationalError at /admin/

FATAL:  Peer authentication failed for user "postgres"
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.3.1
Exception Type: OperationalError
Exception Value:
FATAL:  Peer authentication failed for user "postgres"
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py in _cursor, line 140
Python Executable: /usr/bin/python
Python Version: 2.7.2
Python Path:
['/home/guillaume/moisiedarling',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
 '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
 '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
Server time: Tue, 17 Apr 2012 01:46:23 -0500


On Tue, Apr 17, 2012 at 2:07 PM, Gchorn <guillau...@gmail.com> wrote:
I'm not totally sure if this qualifies as a Django question, but it's impeding my ability to make a website with Django so I thought I'd ask here.  I'm working with Django in Ubuntu 11.10, where I've set up PostgreSQL to make and manage databases for my Django-powered website.  Unfortunately, when working with Django in the Terminal, I need to first switch over to the user "postgres" (the user I created when installing PostgreSQL) in order to do anything with PostgreSQL or its databases.  This becomes a problem when I need to simultaneously access my database and the local file system, since my local filesystem is only accessible to my normal Ubuntu Terminal user, "guillaume."

I already have the correct user and passwords entered in my settings.py file for my database, but this doesn't seem to help--I still need to switch over to "posgres" in the Terminal to access my databases.  I'm guessing I need to either a) give "guillaume" access to my databases (which I've tried reading up on in the PostgreSQL docs, but am still not sure how to do...part of it is I'm not sure how to tell apart Ubuntu users, Unix users, and Postgres users), or I need to b) give "postgres" access to my local file system.  Can anyone tell me which is the better route to follow, and how to achieve it?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/1NWyssjq5sYJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

kenneth gonsalves

unread,
Apr 17, 2012, 3:03:15 AM4/17/12
to django...@googlegroups.com
On Tue, 2012-04-17 at 14:50 +0800, Guillaume Chorn wrote:
> FATAL: Peer authentication failed for user "postgres"

suitably edit pg_hba.conf
--
regards
Kenneth Gonsalves

Guillaume Chorn

unread,
Apr 17, 2012, 3:45:05 AM4/17/12
to django...@googlegroups.com
Thanks for the input, but I think I'm going to need more help than this.  I was able to find the pg_hba.conf file, but have no idea how to edit it.  Can anyone help with this?

Sorry, I'm pretty new to all of this (SQL, Linux, etc.) so I'm hoping someone can provide me fairly detailed instructions.

--
You received this message because you are subscribed to the Google Groups "Django users" group.

kenneth gonsalves

unread,
Apr 17, 2012, 8:30:46 AM4/17/12
to django...@googlegroups.com
On Tue, 2012-04-17 at 15:45 +0800, Guillaume Chorn wrote:
> Thanks for the input, but I think I'm going to need more help than
> this. I
> was able to find the pg_hba.conf file, but have no idea how to edit
> it.
> Can anyone help with this?
>
>

look at the last few lines - change the authentication to 'trust' - this
is ok for a dev machine, later you can study the safer options.
--
regards
Kenneth Gonsalves


kenneth gonsalves

unread,
Apr 18, 2012, 12:49:40 AM4/18/12
to django...@googlegroups.com
On Tue, 2012-04-17 at 15:45 +0800, Guillaume Chorn wrote:
> Thanks for the input, but I think I'm going to need more help than
> this. I
> was able to find the pg_hba.conf file, but have no idea how to edit
> it.
> Can anyone help with this?
>
>

look at the last few lines - change the authentication form 'ident' to 'trust' - this

Gelonida N

unread,
Apr 18, 2012, 5:50:07 AM4/18/12
to django...@googlegroups.com
Not sure if this helps you.


I had to create the file ~/.pgpass in the home directory of my
developers account.


I repeated there the data base name, the user name and the password for
my database.

Example:

localhost:*:db_name:username:password


Afterwards I was able to access the db with
./manage.py dbshell

> <mailto:django...@googlegroups.com>.


> To unsubscribe from this group, send email to
> django-users...@googlegroups.com

> <mailto:django-users%2Bunsu...@googlegroups.com>.


> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.

Reply all
Reply to author
Forward
0 new messages