Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to test pyhton-postgresql script in ubuntu 12.04.

The script is this:

    import psycopg2
    import sys

    con = None


            con = psycopg2.connect(database='mydb', user='myuser') 
            cur = con.cursor()

   except psycopg2.DatabaseError, e:

   if con:

   print 'Error %s' % e    


     if con:

and the error I get each time I run the script from the terminal (python is:

Error  could not connect server: No such file or directory 
Is the server running locally and accepting connection on unix domain socket "/tmp/.s.PGSQL.5432"?

I don't have any idea what this mean, and I have been looking around for a while now. All to no avail.

Any help would be appreciated.

share|improve this question
Can you provide the script, or atleast the lines you use to connect to the db? – Salem Jul 18 '13 at 10:28
@Salem Thanks I have posted an extract from the script – kplus Jul 18 '13 at 10:38
And PostgreSQL is installed and running? You can connect to it using psql or PgAdmin? – Salem Jul 18 '13 at 10:42
let me give it a try. Thanks – kplus Jul 18 '13 at 10:47
PostgreSQL is installed and it's running. Do I need to do any configuration before I can use psql or PgAdmin? – kplus Jul 18 '13 at 10:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.