Deploying a rails API app with postgress

I have the following setup -

  1. Created a new rails api only app with postgres
  2. Created a dockerfile and dockercompose and the app works fine
  3. Initialized a new app to deploy via flyctl launch
  4. Ran fly deploy

I get the following error
#20 2.459 rails aborted! #20 2.459 ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory #20 2.459 Is the server running locally and accepting #20 2.459 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"? #20 2.459 /app/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in rescue in new_client’
`

The symptoms indicate that you don’t have a DATABASE_URL secret set. Verify by running fly secrets list. Most likely this is because you didn’t answer yes to creating a postgres database when you ran fly launch.

The easiest way to proceed from here is to run fly postgres create, note the name of the new postgres application, and then within your rails application directory run fly postgres attach specifying that name.

1 Like

Thank you for the reply @rubys, turns out the issue was related to this link here - Unable to create apps in Chennai (India) region