python - Postgresql & psycopg2: database does not exist -
i trying establish connection database this:
psycopg2.connect(database="movies", user="lfcj", host="127.0.0.1");
my pg_hba.conf
file has line:
type __ database___user__address___method
local lfcj peer
i trying use peer identification, , user name lfcj
.
when log in postgresql this, grant privileges lfcj
, , 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" help. movies=# grant privileges on database movies lfcj grant option; movies=#\list
i 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: database movies
exists, lfcj
owner , has priviliges. when run:
psycopg2.connect(movies, lfcj);
it throws 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" not exist
any ideas?
your connection string should this:
psycopg2.connect("dbname=test user=postgres password=secret")
the connect method give connection database need store in variable. typically this:
conn = psycopg2.connect("dbname=test user=postgres password=secret")
you can use set of keywords this:
conn = psycopg2.connect(database="test", user="postgres", password="secret")
Comments
Post a Comment