fly deploy fails to connect to Postgres - wrong port?

Hi,

fly deploy is failing on my Rails app due to not being able to reach postgres, at a point of docker build when activerecord tries to establish a connection I get this:

#0 5.225 /rails/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in `rescue in new_client': connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory (ActiveRecord::ConnectionNotEstablished)
#0 5.225 	Is the server running locally and accepting connections on that socket?

I can connect to the db with pg connect ( fly pg connect --app frdm-production). Curiously, postgres seems to be using a different port:

psql (15.3 (Debian 15.3-1.pgdg120+1))
Type "help" for help.

postgres=# SELECT name, setting
FROM pg_settings
WHERE name = 'port';
 name | setting 
------+---------
 port | 5433
(1 row)

these are the apps, created with the cli wizard:

fly apps list
NAME                    	OWNER   	STATUS  	PLATFORM	LATEST DEPLOY 
fly-builder-red-surf-271	personal	deployed	machines	             	
frdm                    	personal	pending 	machines	             	
frdm-production         	personal	deployed	machines	

is 5433 just the internal port that at some point in fly’s internal docker-compose equivalent gets mapped to the right port, 5432? Or is this a legit problem that is causing the connection to fail?

What this generally means is that the DATABASE_URL secret isn’t set. The easiest/best way to set this secret is to use the fly postgres attach command.

DATABASE_URL was set. I did fly detach and fly attach just to make sure the DATABASE_URL value is correct, and got the same error

If database URL is set, then the next most likely culprit is your config/database.yml. For information on how Rails resolves the port, see Configuring Rails Applications — Ruby on Rails Guides

Yep, that was it. I thought DATABASE_URL took precedence over and replaced database.yml, but rather they are merged. Thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.