The database nh-tourism-db is stuck in "pending" state and DATABASE_URL is not being set when attaching the database to the app.
Follow these steps in order on your local machine:
flyctl apps destroy nh-tourism-db --yesflyctl postgres create --name nh-tourism-db --region ewr --initial-cluster-size 1Important Notes:
- When prompted, accept the defaults
- Wait for the database to fully provision (should take 2-3 minutes)
- Look for "Postgres cluster nh-tourism-db created" message
flyctl postgres listExpected output: Database should show STATUS as "running" (not "pending")
flyctl postgres attach nh-tourism-db --app nh-tourismExpected output: Should see message like:
Postgres cluster nh-tourism-db is now attached to nh-tourism
The following secret was added to nh-tourism:
DATABASE_URL=postgres://...
flyctl secrets list --app nh-tourismExpected output: You should see DATABASE_URL in the list
flyctl deployThis will:
- Build the Docker container
- Run the release command (
rails db:prepare db:seed) - Start the application
# Check app status
flyctl status --app nh-tourism
# View logs
flyctl logs --app nh-tourism
# Test the site
curl https://nh-tourism.fly.devWait 3-5 minutes and check again:
flyctl postgres listIf still pending after 10 minutes, try:
flyctl apps restart nh-tourism-dbManually set it:
# Get the connection string
flyctl postgres db list --app nh-tourism-db
# Set it manually (replace with actual connection string from above)
flyctl secrets set DATABASE_URL="postgres://postgres:password@hostname:5432/nh_tourism" --app nh-tourismCheck logs:
flyctl logs --app nh-tourismCommon issues:
- "PG::ConnectionBad": DATABASE_URL is incorrect or database is not running
- "relation does not exist": Migrations need to run (should auto-run via db:prepare)
If the above doesn't work, try the newer Managed Postgres:
# Destroy old database
flyctl apps destroy nh-tourism-db --yes
# Create with mpg (Managed Postgres - newer, more stable)
flyctl mpg create --name nh-tourism-db --region ewr --initial-cluster-size 1
# Attach (same as before)
flyctl postgres attach nh-tourism-db --app nh-tourism
# Verify
flyctl secrets list --app nh-tourism
# Deploy
flyctl deployAfter successful deployment:
- Database:
nh-tourism-db(STATUS: running) - App:
nh-tourism(STATUS: running) - Secrets: DATABASE_URL, SECRET_KEY_BASE, AWS credentials, etc.
- URL: https://nh-tourism.fly.dev
- Admin login: admin / Cure8-Penpal4-Sapling0-Deputy1-Glory0
If you encounter errors, provide:
- Output from
flyctl postgres list - Output from
flyctl secrets list --app nh-tourism - Output from
flyctl logs --app nh-tourism