postgresql-dart icon indicating copy to clipboard operation
postgresql-dart copied to clipboard

Does not connect to local hosted server.... SSL is mandatory!!!

Open dooley-ch opened this issue 9 months ago • 3 comments

So I'm working on a Mac and have the local Postgres App running on my machine (https://postgresapp.com/).

And while it works fine with all my other environments (Ruby, Python, Purebasic, Xojo, Datagrip etc...) I cannot make a connection from Dart using your package!

If I use this style of connection:

  @protected
  Future<Connection> getConnection() async {
    return await Connection.open(Endpoint(
      host: dbInfo.host,
      database: dbInfo.database,
      username: dbInfo.user,
      password: dbInfo.password,
    ));
  }

I get the error message:

Unhandled exception:
Severity.error Server does not support SSL, but it was required.

And if I use this format, which I believe is wrong in any case:

  Future<Connection> getConnection() async {
    return await Connection.open(Endpoint(
      host: dbInfo.host,
      database: dbInfo.database,
      username: dbInfo.user,
      password: dbInfo.password,
      isUnixSocket: true
    ));
  }

I get this error, which is kinda what I'm expecting to happen:

Connection failed (OS Error: No such file or directory, errno = 2), address = localhost, port = 5432

So how can I turn off the SSL mode as is supported in other environments, something likeL

'postgres://username:password@localhost:5432/database?sslmode=false';

Or alternative how do you expect people to handle this use case?

dooley-ch avatar Mar 17 '25 11:03 dooley-ch

So how can I turn off the SSL mode

Use the settings: ConnectionSettings(sslMode: SslMode.disable).

how do you expect people to handle this use case?

We decided to opt for defaults that are secure and you need to opt-out (like the above setting) to go with the unsecure option. I guess we could have better error messages though.

isoos avatar Mar 17 '25 11:03 isoos

Thank you for the quick response!

I used to work on banking systems so I appreciate your approach. Perhaps you could consider adding a note to usage section in the docs....

Once again thanks.

dooley-ch avatar Mar 17 '25 13:03 dooley-ch

Expanded the exception message in #420. Closing, but feel free to submit PRs if you encounter something non-intuitive that could be fixed with better messages.

isoos avatar Mar 17 '25 17:03 isoos