Im not able to connect database for deployment

Image size: 123 MB
Starting instance
Pulling container image
Preparing kernel init
Starting virtual machine
Preparing to run: /app/bin/migrate as nobody
03:22:58.108 [error] GenServer #PID<0.135.0> terminating
** (RuntimeError) connect raised KeyError exception: key :database not found. The exception details are hidden, as they may contain sensitive data such as dat (elixir 1.12.3) lib/keyword.ex:420: Keyword.fetch!/2
(stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
** (RuntimeError) connect raised KeyError exception: key :database not found. The exception details are hidden, as they may contain sensitive data such as datError Release command failed, deployment aborted.

config :my_app, Fchatapp.Repo,
       url: "postgres://postgres:1770cf3fe339bb8b5263ab6571c91ec8b08f74214@chatapp-db.internal:5432/chatapp-db",
         # DON'T FORGET THE FOLLOWING LINE
       socket_options: [:inet6],
       pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

Hello @usama. Did you create the database manually(through psql) and specifically called it chatapp-db or did you use flyctl postgres attach. If the latter is what you did flyctl would have created a database with the same name as the app you are trying to attach a cluster to and injected a DATABASE_URL secret in the app for you.

To see what databases you have in your cluster flyctl pg connect can give access to your cluster psql console(make sure your cluster is running an updated image with flyctl image show) or use any of these options documented here: Postgres on Fly

im biggner and not really sure how to get my db URL from fly.io

usama@Usamas-MacBook-Pro chatapp % flyctl image show
Update available 0.0.301 -> v0.0.302.
Run "flyctl version update" to upgrade.
Deployment Status
  Registry   = unknown  
  Repository = unknown  
  Tag        = unknown  
  Version    = unknown  
  Digest     = unknown  

usama@Usamas-MacBook-Pro chatapp % 

usama@Usamas-MacBook-Pro chatapp % flyctl postgres connect -a chatapp   
Update available 0.0.301 -> v0.0.302.
Run "flyctl version update" to upgrade.
Error Malformed version: nknown
Connecting to chatapp-db.internal... complete
psql (14.1 (Debian 14.1-1.pgdg110+1))W
Type "help" for help.WWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
postgres=# WWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

@usama Looks like there’s a bug that needs to be addressed. I will plan on taking a look at this today. For now, could you give this a try?

fly ssh console -C "connect" --app chatapp-db

usama@Usamas-MacBook-Pro chatapp % fly ssh console -C "connect" --app chatapp-db
Update available 0.0.301 -> v0.0.302.
Run "fly version update" to upgrade.
WARN app flag 'chatapp-db' does not match app name in config file 'chatapp'
? Continue using 'chatapp-db' (y/N) 

after pressing y

Connecting to top1.nearest.of.chatapp-db.internal... complete
psql (14.1 (Debian 14.1-1.pgdg110+1))WWWWWWWWWWWWWWWWW
Type "help" for help.WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
postgres=# WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWW

Interesting, what OS are you running? Also, aside from all of the extra characters added, does it still work?

MacOS
yes it connects like this but it is not allowing deployment its first time I’m deploying phoenix with fly.io

Even I have tried connecting with heroku database that is also not working

Thats what it says now

--> Pushing image done
Image: registry.fly.io/chatapp:deployment-1646323131
Image size: 123 MB
         Starting instance
         Pulling container image
         Unpacking image
         Preparing kernel init
         Configuring firecracker
         Starting init (commit: 0c50bff)...
         2022/03/03 15:59:18 listening on [fdaa:0:512b:a7b:7b:bff7:579d:2]:22 (DNS: [fdaa::3]:53)
         ** (ArgumentError) argument error
             (kernel 7.3) gen_tcp.erl:169: :gen_tcp.connect/4
             (postgrex 0.15.13) lib/postgrex/protocol.ex:191: Postgrex.Protocol.connect_and_handshake/6
             (db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
             (stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
         [error] GenServer #PID<0.136.0> terminating
             (kernel 7.3) gen_tcp.erl:169: :gen_tcp.connect/4
             (postgrex 0.15.13) lib/postgrex/protocol.ex:191: Postgrex.Protocol.connect_and_handshake/6
             (db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
             (stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
         [error] GenServer #PID<0.137.0> terminating
         ** (ArgumentError) argument error
             (kernel 7.3) gen_tcp.erl:169: :gen_tcp.connect/4
             (postgrex 0.15.13) lib/postgrex/protocol.ex:622: Postgrex.Protocol.connect/5
             (postgrex 0.15.13) lib/postgrex/protocol.ex:191: Postgrex.Protocol.connect_and_handshake/6
             (postgrex 0.15.13) lib/postgrex/protocol.ex:160: Postgrex.Protocol.connect_endpoints/6
             (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
         Last message: nil
         ** (ArgumentError) argument error
             (postgrex 0.15.13) lib/postgrex/protocol.ex:622: Postgrex.Protocol.connect/5
             (postgrex 0.15.13) lib/postgrex/protocol.ex:191: Postgrex.Protocol.connect_and_handshake/6
             (db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
             (stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Error Release command failed, deployment aborted
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

When i try to connect with heroku postgres db it gives this error

--> Pushing image done
image: registry.fly.io/chatapp:deployment-1646325512
image size: 123 MB
         Configuring firecracker
             (kernel 7.3) gen_tcp.erl:169: :gen_tcp.connect/4
             (postgrex 0.15.13) lib/postgrex/protocol.ex:160: Postgrex.Protocol.connect_endpoints/6
             (kernel 7.3) gen_tcp.erl:169: :gen_tcp.connect/4
             (db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
Error release command failed, deployment aborted

Probably a dumb question… but just to make sure… your config doesn’t actually say config :my_app, Fchatapp.Repo right?

But I have seen people do a copy paste from the older version of the docs and it fails because they didn’t change :my_app to actually be the name of their app.

@usama I’ve deleted your latest post because apparently, you pasted real credentials from your DB.

Here’s a redacted version:


i have changed the :my_to correct name but it still not allowing me I have shared the series of problem
I have tried it in different ways nothing working for me and I’m not sure how can I get the URL of instance that is running of fly.io that’s why I have tried with heroku database but that is also not working

config :fchatapp, Fchatapp.Repo,
       username: "REDACTED",
       password: "REDACTED",
       database: "REDACTED",
       hostname: " REDACTED",
       show_sensitive_data_on_connection_error: true,
       pool_size: 10


#config :fchatapp, Fchatapp.Repo,
#       username: "postgres",
#       password: "REDACTED",
#       database: "REDACTED",
#       hostname: " REDACTED",
#       show_sensitive_data_on_connection_error: true,
#       pool_size: 10

I can’t help but notice you used on hostname a space inside your string:

hostname: " myactualpassword"

Can you try to remove this blank space?