All Products
Search
Document Center

ApsaraDB RDS:Connect RDS for PostgreSQL to a self-managed domain

Last Updated:Mar 28, 2026

Active Directory (AD) authentication lets enterprise users log in to your RDS PostgreSQL instance with their AD credentials — no separate database passwords required. This guide walks you through configuring an AD domain controller on an Elastic Compute Service (ECS) instance, then connecting your RDS instance to that self-managed AD domain using LDAP.

How it works

When a user connects to the RDS instance, the instance forwards the authentication request to the AD domain controller over Lightweight Directory Access Protocol (LDAP). The domain controller verifies the user's credentials and returns the result. If AD authentication is enabled for the connection, the AD domain controller manages password verification. If AD is not in use for a given connection, ApsaraDB RDS falls back to its own password verification.

The RDS instance and the AD domain controller communicate exclusively over the private network. Both must reside in the same virtual private cloud (VPC).

Prerequisites

Before you begin, ensure that you have:

  • An ApsaraDB RDS for PostgreSQL instance running PostgreSQL 10 or later, minor engine version 20210228 or later, and using cloud disks. To update the minor engine version, see Update the minor engine version of an ApsaraDB RDS for PostgreSQL instance

  • An ECS instance in the same VPC as the RDS instance, running Windows Server 2016 or later

  • The ECS security group configured to allow inbound traffic from the private IP address of the RDS instance. See Add a security group rule. If the ECS firewall is enabled, configure it to allow the same traffic (the firewall is disabled by default)

  • A domain account that belongs to the Domain Admins group

  • Access to the ApsaraDB RDS console

Step 1: Set up the AD domain controller on ECS

The AD domain controller must run Windows Server. This guide uses Windows Server 2016 as an example.
  1. Log in to the ECS instance and open Server Manager.

  2. In the left-side navigation pane, click Dashboard, then click Add roles and features.

    添加角色和功能

  3. In the Add Roles and Features Wizard, configure each tab as follows:

    The ECS instance must have a static IP address. A dynamic IP address causes the DNS server to become unavailable.
    TabSetting
    Before You BeginUse the default settings.
    Installation TypeUse the default settings.
    Server SelectionUse the default settings.
    Server RolesSelect Active Directory Domain Services, then click Add Features in the dialog box. Select DNS Server, then click Add Features.
    FeaturesUse the default settings.
    AD DSUse the default settings.
    DNS ServerUse the default settings.
    InstallClick Install.
  4. After installation completes, click Close.

  5. In the left-side navigation pane, click AD DS. In the upper-right corner, click More.

    AD DS更多

  6. In the All Servers Task Details and Notifications panel, click Promote this server to a domain controller.

    将此服务器提升为域控制器

  7. In the Active Directory Domain Services Configuration Wizard, configure the following:

    TabSetting
    Deployment ConfigurationSelect Add a new forest and set the Root domain name. This example uses pgsqldomain.net (pgsqldomain is the prefix, net is the suffix). Use the same root domain name throughout the configuration. 添加新林,设置域名
    Domain Controller OptionsSet a Directory Services Restore Mode (DSRM) password. 设置还原密码
    Server SelectionClear Create DNS delegation. 创建 DNS 委派
    Additional Options, Paths, Review OptionsUse the default settings.
    Prerequisites CheckClick Install.
  8. After the ECS instance restarts as an AD domain controller, log back in before proceeding to the next step.

Step 2: Add users to the AD domain controller

You need two types of AD users: an administrator user (used by LDAP to bind to the directory) and a standard user (used to log in to the RDS instance).

Add an administrator user

  1. In Server Manager, click AD DS in the left-side navigation pane. Right-click the domain controller and select Active Directory Users and Computers.

    添加ad用户

  2. Expand pgsqldomain.net, right-click Users, and choose New > User.

    pgsqldomain.net is the root domain name set in Step 1.

    添加用户

  3. Enter a username and click Next.

    新建对象-用户

  4. Enter a password, select Password never expires, then click Next and Finish.

    设置密码

  5. Double-click the new user and add them to the Domain Admins group.

    加入管理员组

    添加管理员组结果

Add a standard user

Follow the same steps as above to create a standard user. Skip the step of adding the user to the Domain Admins group.

This example uses ldapuser as the standard user. This account is used to log in to the RDS instance.

Step 3: Configure security group rules for ECS

The AD domain controller requires several ports to be open. Use a dedicated security group for the domain controller rather than sharing it with other ECS instances.

  1. Log in to the ECS console and go to Instances & Images > Instances.

  2. In the top navigation bar, select the region of the ECS instance.

  3. Click the ECS instance ID, then click Security Groups in the left-side navigation pane.

  4. Click Add Rules in the Actions column.

  5. On the Inbound tab, click Add Rule to allow the RDS instance to reach the ECS instance on the following ports:

    ProtocolPortService
    TCP88Kerberos authentication
    TCP135RPC
    TCP/UDP389LDAP
    TCP445CIFS
    TCP3268Global Catalog
    TCP/UDP53DNS
    TCP49152–65535Default dynamic port range (enter as 49152/65535)

