xo / usql

Universal command-line interface for SQL databases
MIT License
8.88k stars 347 forks source link

Not able to connect to local postgresql db via .usqlpass #361

Closed Crandel closed 2 years ago

Crandel commented 2 years ago

aur/usql 0.12.13-1 Arch linux

My ~/.usqlpass (with 0600 permission)

postgres:localhost:5433:db:db:pass

I was trying to connect

➜ usql pg://
error: pq: dial tcp [::1]:5432: connect: connection refused

But as you can see usql ignore host and port settings

Also I was trying with ?sslmode=disable. Result is the same

➜ usql pg://?sslmode=disable
error: pq: dial tcp [::1]:5432: connect: connection refused

postgres url works fine

➜  usql postgres://db:pass@localhost:5433/db?sslmode=disable
Connected with driver postgres (PostgreSQL 13.5 (Debian 13.5-1.pgdg110+1))
Type "help" for help.

pg:db@localhost:5433/db=>
nineinchnick commented 2 years ago

It doesn't ignore it. You're connecting to the default port 5432 but have 5433 in your .usqlpass file, which doesn't match. .usqlpass can't change defaults.

Crandel commented 1 year ago

It doesn't ignore it. You're connecting to the default port 5432 but have 5433 in your .usqlpass file, which doesn't match. .usqlpass can't change defaults.

But I mentioned port 5433 here postgres:localhost:5433:db:db:pass in .usqlpass.

nineinchnick commented 1 year ago

Can you try running usql pg://localhost:5433 or usql pg://postgres@localhost:5433?

kenshaw commented 1 year ago

@Crandel the issue is that the way the pass file works is that it matches the URL you're putting in, and fills in the missing fields. You would need to do usql postgres://<host>:5433 in order to use what you listed in your pass file.

Crandel commented 1 year ago

Now it works, thank you!