Question
How do I do a simple rails db:drop
on fly.io?
Background
I tried
fly ssh console -C "/app/bin/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1"
and also shelling in via
fly ssh myapp
then
/app/bin/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1
but both give the same error:
# /app/bin/rails db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1
D, [2022-12-03T07:19:04.077483 #564] DEBUG -- : (5010.1ms) DROP DATABASE IF EXISTS "myapp"
PG::ObjectInUse: ERROR: database "myapp" is being accessed by other users
DETAIL: There is 1 other session using the database.
Couldn't drop database 'myapp'
rails aborted!
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR: database "myapp" is being accessed by other users
DETAIL: There is 1 other session using the database.
Notes
- All browsers accessing the site are closed
- All shell sessions are ended
- I tried using
ps -ef | grep postgres
to get the process id in order to kill it, but all I see is/bin/sh: 18: ps: not found
, and - Related thread.
Ideas
It may be possible to force postress to kill all connections to allow the db:drop to succeed (although I haven't worked out how to do that yet)
It may be possible to delete all the database tables (suggested here)