Step 4: Configure the RDS instance

Create a matching database account

  1. In the ApsaraDB RDS console, find the RDS instance and click its ID.

  2. Create an account named ldapuser. See Create an account.

    The RDS account name must match the AD standard user name exactly (ldapuser in this example). The passwords can differ. When AD authentication is active, the AD domain controller verifies the password. When it is inactive, ApsaraDB RDS uses the account password set in the console.

    dbadminrds账号

Configure the AD domain service

  1. In the left-side navigation pane, click Accounts, then open the AD Domain Services tab. The first time you open this tab, the system creates two default records:

    host    all            all    0.0.0.0/0    md5
    host    replication    all    0.0.0.0/0    md5

    You can delete or modify these records.

  2. Click Edit on the first record and configure the following parameters: For the OPTION field, use the following format:

    ParameterExample valueDescription
    Priority0Record priority. 0 is the highest priority and is auto-assigned to the first record.
    TYPEhostConnection type. host matches both SSL and non-SSL TCP/IP connections. hostssl matches SSL connections only (requires SSL encryption to be enabled). hostnossl matches non-SSL connections only.
    DATABASEallDatabases accessible to the specified users. Use all to allow access to all databases. Separate multiple databases with commas.
    USERldapuserAD standard users allowed to connect. Separate multiple users with commas. Domain Admins accounts cannot be used here.
    ADDRESS0.0.0.0/0Allowed source IP addresses. 0.0.0.0/0 allows connections from any IP address.
    MASK(leave blank)Subnet mask for the IP address in ADDRESS. Leave blank when using CIDR notation.
    METHODldapAuthentication method. Must be lowercase. Valid values: trust, reject, scram-sha-256, md5, password, gss, sspi, ldap, radius, cert, pam.
    OPTIONSee belowLDAP options required when METHOD is ldap.
    ldapserver=<Private IP address of the ECS instance> ldapbasedn="CN=Users,DC=<domain prefix>,DC=<domain suffix>" ldapbinddn="CN=<AD administrator username>,CN=Users,DC=<domain prefix>,DC=<domain suffix>" ldapbindpasswd="<AD administrator password>" ldapsearchattribute="sAMAccountName"

    For the example domain pgsqldomain.net with administrator user adminuser:

    ldapserver=<ECS private IP> ldapbasedn="CN=Users,DC=pgsqldomain,DC=net" ldapbinddn="CN=adminuser,CN=Users,DC=pgsqldomain,DC=net" ldapbindpasswd="<adminuser password>" ldapsearchattribute="sAMAccountName"

    For the complete list of OPTION parameters, see the PostgreSQL authentication methods documentation.

  3. Click add to the right of the AD domain service record to add a fallback record with the following values:

    host    all    all    0.0.0.0/0    md5
  4. Click OK, then click Submit.

    After you click Submit, the RDS instance enters Maintaining Instance status for about one minute. New configurations take effect for new connections only. Close existing connections and reconnect for the changes to apply.

Step 5: Test the connection

Connect to the RDS instance using the psql command-line tool. Use the AD standard user's credentials, not the RDS account password.

psql -h <RDS instance endpoint> -U ldapuser -p 5432 -d postgres

When prompted for a password, enter the AD password for ldapuser (not the RDS account password).

Install the PostgreSQL client before using psql. For other connection methods, see Connect to an ApsaraDB RDS for PostgreSQL instance.

Import AD domain service records in bulk (optional)

To configure multiple AD domain service records at once, use the bulk import feature.

导入AD域服务信息

Import modes:

  • Overwrite existing service information — replaces all current records.

  • Additional service information (highest priority) — inserts the new records at the beginning, giving them higher priority than existing records.

  • Additional service information (lowest priority) — appends the new records at the end, giving them lower priority than existing records.

Required format:

TYPE|DATABASE|USER1|ADDRESS|MASK|METHOD|OPTION

Sample record:

host|all|ldapuser|0.0.0.0/0||ldap|ldapserver=<ECS private IP> ldapbasedn="CN=Users,DC=pgsqldomain,DC=net" ldapbinddn="CN=<AD administrator username>,CN=Users,DC=pgsqldomain,DC=net" ldapbindpasswd="<AD administrator password>" ldapsearchattribute="sAMAccountName"

Enter the records in the Edit AD domain text box, then select an import mode and submit.

View AD domain service edit history

  1. In the RDS console, click the instance ID, then go to Accounts > AD Domain Services Edit History.

  2. Click changedetails in the Actions column to view the change details. If a modification failed, the status shows Not Taking Effect. Click Change log to see the error message.

    查看AD域修改记录

What's next