This guide explains how to use pgstream with AWS RDS/Aurora databases, covering snapshots and replication.
👉 Throughout this guide:
pgstreamsourcerefers to the user provided in the pgstream source URL.pgstreamtargetrefers to the user provided in the pgstream target URL.
- Create a source user (
pgstreamsource) with access to required schemas/tables. - For roles without passwords → no special config needed.
- Snapshot of roles with passwords is not supported.
- Update YAML config with correct snapshot settings.
-
User privileges Ensure the
pgstreamsourceuser (from the pgstream source URL) can access the database schema and tables you need. -
Roles handling
-
No roles → no changes required.
-
Roles without passwords → no changes required.
-
Roles with passwords → not supported by AWS.
If you try to snapshot roles with passwords, you'll see:
pg_dumpall: error: query failed: ERROR: permission denied for table pg_authid
-
-
Config when not snapshotting roles If roles are disabled or not manually managed, add the following to avoid failures:
snapshot: schema: pgdump_pgrestore: roles_snapshot_mode: "disabled" no_owner: true no_privileges: true
Example full configuration:
source: postgres: url: "postgresql://pgstreamsource:password@<aws-host>:5432/db?sslmode=require" mode: snapshot snapshot: mode: full # schema + data tables: ["public.*"] # all tables in the public schema schema: mode: pgdump_pgrestore pgdump_pgrestore: roles_snapshot_mode: "disabled" no_owner: true no_privileges: true
ℹ️ AWS RDS/Aurora-managed roles (rdsadmin, rds_reserved, rds_extension, rds_ad, rds_password, rds_iam, rds_replication, rds_superuser and postgres) will not be snapshotted.
- Create a target user (
pgstreamtarget) for the pgstream target URL. - Grant privileges for schema/database ownership.
- Grant optional privileges depending on features (create DB, create roles).
- Use
disable_triggers: false(required for all non-rds_superuserusers).
The pgstreamtarget user (from the pgstream target URL) must have the following privileges:
-
Schema ownership
ALTER DATABASE db OWNER TO pgstreamtarget; ALTER SCHEMA public OWNER TO pgstreamtarget;
-
Database creation (if
create_target_dbis enabled)ALTER ROLE pgstreamtarget CREATEDB;
-
Role creation (if
roles_snapshot_modeisenabled/no_passwords)ALTER ROLE pgstreamtarget CREATEROLE;
⚠️ pgstreamtargetmust already hold any privileges it assigns (e.g.,REPLICATION). -
Disable triggers (required for AWS RDS/Aurora)
⚠️ AWS RDS/Aurora only allows settingsession_replication_roleforrds_superuserroles. You must disable trigger management in pgstream if using a non superuser role:target: postgres: disable_triggers: false # Required for AWS RDS/Aurora target databases when using non superuser roles
❌ If using
disable_triggers: trueand a role without enough privileges, pgstream will fail with:permission denied to set parameter "session_replication_role"
- Ensure logical replication is enabled (
rds.logical_replication=1in parameter group). - Use the
postgresuser or a user withrds_superuserfor initialization. - Grant
rds_replicationrole for replication privileges. - Optionally use a different
pgstreamsourceuser for streaming.
-
Enable logical replication
Logical replication requires
wal_levelto be set tological.Check current setting:
SHOW wal_level;
If not set to
logical, update it:AWS RDS and Aurora require modifying the database parameter group:
- Go to the AWS RDS Console
- Navigate to Parameter groups in the left sidebar
- Create a new parameter group or select your existing custom parameter group
- Note: You cannot modify the default parameter groups
- Search for and modify the
rds.logical_replicationparameter:- Set
rds.logical_replicationto1(enabled)
- Set
- Apply the parameter group to your RDS/Aurora instance:
- Go to your database instance
- Click Modify
- Under Database options, select your custom parameter group
- Apply the changes
- Reboot your database instance for the changes to take effect
Verification:
After the reboot, verify the setting:
SHOW wal_level; -- Should return 'logical' SHOW rds.logical_replication; -- Should return 'on' or '1'
⚠️ Important notes:- Setting
rds.logical_replication=1automatically setswal_level=logical - This change requires a database reboot
- Logical replication may increase storage usage due to retained WAL files
- Ensure you have adequate monitoring for replication slot lag
-
Replication phases
- Initialization → requires elevated privileges to create schemas, event triggers, and replication slots.
- Streaming → can use a dedicated
pgstreamsourceuser.
Initialization does the following:
- Creates
pgstreamschema - Creates replication slot (if missing)
- Creates event triggers/functions for schema changes
rds_superuser privileges (typically the postgres user) for initialization, as creating event triggers requires elevated privileges:
source:
postgres:
url: "postgresql://postgres:password@<aws-host>:5432/db?sslmode=require"
mode: replicationRequired privileges for initialization user:
-- The postgres user typically has these by default
-- If using a different user, grant:
GRANT rds_superuser TO pgstreamsource;
GRANT rds_replication TO pgstreamsource;After initialization, you can:
- Keep using
postgres, or - Transfer ownership to a dedicated
pgstreamsourcerole.
-- Allow ownership transfer
GRANT pgstreamsource TO current_user;
-- Transfer ownership
ALTER DATABASE db OWNER TO pgstreamsource;
ALTER SCHEMA pgstream OWNER TO pgstreamsource;
ALTER SCHEMA <schema> OWNER TO pgstreamsource;
ALTER TABLE pgstream.schema_log OWNER TO pgstreamsource;
ALTER TABLE pgstream.table_ids OWNER TO pgstreamsource;
ALTER SEQUENCE pgstream.xid_serial OWNER TO pgstreamsource;
-- Replication privileges (AWS RDS/Aurora specific)
GRANT rds_replication TO pgstreamsource;- Ensure
pgstreamtargethas schema/database ownership. - If combined with snapshot → follow Snapshot target requirements.
Privileges required:
ALTER DATABASE db OWNER TO pgstreamtarget;
ALTER SCHEMA <schema> OWNER TO pgstreamtarget;| Error message | Cause | Fix |
|---|---|---|
permission denied for table pg_authid |
Roles with passwords require pg_authid access. | AWS RDS doesn't allow access to pg_authid. Disable role passwords (roles_snapshot_mode: disabled or no_passwords). |
permission denied to set parameter "session_replication_role" |
AWS RDS only allows setting this parameter when using an rds_superuser role. |
Set disable_triggers: false in target config or use a role with enough privileges. |
permission denied for schema public when transferring ownership |
Target role lacks CREATE privilege on schema. | Grant CREATE on schema to the role: GRANT CREATE ON SCHEMA public TO role_name; |
| Role creation fails | pgstreamtarget lacks privileges it tries to assign. |
Grant required privileges to pgstreamtarget first, or use a user with more privileges. |
must be superuser to create event triggers |
Initialization user lacks sufficient privileges. | Use the postgres user or grant rds_superuser: GRANT rds_superuser TO username; |
cannot set parameter "rds.logical_replication" |
Parameter can only be set in parameter group. | Modify the parameter group via AWS Console, not via SQL. |