Django can't find database

414 views
Skip to first unread message

Gary Roach

unread,
Oct 22, 2016, 2:36:59 PM10/22/16
to django-users
Hi all,

Debian System, stretch, 64 bit. KDE4 Desktop
Django 1.10
Postgresql 9.6 with psycopg2



When I try to migrate, I get the following error:

> Traceback (most recent call last):
> File "/home/gary/workspace/djenv/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
> self.connect()
> File "/home/gary/workspace/djenv/lib/python3.5/site-packages/django/db/backends/base/base.py", line 171, in connect
> self.connection = self.get_new_connection(conn_params)
> File "/home/gary/workspace/djenv/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection
> connection = Database.connect(**conn_params)
> File "/home/gary/workspace/djenv/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
> conn = _connect(dsn, connection_factory=connection_factory, async=async)
> psycopg2.OperationalError: FATAL: database "archivedb" does not exist

My settings file looks like this:

> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.postgresql_psycopg2',
> 'NAME': 'archivedb',
> 'USER': 'gary',
> 'PASSWORD': 'zzyyxx', # WARNING If they get this far I'm screwed anyway
> 'HOST': 'localhost',
> 'PORT': '5432',
> }
> }

My pgAdminIII Object Browser:

See attachment Spectacl.....
And SQL Pane for Gary:

> CREATE ROLE gary LOGIN
> ENCRYPTED PASSWORD 'md5772cde60e4a04dc0cb7268674810bf03'
> SUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION;

The pg_hba.conf file at /etc/postgresql/9.6/main is:

> # Database administrative login by Unix domain socket
> local all postgres trust
>
> # TYPE DATABASE USER ADDRESS METHOD
>
> # "local" is for Unix domain socket connections only
> local all all trust
> # IPv4 local connections:
> host all all 127.0.0.1/32 trust
> # IPv6 local connections:
> host all all ::1/128 trust
> # Allow replication connections from localhost, by a user with the
> # replication privilege.
> #local replication postgres peer
> #host replication postgres 127.0.0.1/32 md5
> #host replication postgres ::1/128 md5

What's happening here?

Any help will be sincerely appreciated.

Gary R.







Spectacle.f30721.png

Jamie Lawrence

unread,
Oct 22, 2016, 2:49:41 PM10/22/16
to django...@googlegroups.com

> On Oct 22, 2016, at 11:35 AM, Gary Roach <gary71...@verizon.net> wrote:

> When I try to migrate, I get the following error:
>
>> psycopg2.OperationalError: FATAL: database "archivedb" does not exist


> What's happening here?

Are you certain the ‘archivedb’ database actually exists?

If it does, is in in an accessible schema?

If it is, is it in the cluster you’re connecting to in Django?

-j

Vijay Khemlani

unread,
Oct 22, 2016, 4:13:34 PM10/22/16
to django...@googlegroups.com
Can you connect to the database via command line?

psql -U gary -d archivedb 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/AB039201-8818-40D4-B3BA-F036F510FDC5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Gary Roach

unread,
Oct 22, 2016, 7:24:14 PM10/22/16
to django...@googlegroups.com


psql -U gary -d archivedb gives:
    FATAL:  Peer authentication failed for user "gary"
which probably means that psql can't find the database either.

My process table ( ps -xaf) shows:
642 ?        S      0:07 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
  754 ?        Ss     0:00  \_ postgres: 9.6/main: checkpointer process   
  755 ?        Ss     0:04  \_ postgres: 9.6/main: writer process   
  756 ?        Ss     0:04  \_ postgres: 9.6/main: wal writer process   
  757 ?        Ss     0:04  \_ postgres: 9.6/main: autovacuum launcher process   
  758 ?        Ss     0:05  \_ postgres: 9.6/main: stats collector process   
  643 ?        S      0:12 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf
  768 ?        Ss     0:00  \_ postgres: checkpointer process   
  772 ?        Ss     0:11  \_ postgres: stats collector process   
 6501 ?        Ss     0:00  \_ postgres: postgres postgres [local] idle

So the database seems  to be running. No sure why there are two versions running but may be due to Debian using the older version of something. Is this a path problem?

Does this help

Gary R.



On 10/22/2016 01:13 PM, Vijay Khemlani wrote:

Antonis Christofides

unread,
Oct 23, 2016, 7:05:36 AM10/23/16
to django-users
No, "peer authentication failed for user "gary"" doesn't mean that psql can't find the database; it means what it says, authentication failed.

Peer authentication is quite complicated. "psql -U gary archivedb" is a local connection (using Unix sockets I think), and by default postgresql uses peer authentication for such connections. You want to avoid it, because it will confuse you, so use "psql -h localhost -U gary archivedb"; this is a network connection to localhost:5432, and this, by default, does username/password authentication, which is what you want.

But, anyway, the problem is very likely that your database does not exist. You can create it with "sudo -u postgres createdb archivedb --owner=gary".

You must definitely get rid of the second instance that is running. Try "dpkg -l postgresql* | grep ^ii"; this will show you which postgresql packages you have installed. If you have two server packages installed, uninstall one of them with "apt-get remove [packagename]".

Regards,

Antonis Christofides
http://djangodeployment.com/
> > <gary71...@verizon.net <mailto:gary71...@verizon.net>> wrote:
> >
> > > When I try to migrate, I get the following error:
> > >
> > >> psycopg2.OperationalError: FATAL: database "archivedb" does not exist
> >
> >
> > > What's happening here?
> >
> > Are you certain the ‘archivedb’ database actually exists?
> >
> > If it does, is in in an accessible schema?
> >
> > If it is, is it in the cluster you’re connecting to in Django?
> >
> > -j
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4016676a-9008-8b14-54ac-79d09806bb51%40verizon.net.
Reply all
Reply to author
Forward
0 new messages