You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过PgAdmin及Django生产服务器连接Amazon Aurora Postgres求助

Hey there, let's walk through the most common issues that cause this kind of connection failure with Aurora PostgreSQL—since both PgAdmin and your Django app are hitting the same error, it's almost certainly a network or permission issue rather than a client-specific problem. Let's break this down step by step:

1. Check Your VPC Security Group Rules

This is the #1 reason for connection failures with Aurora, since it's deployed in a VPC by default. Here's what to do:

  • Head to the AWS RDS Console, find your Aurora cluster, and go to the Connectivity & security tab. Look for the "VPC security groups" section.
  • Click on the security group linked to your cluster to open the EC2 Security Groups page.
  • Verify the inbound rules:
    • There should be a rule allowing traffic on PostgreSQL's default port (5432) — if you changed the port during setup, use that instead.
    • For your local PgAdmin connection: Add your public IP address (you can get this with curl ifconfig.me in your terminal) as the source. You can temporarily use 0.0.0.0/0 to test (but don't leave this enabled long-term, it's insecure).
    • For your production server: Add the server's public IP, or if it's in the same VPC, its private IP range as the source.
2. Confirm the Database Endpoint & Port

It's easy to mix up endpoints when you're new to Aurora:

  • Aurora has two main endpoints: a cluster endpoint (for write operations) and a read-only endpoint. Make sure you're using the cluster endpoint unless you specifically need read-only access.
  • Double-check the port matches what you set during cluster creation (default is 5432).
  • Ensure you're using the full endpoint domain name (e.g., your-cluster.cluster-xxxxxx.us-east-1.rds.amazonaws.com — don't truncate it!).
3. Verify Database User Permissions

Sometimes the user you created doesn't have permission to connect remotely:

  • First, use the AWS RDS Console's Query Editor to connect to your database (this bypasses external network rules, so if this works, you know the database itself is healthy).
  • Run this query to check your user's connection permissions:
    SELECT usename, host FROM pg_hba_rule;
    
    Look for your user — if the host column isn't 0.0.0.0/0 or doesn't include your client IP range, you'll need to update it. For Aurora, you can modify this via the parameter group, or run:
    ALTER USER your_username WITH LOGIN CONNECTION LIMIT -1;
    GRANT ALL PRIVILEGES ON DATABASE your_db_name TO your_username;
    
  • Also, double-check that your password is correct — it's easy to mistype during setup!
4. Test Network Reachability for Your Production Server

If your Django server is failing to connect, add these checks:

  • On the production server, run telnet your-cluster-endpoint 5432 or nc -zv your-cluster-endpoint 5432 to see if the port is reachable. (AWS blocks ping, so don't rely on that.)
  • If your server is in a different VPC, make sure you have VPC peering or a transit gateway configured to allow traffic between the two VPCs.
  • Check if the server's local firewall or a network ACL is blocking outbound traffic on port 5432.
5. Double-Check Django's Database Configuration

For your Django app, there are a few extra things to confirm:

  • Make sure your settings.py has the correct database setup:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'your_db_name',
            'USER': 'your_db_user',
            'PASSWORD': 'your_db_password',
            'HOST': 'your-cluster-endpoint',
            'PORT': '5432',
        }
    }
    
  • Ensure you've installed the PostgreSQL adapter: Run pip install psycopg2-binary (for testing) or psycopg2 (for production, though you'll need system dependencies like libpq-dev first).
  • Check if you're using environment variables for credentials — it's easy to mistype a variable name!
Quick Troubleshooting Tip

If the AWS Query Editor connects successfully but your external clients don't, you can rule out database-level issues entirely and focus 100% on network security groups, firewalls, or endpoint typos.

内容的提问来源于stack exchange,提问作者TJB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:40:13