I am trying to establish a connection to a database like this:
psycopg2.connect(database="movies", user="lfcj", host="127.0.0.1");
my pg_hba.conf
file has a line:
TYPE __ DATABASE___USER__ADDRESS___METHOD
local all lfcj peer
I am trying to use peer identification, and my SO user name is also lfcj
.
When I log in postgresql like this, grant all privileges to lfcj
, and run \list
:
psql lfcj -h 127.0.0.1 -d movies
Enter password: 'myPassword'
psql (9.4.1)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
movies=# GRANT ALL PRIVILEGES ON DATABASE movies TO lfcj WITH GRANT OPTION;
movies=#\list
I get this information:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------+----------+----------+-------------+-------------+-----------------------
movies | lfcj | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/lfcj +
| | | | | lfcj=C*T*c*/lfcj+
So: the database movies
exists, lfcj
is the owner and has all priviliges. But when I run:
psycopg2.connect(movies, lfcj);
it throws an error:
File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL: database "movies" does not exist
Any ideas?
Your connection string should look like this:
The connect method will give you a connection to the database so you will probably need to store it in a variable. Typically like this:
You can also use a set of keywords like this: