[Rails app] Fly Deploy failing with Is the server running locally and accepting

Hello,

I am trying to deploy a rails app with a postgres DB and deployment is failing at ‘release command’ step

below is the error

Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Preparing kernel init
	 Configuring firecracker
	 Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
	 no label, UUID=ff6fd307-4306-4bb0-87e0-9fed562816f7
	 Preparing to run: `bin/rails fly:release` as root
	 2022/12/09 08:19:04 listening on [fdaa:0:c7fe:a7b:81:7d85:4da2:2]:22 (DNS: [fdaa::3]:53)
	 rails aborted!
	 /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in `rescue in new_client'
	 /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
	 /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
	 /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
	 /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
	 /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/railties/databases.rake:92:in `block (2 levels) in <main>'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/commands/rake/rake_command.rb:18:in `perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.4/lib/rails/commands.rb:18:in `<main>'
	 Caused by:
	 PG::ConnectionBad: could not connect to server: No such file or directory

Running fly logs gives me below,

2022-12-09T08:19:07Z app[7d854da2] sin [info]rails aborted!
2022-12-09T08:19:07Z app[7d854da2] sin [info]ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
2022-12-09T08:19:07Z app[7d854da2] sin [info]	Is the server running locally and accepting
2022-12-09T08:19:07Z app[7d854da2] sin [info]	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
2022-12-09T08:19:07Z app[7d854da2] sin [info]/app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in `rescue in new_client'

I tried the deploy command for one of my existing app and that seems to be working fine. Can you please help me debug this. Thanks!

Best guess is that DATABASE_URL is not set? What does flyctl secrets list say?

Name Digest Created At (all empty)

How should I resolve this?

Thanks!

It seems like the secrets list is empty since this is a new app (and the secrets list command tries connecting to a running instance of the app I believe).

Nonetheless, you can try fly secrets set DATABASE_URL=postgres://url_to_your_database which will try a new release that includes the change to the environment variables. Or alternatively fly pg attach to attach a Fly-hosted postgres cluster to your app which internally performs this step as well.

If this is not enough you might want to double-check the configuration in your Rails app’s config/database.yml.

fly pg attach solved it for me.
Thanks for the help!

1 Like