39

I've installed postgresql 9.2 on linux (kubuntu) and the last version of pgadmin3, but when I connect them I have this error:

An error has occurred: Error connecting to the server: fe_sendauth: no password supplied

What can I do?

I have also configured tomcat for my web application in java. In fact, postgresql was working before trying my application.

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
DarkCoffee
  • 930
  • 3
  • 17
  • 30

5 Answers5

35

Change the password for role postgres:

sudo -u postgres psql postgres

alter user postgres with password 'postgres';

Try connect using "postgres" for both username and password.

Refer to: How to change PostgreSQL user password

Paschal
  • 725
  • 1
  • 9
  • 17
16

Whether a password is required depends on your settings in pg_hba.conf. And there are different ways you can connect - different settings in pg_hba.conf may apply.

I quote the help shipped with pgAdmin 3 for the "Host" field in the connection ("server") settings:

The host is the IP address of the machine to contact, or the fully qualified domain name. On Unix based systems, the address field may be left blank to use the default PostgreSQL Unix Domain Socket on the local machine, or be set to an alternate path containing a PostgreSQL socket. If a path is entered, it must begin with a “/”. The port number may also be specified.

If you connect via Unix socket the rules for "local" apply. Whereas when connecting via TCP/IP "host" (or "hostssl") rules applies.

If you have a line like this at the top your pg_hba.conf file:

local    all     all     peer

or:

local    all     all     ident

.. then you can connect locally without password if your system user is "postgres" and your database user is "postgres", too.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • 2
    I changhed
    # "local" is for Unix domain socket connections only
    local all all peer # IPv4 local connections: host all all 127.0.0.1/32 trust
    # IPv6 local connections:
    host all all ::1/128 trust
    and it works! Thank you!!
    – DarkCoffee Dec 26 '12 at 18:32
  • @DarkCoffee: I take it you are aware that the `trust` setting is unsafe. – Erwin Brandstetter Dec 26 '12 at 19:26
  • This may be true for version3, but on pgAdmin 4, the host name / address field cannot be left blank; it generates an error. – cazort May 27 '19 at 16:14
10

I realize this is question is years old, but I ran into this same problem today and have a solution that uses trust in a limited but useful way.

As in many development shops, when the devs need a QA postgres password, they just yell it, message it, email it, write it on their foreheads, etc. And I'm like, "This is really bad. I need to figure out a way to use PKI here." We also use pgAdmin3.

First, add a line like this to your pg_hba.conf, where dev represents the user for the developers in your shop:

host all dev 127.0.0.1/32 trust

Drop the developers' public key in their authorized_keys folder on the database server. Now have them ssh into the server with the -L flag with a command similar to the following:

ssh -i ~/.ssh/id_rsa -L5432:127.0.0.1:5432 -vvv 101.102.103.104

This allows one to use the postgres port as if it were localhost. Of course, replace the key, server and make sure to map to an open port locally (if you have a local postgres running, it's probably bound to 5432). I use a pretty verbose flag so I can easily troubleshoot any ssh issues.

Open another terminal and issue this command:

psql -h 127.0.0.1 -U dev -p 5432

You should have access to the database and never be prompted for a password, which I think is great because otherwise, the devs will just waive the password around with little regard to security, passing it out like Halloween candy.

As of now, PgAdmin3 will still prompt you for a password, even though -- plain as day -- you do not need it. But other postgres GUIs will not. Try Postico. It's in beta but works great.

I hope this answer helps anyone like me who would rather use PKI for postgres auth rather than sharing passwords willy-nilly.

bbuckley123
  • 1,879
  • 13
  • 18
  • The log file gave me the additional information the the rules in pg_hba.conf were processed in order. I had to move my rule up over a broader rule so it had an effect. Thanks! – Christian Dec 20 '18 at 10:26
1

Met this problem recently.

If you're using PostgreSQL on local machine, and psql works well without logging needed, try pgadmin3's menu File - Add Server - Properties tab, fill in Name field for this connection, leave Host field and Password field empty, and click ok.

from pgadmin docs

On Unix based systems, the address field may be left blank to use the default PostgreSQL Unix Domain Socket on the local machine, or be set to an alternate path containing a PostgreSQL socket. If a path is entered, it must begin with a “/”.

Worked on Debian testing (pgadmin3 1.22, PostgreSQL 11), without touching pg_hba.conf.

zhazha
  • 3,114
  • 2
  • 13
  • 7
0

For me, I run pg_ctl -D /usr/local/var/postgres start, start the server, then everything is OK, it will pop out the connection host port.

Ping Woo
  • 1,423
  • 15
  • 21