Postgresql 9 - psql: could not connect to server: No such file or directory

Posted on 2011-04-28
Last Modified: 2012-05-11
I have just installed PostgreSQL 9.0.4 on my local machine (ubuntu 10.10), after removing 8.4. Now I want to import a database that is so large that the import in Pgadmin crashes. So I need psql to do this, but when I try, I get the following error:

psql: could not connect to server: No such file or directory
      Is the server running locally and accepting
      connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

The server seems to be running though, as I can open Pgadmin, create a database, etc. So I wonder if this is different from 8.4? How can I get this working?
Question by:R7AF
    LVL 7

    Accepted Solution


    Do you know how you configured pgadmin to access the database? You can try to use same configuration for psql. e.g.

    psql -hlocalhost -Uusername  database name

    If you don't know the username/password,

    You can run "ps -elf | grep postmaster" to find out the postgres database process. it should be somthing like

    /usr/bin/postmaster -p 5432 -D /var/lib/pgsql/data

    Then you need to goto /var/lib/pgsql/data/ folder, modify pg_hba.conf, the reload the postgresql configuration.

    for example, add
    host    all         root  trust

    in pg_hba.conf file, then reload the configuration by "/etc/init.d/postgresql reload"

    Then you can login by "psql -hlocalhost database" as root

    LVL 13

    Author Comment


    psql -hlocalhost -Upostgres
    psql -hlocalhost -Upostgres  database_name

    (At first I read it like "database" was a parameter name, with the space inbetween database and name.)

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now