I’m trying to connect to a PostgreSQL 8.4 DB in Ubuntu 10.10 via the JDBC drivers. I’m connecting via jdbc:postgresql:localhost:5433/dbname because PostgreSQL is running on a non-default port 5433 so I have to specify the port.
I’ve already edited my postgresql.conf to set listen_addresses = "*". I understand that even though it’s localhost, it’s still using TCP/IP to connect via JDBC.
My problem is that I created a user without a password. If i do not specify a password with DriverManager.connect(url), it errors indicating that I need to specify a password for authentication. Every password I try, including empty string, fails to authenticate with the DB.
How can I connect?
Edit:
If connecting over wrong port, the error is : PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. When attempting to connect on the correct port, I’m getting PSQLException: FATAL: password authentication failed for user “user”. THis is remedied by the accepted answer below.
If you have
pg_hba.confset to requiremd5authentication and the user has no password, then no authentication can occur.Alternately, use
identor (for localhost only, unsafe)trustauthentication for that user/db combo inpg_hba.confif you really must have no password. This is usually a bad idea, it’s much better to just set a password.Demo: