# Database Connection Timeout Troubleshooting

## Issue
PostgreSQL connection timeout to `20.197.43.96:5432`

## Current Status
- **Database Type**: PostgreSQL
- **Host**: 20.197.43.96
- **Port**: 5432
- **Database**: mtv_sms
- **Connection Status**: ❌ Not reachable (100% packet loss on ping)

## Troubleshooting Steps

### 1. Check Network Connectivity
```bash
# Test if server is reachable
ping -c 4 20.197.43.96

# Test PostgreSQL port
telnet 20.197.43.96 5432
# OR
nc -zv 20.197.43.96 5432
```

### 2. Check PostgreSQL Server Status
- Verify the PostgreSQL server is running
- Check if the server is accessible from your network
- Verify firewall rules allow connections from your IP

### 3. Check Firewall Rules
On the PostgreSQL server (20.197.43.96), ensure:
- Port 5432 is open
- Your application server's IP is whitelisted in `pg_hba.conf`
- Firewall allows connections from your IP

### 4. Verify Database Credentials
Check your `.env` file:
```env
DB_CONNECTION=pgsql
DB_HOST=20.197.43.96
DB_PORT=5432
DB_DATABASE=mtv_sms
DB_USERNAME=postgres
DB_PASSWORD=multitv@%32SMS
```

### 5. Temporary Workaround: Use File Sessions
If you need the application to work while fixing the database connection:

Edit `.env`:
```env
SESSION_DRIVER=file
```

Or edit `config/session.php`:
```php
'driver' => 'file', // Change from 'database' to 'file'
```

### 6. Alternative: Use SQLite for Development
If PostgreSQL is not available, you can temporarily use SQLite:

Edit `.env`:
```env
DB_CONNECTION=sqlite
# Remove or comment out DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD
```

## Solutions

### Solution 1: Fix Network Connectivity
1. Contact your network administrator
2. Verify the PostgreSQL server IP is correct
3. Check VPN/network routing if applicable
4. Ensure firewall rules allow your IP

### Solution 2: Use Connection Pooling
If the server is intermittently available, consider using a connection pooler like PgBouncer.

### Solution 3: Switch to Local Database
If this is a development environment, consider using a local PostgreSQL instance or SQLite.

## Configuration Changes Made
- Added timeout options to `config/database.php` for PostgreSQL connection
- You can now set `DB_TIMEOUT` and `DB_CONNECT_TIMEOUT` in your `.env` file

