🔍 PostgreSQL Connection Diagnostics

📋 System Information

PHP Version: 8.3.25
Operating System: Linux
Server Software: Apache
Script Path: /home/nizeman.com/httpdocs/quiz/db_diagnostics.php
Current Time: 2025-09-11 03:32:10

🔌 PHP Extensions Check

✅ PDO extension is loaded
✅ PDO_PGSQL extension is loaded
Available PDO Drivers: mysql, odbc, pgsql, sqlite

🌐 Network Connectivity Tests

Testing Host: 127.0.0.1

Attempting: 127.0.0.1:5432
✅ Socket connection successful to 127.0.0.1:5432
Testing database: postgres
✅ Database connection successful to: postgres
✅ Target database "engrprimusapps_quiz" exists!
✅ Successfully connected to target database!
✅ Leaderboard table accessible with 120 records
🎉 WORKING CONFIGURATION FOUND!
Host: 127.0.0.1
Port: 5432
Database: engrprimusapps_quiz
Username: engrprimusapps_devotions_prayers
Testing database: template1
✅ Database connection successful to: template1
✅ Target database "engrprimusapps_quiz" exists!
✅ Successfully connected to target database!
✅ Leaderboard table accessible with 120 records
🎉 WORKING CONFIGURATION FOUND!
Host: 127.0.0.1
Port: 5432
Database: engrprimusapps_quiz
Username: engrprimusapps_devotions_prayers
Testing database: engrprimusapps_devotions_prayers
❌ Database connection failed: SQLSTATE[08006] [7] connection to server at "127.0.0.1", port 5432 failed: FATAL: database "engrprimusapps_devotions_prayers" does not exist
Error Code: 7
DSN: pgsql:host=127.0.0.1;port=5432;dbname=engrprimusapps_devotions_prayers
Attempting: 127.0.0.1:5433
❌ Socket connection failed to 127.0.0.1:5433 - Connection refused (Error: 111)
Attempting: 127.0.0.1:5434
❌ Socket connection failed to 127.0.0.1:5434 - Connection refused (Error: 111)

Testing Host: localhost

Attempting: localhost:5432
✅ Socket connection successful to localhost:5432
Testing database: postgres
✅ Database connection successful to: postgres
✅ Target database "engrprimusapps_quiz" exists!
✅ Successfully connected to target database!
✅ Leaderboard table accessible with 120 records
🎉 WORKING CONFIGURATION FOUND!
Host: localhost
Port: 5432
Database: engrprimusapps_quiz
Username: engrprimusapps_devotions_prayers
Testing database: template1
✅ Database connection successful to: template1
✅ Target database "engrprimusapps_quiz" exists!
✅ Successfully connected to target database!
✅ Leaderboard table accessible with 120 records
🎉 WORKING CONFIGURATION FOUND!
Host: localhost
Port: 5432
Database: engrprimusapps_quiz
Username: engrprimusapps_devotions_prayers
Testing database: engrprimusapps_devotions_prayers
❌ Database connection failed: SQLSTATE[08006] [7] connection to server at "localhost" (::1), port 5432 failed: FATAL: database "engrprimusapps_devotions_prayers" does not exist
Error Code: 7
DSN: pgsql:host=localhost;port=5432;dbname=engrprimusapps_devotions_prayers
Attempting: localhost:5433
❌ Socket connection failed to localhost:5433 - Connection refused (Error: 111)
Attempting: localhost:5434
❌ Socket connection failed to localhost:5434 - Connection refused (Error: 111)

Testing Host: ::1

Attempting: ::1:5432
❌ Socket connection failed to ::1:5432 - php_network_getaddresses: getaddrinfo for failed: Name or service not known (Error: 0)
Attempting: ::1:5433
❌ Socket connection failed to ::1:5433 - php_network_getaddresses: getaddrinfo for failed: Name or service not known (Error: 0)
Attempting: ::1:5434
❌ Socket connection failed to ::1:5434 - php_network_getaddresses: getaddrinfo for failed: Name or service not known (Error: 0)

⚙️ Configuration Analysis

Your Current Configuration:

Host: localhost
Port: 5432
Database: engrprimusapps_quiz
Username: engrprimusapps_devotions_prayers
Password: ************ (12 characters)

Server Environment Variables:

PGHOST: Not set
PGPORT: Not set
PGDATABASE: Not set
PGUSER: Not set
PGPASSWORD: [Hidden]
DATABASE_URL: [Hidden]

🔧 Troubleshooting Steps

Common Issues and Solutions:

  1. Database doesn't exist: Run your setup_database.php script first
  2. PostgreSQL not running: Contact your hosting provider to start PostgreSQL
  3. Wrong credentials: Verify username/password with hosting provider
  4. Firewall blocking connection: Check if port 5432 is open
  5. Different host/port: Some hosts use different configurations
  6. SSL required: Some hosts require SSL connections

Try These Alternative Connection Strings:

// Option 1: With SSL
$dsn = "pgsql:host=localhost;port=5432;dbname=engrprimusapps_quiz;sslmode=require";

// Option 2: With specific SSL mode
$dsn = "pgsql:host=localhost;port=5432;dbname=engrprimusapps_quiz;sslmode=prefer";

// Option 3: Different timeout
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_TIMEOUT => 30,
PDO::ATTR_PERSISTENT => false
];

Contact Your Hosting Provider If:

  • No socket connections work on any host/port combination
  • You get "connection refused" errors consistently
  • You get authentication errors with correct credentials
  • PostgreSQL extensions are missing

Ask them for:

  • Correct PostgreSQL host and port
  • Database connection examples for your hosting environment
  • Whether SSL is required for connections
  • PostgreSQL server status and logs