1

I am having trouble connecting to a PostgreSQL database hosed on my local host. I have a Python script to connect and connected through the command line, but for the life of me can't connect to a the database from QGIS. Here is the Python code I got to work:

import psycopg2    
try:
    conn = psycopg2.connect("dbname='mb_sed_class' user='postgres' host='localhost' password='Daniel'")
except:
    print "I am unable to connect to the database"

print ("I connected to the database")
cur = conn.cursor()
cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")
print cur.fetchall()

This connected to the database and returned the names tables. And here is how I connected to it from the command line:

psql -d mb_sed_clsss -U postgres

The command line prompted me to input my password and it opened the psql interpreter.

A screen shot of my Create a New PostGIS Connection dialog can be found here. When I try an connect with those inputs I get the error:

FATAL: pssword Authentication failed for user "postgres"

Any ideas on why this might be happening?

I am running QGIS 2.8.2 and PostgreSQL 9.4 on windows 8 64 bit machine.

  • Your script doesn't really test connection works. Try doing a simple select query. cur = conn.cursor()...cur.execute("SELECT * FROM yourtable;")...cur.fetchone() and do a print out. – Matt May 18 '15 at 19:51
  • Are you sure about the exterior inverted commas: conn = psycopg2.connect(dbname='mb_sed_class' user='postgres' host='localhost' password='Daniel')? – n1000 May 18 '15 at 20:24
  • Did you actually start the server, like pg_ctl -D /path/to/database start – n1000 May 18 '15 at 20:29
  • 1
    In the screenshot provided, you did not specify a database. – Scro May 18 '15 at 20:57
  • 1
    dba.stackexchange.com/q/36740, just as @Scro noticed – n1000 May 18 '15 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.