cli: Supabase db diff fails to connect to database
Bug Report
Describe the bug
Running supabase db diff throws a “failed to connect” error:
failed to connect to `host=localhost user=postgres database=postgres`: dial error (dial tcp 127.0.0.1:54320: connect: connection refused)
To Reproduce
Steps to reproduce the behavior:
- Run
supabase db reset - Make a change via the web ui (optional)
- Run
supabase db diff - See error
Expected behavior
Produce output as the command usually would.
System Info
- OS: macOS 13.4.1
- Version of CLI: 1.106.1 (also fails with beta, 1.110.2)
- Version of Node.js: v18.15.0
Additional context
In case it’s helpful: When I run docker ps in another terminal while running supabase db diff, during its Creating shadow database... output / waiting time, I can see the target process running:
3189bce66164 public.ecr.aws/supabase/postgres:15.1.0.117 "sh -c 'cat <<'EOF' …" 1 second ago Up Less than a second (health: starting) 0.0.0.0:54320->5432/tcp, :::54320->5432/tcp
Here’s the full debug output:
Full debug output
% supabase db diff --debug | pbcopy
Supabase CLI 1.106.1
Connecting to local database...
2023/10/29 15:31:35 Connect Start: tcp [::1]:54322
2023/10/29 15:31:35 Connect Error: tcp [::1]:54322 dial tcp [::1]:54322: connect: connection refused
2023/10/29 15:31:35 Connect Start: tcp 127.0.0.1:54322
2023/10/29 15:31:35 Connect Done: tcp 127.0.0.1:54322
2023/10/29 15:31:35 PG Send: {"Type":"StartupMessage","ProtocolVersion":196608,"Parameters":{"database":"postgres","user":"postgres"}}
2023/10/29 15:31:35 PG Recv: {"Type":"AuthenticationSASL","AuthMechanisms":["SCRAM-SHA-256"]}
2023/10/29 15:31:35 PG Send: {"Type":"SASLInitialResponse","AuthMechanism":"SCRAM-SHA-256","Data":"n,,n=,r=wXSRHl7QZKN1F7h9VxR3g9EW"}
2023/10/29 15:31:35 PG Recv: {"Type":"AuthenticationSASLContinue","Data":"r=wXSRHl7QZKN1F7h9VxR3g9EWGFxi27bdYXvKRBGoN+ihfZ5F,s=V6sB21EybtDJi/QvHZevGQ==,i=4096"}
2023/10/29 15:31:35 PG Send: {"Type":"SASLResponse","Data":"c=biws,r=wXSRHl7QZKN1F7h9VxR3g9EWGFxi27bdYXvKRBGoN+ihfZ5F,p=Gpu1pmTIJ78DWushWXy27fSDZtrv0Ms8RgPSIZdkDng="}
2023/10/29 15:31:35 PG Recv: {"Type":"AuthenticationSASLFinal","Data":"v=Km4X5HTphFn4pCOkMM0/ALXoTVwDjmhHQ00yh3hb+v4="}
2023/10/29 15:31:35 PG Recv: {"Type":"AuthenticationOK"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"application_name","Value":""}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"client_encoding","Value":"UTF8"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"DateStyle","Value":"ISO, MDY"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"default_transaction_read_only","Value":"off"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"in_hot_standby","Value":"off"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"integer_datetimes","Value":"on"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"IntervalStyle","Value":"postgres"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"is_superuser","Value":"off"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"server_encoding","Value":"UTF8"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"server_version","Value":"15.1 (Ubuntu 15.1-1.pgdg20.04+1)"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"session_authorization","Value":"postgres"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"standard_conforming_strings","Value":"on"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterStatus","Name":"TimeZone","Value":"UTC"}
2023/10/29 15:31:35 PG Recv: {"Type":"BackendKeyData","ProcessID":16432,"SecretKey":1954759019}
2023/10/29 15:31:35 PG Recv: {"Type":"ReadyForQuery","TxStatus":"I"}
2023/10/29 15:31:35 PG Send: {"Type":"Parse","Name":"lrupsc_1_0","Query":"SELECT schema_name FROM information_schema.schemata WHERE NOT schema_name LIKE ANY($1) ORDER BY schema_name","ParameterOIDs":null}
2023/10/29 15:31:35 PG Send: {"Type":"Describe","ObjectType":"S","Name":"lrupsc_1_0"}
2023/10/29 15:31:35 PG Send: {"Type":"Sync"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParseComplete"}
2023/10/29 15:31:35 PG Recv: {"Type":"ParameterDescription","ParameterOIDs":[1009]}
2023/10/29 15:31:35 PG Recv: {"Type":"RowDescription","Fields":[{"Name":"schema_name","TableOID":13330,"TableAttributeNumber":2,"DataTypeOID":19,"DataTypeSize":64,"TypeModifier":-1,"Format":0}]}
2023/10/29 15:31:35 PG Recv: {"Type":"ReadyForQuery","TxStatus":"I"}
2023/10/29 15:31:35 PG Send: {"Type":"Bind","DestinationPortal":"","PreparedStatement":"lrupsc_1_0","ParameterFormatCodes":[1],"Parameters":[{"binary":"00000001000000000000001900000018000000010000000461757468000000097067626f756e636572000000087265616c74696d650000000a5c5f7265616c74696d650000000773746f726167650000000b5c5f616e616c79746963730000001373757061626173655c5f66756e6374696f6e730000001473757061626173655c5f6d6967726174696f6e7300000013696e666f726d6174696f6e5c5f736368656d610000000570675c5f250000000463726f6e000000076772617068716c0000000f6772617068716c5c5f7075626c6963000000036e6574000000087067736f6469756d0000000f7067736f6469756d5c5f6d61736b73000000057067746c650000000672657061636b0000000574696765720000000b74696765725c5f646174610000000e74696d657363616c6564625c5f25000000105c5f74696d657363616c6564625c5f2500000008746f706f6c6f6779000000057661756c74"}],"ResultFormatCodes":[1]}
2023/10/29 15:31:35 PG Send: {"Type":"Describe","ObjectType":"P","Name":""}
2023/10/29 15:31:35 PG Send: {"Type":"Execute","Portal":"","MaxRows":0}
2023/10/29 15:31:35 PG Send: {"Type":"Sync"}
2023/10/29 15:31:35 PG Recv: {"Type":"BindComplete"}
2023/10/29 15:31:35 PG Recv: {"Type":"RowDescription","Fields":[{"Name":"schema_name","TableOID":13330,"TableAttributeNumber":2,"DataTypeOID":19,"DataTypeSize":64,"TypeModifier":-1,"Format":1}]}
2023/10/29 15:31:35 PG Recv: {"Type":"DataRow","Values":[{"text":"app_admin"}]}
2023/10/29 15:31:35 PG Recv: {"Type":"DataRow","Values":[{"text":"dramatiq"}]}
2023/10/29 15:31:35 PG Recv: {"Type":"DataRow","Values":[{"text":"extensions"}]}
2023/10/29 15:31:35 PG Recv: {"Type":"DataRow","Values":[{"text":"public"}]}
2023/10/29 15:31:35 PG Recv: {"Type":"CommandComplete","CommandTag":"SELECT 4"}
2023/10/29 15:31:35 PG Recv: {"Type":"ReadyForQuery","TxStatus":"I"}
Creating shadow database...
2023/10/29 15:31:35 PG Send: {"Type":"Terminate"}
2023/10/29 15:31:35 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:35 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:35 Send Done
2023/10/29 15:31:35 Recv First Byte
2023/10/29 15:31:35 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:35 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:35 Sent Header: Content-Length [306]
2023/10/29 15:31:35 Sent Header: Content-Type [application/json]
2023/10/29 15:31:35 Send Done
2023/10/29 15:31:35 Recv First Byte
2023/10/29 15:31:35 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:35 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:35 Sent Header: Content-Length [11863]
2023/10/29 15:31:35 Sent Header: Content-Type [application/json]
2023/10/29 15:31:35 Send Done
2023/10/29 15:31:35 Recv First Byte
2023/10/29 15:31:35 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:35 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:35 Sent Header: Content-Length [0]
2023/10/29 15:31:35 Sent Header: Content-Type [text/plain]
2023/10/29 15:31:35 Send Done
2023/10/29 15:31:36 Recv First Byte
2023/10/29 15:31:36 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:36 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:36 Send Done
2023/10/29 15:31:36 Recv First Byte
2023/10/29 15:31:37 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:37 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:37 Send Done
2023/10/29 15:31:37 Recv First Byte
2023/10/29 15:31:38 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:38 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:38 Send Done
2023/10/29 15:31:38 Recv First Byte
2023/10/29 15:31:39 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:39 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:39 Send Done
2023/10/29 15:31:39 Recv First Byte
2023/10/29 15:31:40 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:40 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:40 Send Done
2023/10/29 15:31:40 Recv First Byte
2023/10/29 15:31:41 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:41 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:41 Send Done
2023/10/29 15:31:41 Recv First Byte
2023/10/29 15:31:42 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:42 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:42 Send Done
2023/10/29 15:31:42 Recv First Byte
2023/10/29 15:31:43 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:43 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:43 Send Done
2023/10/29 15:31:43 Recv First Byte
2023/10/29 15:31:44 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:44 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:44 Send Done
2023/10/29 15:31:44 Recv First Byte
2023/10/29 15:31:45 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:45 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:45 Send Done
2023/10/29 15:31:45 Recv First Byte
2023/10/29 15:31:46 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:46 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:46 Send Done
2023/10/29 15:31:46 Recv First Byte
2023/10/29 15:31:47 Sent Header: Host [api.moby.localhost]
2023/10/29 15:31:47 Sent Header: User-Agent [Docker-Client/unknown-version (darwin)]
2023/10/29 15:31:47 Send Done
2023/10/29 15:31:47 Recv First Byte
2023/10/29 15:31:47 Connect Start: tcp [::1]:54320
2023/10/29 15:31:47 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:47 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:47 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:47 Connect Start: tcp [::1]:54320
2023/10/29 15:31:47 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:47 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:47 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:48 Connect Start: tcp [::1]:54320
2023/10/29 15:31:48 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:48 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:48 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:48 Connect Start: tcp [::1]:54320
2023/10/29 15:31:48 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:48 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:48 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:49 Connect Start: tcp [::1]:54320
2023/10/29 15:31:49 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:49 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:49 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:49 Connect Start: tcp [::1]:54320
2023/10/29 15:31:49 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:49 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:49 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:50 Connect Start: tcp [::1]:54320
2023/10/29 15:31:50 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:50 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:50 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:50 Connect Start: tcp [::1]:54320
2023/10/29 15:31:50 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:50 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:50 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:51 Connect Start: tcp [::1]:54320
2023/10/29 15:31:51 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:51 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:51 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:51 Connect Start: tcp [::1]:54320
2023/10/29 15:31:51 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:51 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:51 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:52 Connect Start: tcp [::1]:54320
2023/10/29 15:31:52 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:52 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:52 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:52 Connect Start: tcp [::1]:54320
2023/10/29 15:31:52 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:52 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:52 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:53 Connect Start: tcp [::1]:54320
2023/10/29 15:31:53 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:53 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:53 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:53 Connect Start: tcp [::1]:54320
2023/10/29 15:31:53 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:53 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:53 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:54 Connect Start: tcp [::1]:54320
2023/10/29 15:31:54 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:54 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:54 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:54 Connect Start: tcp [::1]:54320
2023/10/29 15:31:54 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:54 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:54 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:55 Connect Start: tcp [::1]:54320
2023/10/29 15:31:55 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:55 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:55 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:55 Connect Start: tcp [::1]:54320
2023/10/29 15:31:55 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:55 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:55 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:56 Connect Start: tcp [::1]:54320
2023/10/29 15:31:56 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:56 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:56 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
2023/10/29 15:31:56 Connect Start: tcp [::1]:54320
2023/10/29 15:31:56 Connect Error: tcp [::1]:54320 dial tcp [::1]:54320: connect: connection refused
2023/10/29 15:31:56 Connect Start: tcp 127.0.0.1:54320
2023/10/29 15:31:56 Connect Error: tcp 127.0.0.1:54320 dial tcp 127.0.0.1:54320: connect: connection refused
failed to connect to `host=localhost user=postgres database=postgres`: dial error (dial tcp 127.0.0.1:54320: connect: connection refused)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (7 by maintainers)
I believe the second error can be resolved by running
supabase linkagain. That will configure the pooler url locally for your project.I will ping our internal team regarding the first error. It seems like the pooler response may not be fully compliant.
thanks, that actually worked. I re-linked the project and
npx supabase@beta db pullworked fine.This should be resolved in beta release v1.141.2
Yes the workaround is to pass in the pooler url via
--db-urlflag which resolves to IPv4 address.npx supabase@beta db push --db-url ...worked for me, even though test-ipv6.com showed “No IPv6 address detected”.This should have been a new issue.
The Time Has Come… for IPv6
@emmyduruc Sorry to be the bearer of bad news but it looks like your network does not support IPv6. Check here: https://test-ipv6.com Or from the command line: curl -6 https://ifconfig.co/ip You should see an IPv6 address in your connection settings, not just an IPv4.
If not: Try another network, maybe share your phone’s hotspot, a neighbor, or public access point.
You’re gonna want to read this, you may need to opt into the IPv4 add on if you cannot resolve your local network IPv6 issue. https://supabase.com/docs/guides/database/connecting-to-postgres
From this issue: PGBouncer and IPv4 Deprecation #17817 ):
However, this did not work for me. I had to break down and finally setup IPv6 on my home firewall. I was able to use my phone’s hotspot to push db migrations in the interim.
To this date, running Supabase 1.142.2, I can relink on an IPv6 network, stop/start supabase local, but still cannot perform any action that attempts to connect to the remote db when on an IPv4 only network.
Thank’s @Greyvend, I’ll have to give that a go on another project. Definitely do not want to pull the beta on a production project.
Update: Went ahead and tried this out using a command with no side-effects and it does work for me as well. (disabled IPv6 for the test) Thank you Serge!
pnpx supabase@beta migration list --db-url postgres://[USER].[PROJ-REF]:[PASSWORD]@aws-0-us-west-1.pooler.supabase.com:[PORT]/[DB-NAME]
got the same error on
db pulltoday. ~this solved it.~spoke too soon, now I have this issue: https://github.com/supabase/cli/issues/1574
updated the cli to the newest version. still an issue, although error message a bit more verbose.
system: System Version: macOS 14.3 (23D56) Kernel Version: Darwin 23.3.0