{
  "id": "postgresql",
  "title": "Prepare PostgreSQL/Supabase for RDI",
  "url": "https://redis.io/docs/latest/integrate/redis-data-integration/data-pipelines/prepare-dbs/postgresql/",
  "summary": "Prepare PostgreSQL databases (including Supabase) to work with RDI",
  "tags": [
    "docs",
    "integrate",
    "rs",
    "rdi"
  ],
  "last_updated": "2026-04-01T08:10:08-05:00",
  "page_type": "content",
  "content_hash": "be4f958bf5d91209392353c53fdb7978d0256a7b2368214bc97d5b921aae7fc9",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[Supabase](https://supabase.com/docs/guides/database/overview) uses PostgreSQL as\nits database engine, so the instructions below also apply to Supabase. However, RDI\ndoesn't currently support cloud deployments of Supabase with AWS or GCP.\n\n\nPostgreSQL supports several\n[logical decoding plug-ins](https://wiki.postgresql.org/wiki/Logical_Decoding_Plugins)\nto enable CDC. If you don't want to use the native `pgoutput` logical replication stream support\nthen you must install your preferred plug-in into the PostgreSQL server. Once you have done this,\nyou must enable a replication slot, and configure a user with privileges to perform the replication.\n\nIf you are using a service like [Heroku Postgres](https://www.heroku.com/postgres) to host\nyour database then this might restrict the plug-ins you can use. If you can't use your preferred\nplug-in then could try the `pgoutput` decoder if you are using PostgreSQL 10 or above.\nIf this doesn't work for you then you won't be able to use RDI with your database.\n\nThe following checklist summarizes the steps to prepare a PostgreSQL\ndatabase for RDI, with links to the sections that explain the steps in\nfull detail. You may find it helpful to track your progress with the\nchecklist as you complete each step.\n\n[code example]"
    },
    {
      "id": "amazon-rds-for-postgresql",
      "title": "Amazon RDS for PostgreSQL",
      "role": "content",
      "text": "Follow the steps below to enable CDC with [Amazon RDS for PostgreSQL](https://aws.amazon.com/rds/postgresql/):\n\n[code example]\n\n1.  <a id=\"1-set-the-instance-parameter-rdslogicalreplication-to-1\"></a>\n    Set the instance parameter `rds.logical_replication` to 1.\n\n1.  <a id=\"2-check-that-the-wal_level-parameter-is-set-to-logical\"></a>\n    Check that the `wal_level` parameter is set to `logical` by running the query `SHOW wal_level`\n    as the database RDS master user. The parameter might not have this value in multi-zone replication\n    setups. You can't change the value manually but it should change automatically when you set the\n    `rds.logical_replication` parameter to 1. If it doesn't change then you probably just need to\n    restart your database instance. You can restart manually or wait until a restart occurs\n    during your maintenance window.\n\n1.  <a id=\"3-set-the-debezium-pluginname-parameter-to-pgoutput\"></a>\n    Set the Debezium `plugin.name` parameter to `pgoutput`.\n\n1.  <a id=\"4-initiate-logical-replication-from-an-aws-account-that-has-the-rdsreplication-role\"></a>\n    Initiate logical replication from an AWS account that has the `rds_replication` role. The role grants\n    permissions to manage logical slots and to stream data using logical slots. By default, only the master user account on AWS has the `rds_replication` role on Amazon RDS, but if you have administrator privileges,\n    you can grant the role to other accounts using a query like the following:\n\n    [code example]\n\n    To enable accounts other than the master account to create an initial snapshot, you must grant `SELECT`\n    permission to the accounts on the tables to be captured. See the documentation about\n    [security for PostgreSQL logical replication](https://www.postgresql.org/docs/current/logical-replication-security.html)\n    for more information."
    },
    {
      "id": "install-the-logical-decoding-output-plug-in",
      "title": "Install the logical decoding output plug-in",
      "role": "setup",
      "text": "As of PostgreSQL 9.4, the only way to read changes to the write-ahead-log is to\n[install a logical decoding output plug-in](https://debezium.io/documentation/reference/2.6/postgres-plugins.html).\nThese plug-ins are written in C using PostgreSQL-specific APIs, as described in the\n[PostgreSQL documentation](https://www.postgresql.org/docs/current/logicaldecoding-output-plugin.html). \nThe PostgreSQL connector uses one of Debezium’s supported logical decoding\nplug-ins to receive change events from the database in either the default\n[`pgoutput`](https://github.com/postgres/postgres/blob/master/src/backend/replication/pgoutput/pgoutput.c) format (supplied with PostgreSQL) or the\n[`Protobuf`](https://github.com/protocolbuffers/protobuf) format. \nSee the\n[decoderbufs Protobuf plug-in documentation](https://github.com/debezium/postgres-decoderbufs)\nfor more details about how to compile it and also its requirements and limitations.\n\nFor simplicity, Debezium also provides a container image that compiles and installs the plug-ins\non top of the upstream PostgreSQL server image. Use this image as an example of the steps\ninvolved in the installation.\n\n The Debezium logical decoding plug-ins have been tested on Linux machines, but if you are\nusing Windows or other operating systems, the installation steps might be different from\nthose listed here."
    },
    {
      "id": "plug-in-differences",
      "title": "Plug-in differences",
      "role": "content",
      "text": "Plug-ins don't all behave in exactly the same way. All of them refresh information about\nthe database schema when they detect that it has changed, but the `pgoutput` plug-in is\nmore \"eager\" than some other plug-ins to do this. For example, `pgoutput` will refresh\nwhen it detects a change to the default value of a column but other plug-ins won't\nnotice this until another, more significant change happens (such as adding a new table\ncolumn).\n\nThe Debezium project maintains a\n[Java class](https://github.com/debezium/debezium/blob/main/debezium-connector-postgres/src/test/java/io/debezium/connector/postgresql/DecoderDifferences.java) that tracks the known differences between plug-ins."
    },
    {
      "id": "configure-the-postgresql-server",
      "title": "Configure the PostgreSQL server",
      "role": "configuration",
      "text": "If you want to use a logical decoding plug-in other than the default `pgoutput` then\nyou must first configure it in the `postgresql.conf` file. Set the `shared_preload_libraries`\nparameter to load your plug-in at startup. For example, to load the `decoderbufs`\nplug-in, you would add the following line:\n\n[code example]\n\nAdd the line below to configure the replication slot (for any plug-in).\nThis instructs the server to use logical decoding with the write-ahead log.\n\n[code example]\n\nYou can also set other PostgreSQL streaming replication parameters if you need them.\nFor example, you can use `max_wal_senders` and `max_replication_slots` to increase\nthe number of connectors that can access the sending server concurrently,\nand `wal_keep_size` to limit the maximum WAL size that a replication slot retains.\nThe\n[configuration parameters](https://www.postgresql.org/docs/current/runtime-config-replication.html#RUNTIME-CONFIG-REPLICATION-SENDER)\ndocumentation describes all the parameters you can use.\n\nPostgreSQL’s logical decoding uses replication slots. These are guaranteed to retain all the WAL\nsegments that Debezium needs even when Debezium suffers an outage. You should monitor replication\nslots carefully to avoid excessive disk consumption and other conditions such as catalog bloat that can arise\nif a replication slot is used infrequently. See the PostgreSQL documentation about\n[replication slots](https://www.postgresql.org/docs/current/warm-standby.html#STREAMING-REPLICATION-SLOTS)\nfor more information.\nIf you are using a `synchronous_commit` setting other than `on`, then you should set `wal_writer_delay`\nto a value of about 10 milliseconds to ensure a low latency for change events. If you don't set this then\nthe default value of about 200 milliseconds will apply.\n\nThis guide summarizes the operation of the PostgreSQL write-ahead log, but we strongly\nrecommend you consult the [PostgreSQL write-ahead log](https://www.postgresql.org/docs/current/wal-configuration.html)\ndocumentation to get a better understanding."
    },
    {
      "id": "set-up-permissions",
      "title": "Set up permissions",
      "role": "content",
      "text": "The Debezium connector needs a database user that has the REPLICATION and LOGIN roles so that it\ncan perform replications. By default, a superuser has these roles but for security reasons, you\nshould give the minimum necessary permissions to the Debezium user rather than full superuser\npermissions.\n\nIf you have administrator privileges then you can create a role for your Debezium user\nusing a query like the following. Note that these are the *minimum* permissions the user\nneeds to perform replications, but you might also need to grant other permissions.\n\n[code example]"
    },
    {
      "id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput",
      "title": "Set privileges for Debezium to create PostgreSQL publications with `pgoutput`",
      "role": "content",
      "text": "The Debezium user needs specific permissions to work with the `pgoutput` plug-in.\nThe plug-in captures change events from the\n[*publications*](https://www.postgresql.org/docs/current/logical-replication-publication.html)\nthat PostgreSQL produces for your chosen source tables. A publication contains change events from\none or more tables that are filtered using criteria from a *publication specification*.\n\nIf you have administrator privileges, you can create the publication specification\nmanually or you can grant the Debezium user the privileges to create the specification\nautomatically. The required privileges are:\n\n-   Replication privileges in the database to add the table to a publication.\n-   `CREATE` privileges on the database to add publications.\n-   `SELECT` privileges on the tables to copy the initial table data. Table owners\n    automatically have `SELECT` permission for the table.\n\nTo add a table to a publication, the user must be an owner of the table. However, in\nthis case, the source table already exists, so you must use a PostgreSQL replication\ngroup to share ownership between the Debezium user and the original owner. Configure\nthe replication group using the following commands:\n\n[code example]\n\n1.  <a id=\"1-create-the-replication-group\"></a>\n    Create the replication group (the name `replication_group` here is\n    just an example):\n\n    [code example]\n\n1.  <a id=\"2-add-the-original-owner-of-the-table-to-the-group\"></a>\n    Add the original owner of the table to the group:\n\n    [code example]\n\n1.  <a id=\"3-add-the-debezium-replication-user-to-the-group\"></a>\n    Add the Debezium replication user to the group:\n\n    [code example]\n\n1.  <a id=\"4-transfer-ownership-of-the-table-to-the-replication-group\"></a>\n    Transfer ownership of the table to `replication_group`:\n\n    [code example]\n\nYou must also set the value of the `publication.autocreate.mode` parameter to `filtered`\nto allow Debezium to specify the publication configuration. See the\n[Debezium documentation for `publication.autocreate.mode`](https://debezium.io/documentation/reference/2.6/connectors/postgresql.html#postgresql-publication-autocreate-mode)\nto learn more about this setting."
    },
    {
      "id": "configure-postgresql-for-replication-with-the-debezium-connector-host",
      "title": "Configure PostgreSQL for replication with the Debezium connector host",
      "role": "configuration",
      "text": "You must configure the database to allow replication with the host that runs\nthe PostgreSQL Debezium connector. To do this, add an entry to the\nhost-based authentication file, `pg_hba.conf`, for each client that needs to\nuse replication. For example, to enable replication for `<youruser>` locally,\non the server machine, you would add a line like the following:\n\n[code example]\n\nTo allow `<youruser>` on localhost to receive replication changes using IPV4,\nadd the line:\n\n[code example]\n\nTo allow `<youruser>` on localhost to receive replication changes using IPV6,\nadd the line:\n\n[code example]\n\nFind out more from the PostgreSQL pages about\n[`pg_hba.conf`](https://www.postgresql.org/docs/10/auth-pg-hba-conf.html)\nand\n[network address types](https://www.postgresql.org/docs/current/datatype-net-types.html)."
    },
    {
      "id": "supported-postgresql-topologies",
      "title": "Supported PostgreSQL topologies",
      "role": "compatibility",
      "text": "You can use the Debezium PostgreSQL connector with a standalone PostgreSQL server or\nwith a cluster of servers.\nFor versions 12 and below, PostgreSQL supports logical replication slots on only primary servers.\nThis means that Debezium can only connect to a primary server for CDC and the connection will\nstop if this server fails. If the same server is promoted to primary when service resumes\nthen you can simply restart the Debezium connector. However, if a different server is\npromoted to primary, then you must reconfigure Debezium to use the new server\nbefore restarting. Also, make sure the new server has the correct plug-in and configuration\nfor Debezium."
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "checklist {id=\"postgreslist\"}",
      "code": "- [ ] [Install the logical decoding output plug-in](#install-the-logical-decoding-output-plug-in)\n- [ ] [Configure the PostgreSQL server](#configure-the-postgresql-server)\n- [ ] [Set up permissions](#set-up-permissions)\n- [ ] [Set privileges for Debezium to create PostgreSQL publications with pgoutput](#set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput)\n- [ ] [Configure PostgreSQL for replication with the Debezium connector host](#configure-postgresql-for-replication-with-the-debezium-connector-host)",
      "section_id": "overview"
    },
    {
      "id": "amazon-rds-for-postgresql-ex0",
      "language": "checklist {id=\"postgresawslist\" nointeractive=\"true\" }",
      "code": "- [ ] [Set the instance parameter rds.logical_replication to 1](#1-set-the-instance-parameter-rdslogicalreplication-to-1)\n- [ ] [Check that the wal_level parameter is set to logical](#2-check-that-the-wal_level-parameter-is-set-to-logical)\n- [ ] [Set the Debezium plugin.name parameter to pgoutput](#3-set-the-debezium-pluginname-parameter-to-pgoutput)\n- [ ] [Initiate logical replication from an AWS account that has the rds_replication role](#4-initiate-logical-replication-from-an-aws-account-that-has-the-rdsreplication-role)",
      "section_id": "amazon-rds-for-postgresql"
    },
    {
      "id": "amazon-rds-for-postgresql-ex1",
      "language": "sql",
      "code": "GRANT rds_replication TO <my_user>",
      "section_id": "amazon-rds-for-postgresql"
    },
    {
      "id": "configure-the-postgresql-server-ex0",
      "language": "plaintext",
      "code": "# MODULES\nshared_preload_libraries = 'decoderbufs'",
      "section_id": "configure-the-postgresql-server"
    },
    {
      "id": "configure-the-postgresql-server-ex1",
      "language": "plaintext",
      "code": "# REPLICATION\nwal_level = logical",
      "section_id": "configure-the-postgresql-server"
    },
    {
      "id": "set-up-permissions-ex0",
      "language": "sql",
      "code": "CREATE ROLE <name> REPLICATION LOGIN;",
      "section_id": "set-up-permissions"
    },
    {
      "id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput-ex0",
      "language": "checklist {id=\"postgrespgoutputlist\" nointeractive=\"true\" }",
      "code": "- [ ] [Create the replication group](#1-create-the-replication-group)\n- [ ] [Add the original owner of the table to the group](#2-add-the-original-owner-of-the-table-to-the-group)\n- [ ] [Add the Debezium replication user to the group](#3-add-the-debezium-replication-user-to-the-group)\n- [ ] [Transfer ownership of the table to the replication group](#4-transfer-ownership-of-the-table-to-the-replication-group)",
      "section_id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput"
    },
    {
      "id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput-ex1",
      "language": "sql",
      "code": "CREATE ROLE replication_group;",
      "section_id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput"
    },
    {
      "id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput-ex2",
      "language": "sql",
      "code": "GRANT replication_group TO original_owner;",
      "section_id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput"
    },
    {
      "id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput-ex3",
      "language": "sql",
      "code": "GRANT replication_group TO replication_user;",
      "section_id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput"
    },
    {
      "id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput-ex4",
      "language": "sql",
      "code": "ALTER TABLE table_name OWNER TO replication_group;",
      "section_id": "set-privileges-for-debezium-to-create-postgresql-publications-with-pgoutput"
    },
    {
      "id": "configure-postgresql-for-replication-with-the-debezium-connector-host-ex0",
      "language": "plaintext",
      "code": "local   replication     <youruser>                          trust",
      "section_id": "configure-postgresql-for-replication-with-the-debezium-connector-host"
    },
    {
      "id": "configure-postgresql-for-replication-with-the-debezium-connector-host-ex1",
      "language": "plaintext",
      "code": "host    replication     <youruser>  127.0.0.1/32            trust",
      "section_id": "configure-postgresql-for-replication-with-the-debezium-connector-host"
    },
    {
      "id": "configure-postgresql-for-replication-with-the-debezium-connector-host-ex2",
      "language": "plaintext",
      "code": "host    replication     <youruser>  ::1/128                 trust",
      "section_id": "configure-postgresql-for-replication-with-the-debezium-connector-host"
    }
  ]
}
