PostgreSQL connection type

Updated at:

The PostgreSQL connection type connects EventBridge to PostgreSQL databases, enabling you to mount PostgreSQL tables as queryable event tables in the EventHouse Data Catalog.

Overview

The PostgreSQL connection type establishes connectivity between EventBridge and PostgreSQL databases. After you create a PostgreSQL connection, you can mount it in the EventHouse Data Catalog to map PostgreSQL tables as queryable event tables.

Supported PostgreSQL instances:

  • Alibaba Cloud ApsaraDB RDS for PostgreSQL (version 10 and later, 14 or later recommended)

  • Alibaba Cloud PolarDB for PostgreSQL

  • Self-managed PostgreSQL instances

Connection parameters

Parameter

Field name

Type

Required

Description

Host address

HostName

string

Yes

The PostgreSQL host address. For RDS instances, enter the instance domain name (such as pgm-xxx.pg.rds.aliyuncs.com). For self-managed instances, enter the IP address.

Port number

Port

string

Yes

The PostgreSQL port number. Default value: 5432.

Username

User

string

Yes

The database username. A read-only account is recommended.

Password

Password

string

Yes

The password for the database account.

Database name

DatabaseName

string

Yes

The target database name. PostgreSQL does not support cross-database queries, so this parameter is required.

Parameter example

{
  "HostName": "pgm-bp1xxxxx.pg.rds.aliyuncs.com",
  "Port": "5432",
  "User": "readonly_user",
  "Password": "your_password",
  "DatabaseName": "analytics_db"
}

Create a PostgreSQL connection

Create a connection in the console

  1. Log on to the EventBridge console.

  2. In the left-side navigation pane, choose Integration Center > Connection Management.

  3. In the top navigation bar, select a region and click Create Connection.

  4. Select PostgreSQL as the connection type and configure the connection parameters.

  5. Click Test Connection to verify connectivity.

  6. After the test is passed, click OK.

Create a connection by calling an API operation

Call the CreateConnection API operation to create a PostgreSQL connection:

{
  "ConnectionName": "my-pg-conn",
  "Type": "PostgreSQL",
  "Parameters": {
    "HostName": "pgm-bp1xxxxx.pg.rds.aliyuncs.com",
    "Port": "5432",
    "User": "readonly_user",
    "Password": "your_password",
    "DatabaseName": "analytics_db"
  }
}

Network configuration

Network type

Description

Scenario

Internet

Connects over the Internet. No additional configuration is required.

The PostgreSQL instance has public network access enabled. For RDS instances, enable the public endpoint.

VPC

Connects over a VPC.

The PostgreSQL instance is deployed in a VPC.

VPC connections require the following additional parameters:

  • VPC ID: The VPC where the PostgreSQL instance is located.

  • vSwitch ID: A vSwitch in the VPC.

  • Security group ID: The inbound rules of the security group must allow access to the PostgreSQL port (5432).

EventBridge automatically establishes network connectivity with your VPC. No additional network configuration is required.

In addition to the security group, verify that the pg_hba.conf file of PostgreSQL allows connections from EventBridge IP addresses. For RDS PostgreSQL, you can add the IP address in the whitelist settings on the console.

Usage scenarios

Catalog mount (supported)

Mount a PostgreSQL connection to an EventHouse Catalog to query PostgreSQL tables directly with SQL:

-- Query a users table in PostgreSQL
SELECT * FROM my_catalog.user_namespace.users LIMIT 10;

-- Cross-source three-way JOIN: PostgreSQL + MySQL + EventHouse event table
SELECT u.user_name, o.amount, e.event_type
FROM my_catalog.user_namespace.users u
JOIN my_catalog.order_namespace.orders o ON u.user_id = o.user_id
JOIN my_catalog.event_namespace.payment_events e ON o.order_id = e.order_id
WHERE e.event_type = 'PaymentFailed';

For more information, see Data catalog.

Schemas and tables

PostgreSQL supports multi-schema structures. When mounting to a Catalog, you can select tables under the public schema or other custom schemas. The Catalog retains the schema information in the namespace path.

Permission requirements

Create a dedicated read-only account for EventBridge:

-- Create a read-only role
CREATE ROLE eb_readonly WITH LOGIN PASSWORD 'your_password';
-- Grant schema usage permissions
GRANT USAGE ON SCHEMA public TO eb_readonly;
-- Grant table query permissions
GRANT SELECT ON ALL TABLES IN SCHEMA public TO eb_readonly;
-- Set default permissions (automatically applied to newly created tables)
ALTER DEFAULT PRIVILEGES IN SCHEMA public
  GRANT SELECT ON TABLES TO eb_readonly;

EventBridge requires only SELECT permissions and does not modify data in PostgreSQL.

FAQ

Q: The connection test failed with "Connection refused".

A: Check the following items:

  • The PostgreSQL instance is running.

  • The host address and port are correct.

  • The pg_hba.conf file or the RDS whitelist allows connections from EventBridge IP addresses.

  • The security group or firewall allows access to port 5432.

  • For VPC connections, the VPC and vSwitch are configured correctly.

Q: The connection test succeeded, but the query after mounting reports "permission denied for table".

A: The connection test only verifies network connectivity and basic authentication. Queries after mounting require SELECT permissions on the target schema and tables. Verify that the pg_hba.conf file, schema permissions, and table permissions are correctly configured.

Q: Why is DatabaseName required?

A: PostgreSQL does not support cross-database queries, so you must specify the target database when creating a connection. The Catalog discovers mountable schemas and tables within the specified database. To access multiple databases, create separate PostgreSQL connections.

Q: Can I modify the parameters after creating a connection?

A: You can modify the host address, port, username, password, and database name. The connection name and connection type cannot be modified after creation.