Skip to content

Latest commit

 

History

History
163 lines (120 loc) · 3.21 KB

File metadata and controls

163 lines (120 loc) · 3.21 KB

Database Issues? Here's What to Do

🔴 Current Error: Connection Timeout

Your app is trying to connect to a Neon PostgreSQL database but getting ETIMEDOUT errors.

Quick Diagnosis

Check if your .env.local has a DATABASE_URL:

cat .env.local

You should see something like:

DATABASE_URL=postgresql://user:password@host/database?sslmode=require

💡 Solutions (Pick One)

Solution 1: Use Local PostgreSQL (Fastest for Testing)

# Install PostgreSQL
brew install postgresql  # macOS
sudo apt install postgresql  # Ubuntu
# Download installer for Windows

# Start PostgreSQL
brew services start postgresql  # macOS
sudo systemctl start postgresql  # Ubuntu

# Create database
createdb k8s

# Update .env.local
echo 'DATABASE_URL=postgresql://postgres@localhost:5432/k8s' > .env.local

# Restart app
npm run dev

✅ This works immediately!


Solution 2: Fix Neon Connection

Your .env.local already has Neon configured. Try these fixes:

Check 1: Is the database active?

Check 2: Add IP to whitelist

# See your current IP
curl https://api.ipify.org

# Then in Neon Dashboard:
# Settings → IP Whitelist → Add IP
# Or allow all: 0.0.0.0/0

Check 3: Test the connection string

# Copy your DATABASE_URL from .env.local
DATABASE_URL="postgresql://..." npm run dev

Solution 3: Switch Database Provider

If Neon isn't working, try free alternatives:

Railway.app (Very Easy)

# 1. Push to GitHub
git push origin main

# 2. Sign up at https://railway.app
# 3. Connect your GitHub repo
# 4. Create PostgreSQL plugin (automatic DATABASE_URL)
# 5. Deploy!

Heroku + Postgres (Also Easy)

# 1. Install Heroku CLI
# 2. heroku login
# 3. heroku create my-app
# 4. heroku addons:create heroku-postgresql:hobby-dev
# 5. git push heroku main

🧪 Test Your Database Connection

# Create a test file
cat > test-db.js << 'EOF'
const { Pool } = require('pg');
const pool = new Pool({ connectionString: process.env.DATABASE_URL });

pool.query('SELECT NOW()', (err, res) => {
  if (err) {
    console.error('❌ Connection failed:', err.message);
  } else {
    console.log('✅ Connected! Current time:', res.rows[0].now);
  }
  process.exit();
});
EOF

# Run the test
DATABASE_URL="YOUR_CONNECTION_STRING" node test-db.js

📋 Recommended Setup

For development:

  • Use local PostgreSQL
  • Set: DATABASE_URL=postgresql://postgres@localhost:5432/k8s

For production/deployment:

  • Use Neon, Railway, or AWS RDS
  • Set DATABASE_URL in your hosting provider's environment variables

🆘 Still Not Working?

  1. Check PostgreSQL is running

    psql -U postgres -c "SELECT 1"
  2. Check your connection string format

    postgresql://username:password@host:port/database
    
  3. Check firewall/network

    ping your-database-host.com
  4. Check with verbose logs

    DEBUG=* npm run dev

Need help? Check these: