Datastream lets you replicate partitioned tables from a PostgreSQL
source database into your destination either [as a single root
table](https://docs.cloud.google.com/datastream/docs/work-with-postgresql-partitioned-tables#replicate-as-root) or [as separate partition
tables](https://docs.cloud.google.com/datastream/docs/work-with-postgresql-partitioned-tables#replicate-as-separate). To replicate both the root table and individual
partitions to your destination, you must create two separate streams that use
two different PostgreSQL publications.

## Replicate as a single root table

To replicate partitioned tables using the schema of the root table, do the
following:

1. Use a publication with the `publish_via_partition_root` parameter set to `true`
   or create a new one:

       CREATE PUBLICATION PUBLICATION_NAME FOR TABLE
       SCHEMA1.TABLE1, SCHEMA2.TABLE2 WITH (publish_via_partition_root = true);

   Replace the following:
   - <var translate="no">PUBLICATION_NAME</var>: The name of the publication.
   - <var translate="no">SCHEMA(n)</var>: The name of the schema that contains the table.
   - <var translate="no">TABLE(n)</var>: The name of the table for which you create the publication.

   > [!NOTE]
   > **Note:** Changing the value of the `publish_via_partition_root` parameter in a publication that's already used in a stream isn't supported and causes the stream to fail permanently.

   For more information about creating a publication, see
   [Configure a source PostgreSQL database](https://docs.cloud.google.com/datastream/docs/configure-your-source-postgresql-database).
2. Complete the following in the **Configure source** step when you create your
   stream in Google Cloud:

   1. From the **Objects to include** list, select **Specific schemas and
      tables**.
   2. Select only the root table and make sure that the partitioned tables aren't selected.

   For information about creating a stream, see [Create a stream](https://docs.cloud.google.com/datastream/docs/create-a-stream).

## Replicate as separate tables

To replicate partitioned tables as separate tables, do the following:

1. Use a publication with the `publish_via_partition_root` parameter set to
   `false` or create a new one. `false` is the default setting for the parameter.

   > [!NOTE]
   > **Note:** Changing the value of the `publish_via_partition_root` parameter in a publication that's already used in a stream isn't supported and causes the stream to fail permanently.

   For more information about creating a publication, see
   [Configure a source PostgreSQL database](https://docs.cloud.google.com/datastream/docs/configure-your-source-postgresql-database).
2. When you create your stream in Google Cloud, in the **Configure source** step,
   do the following:

   1. From the **Objects to include** list, select **Specific schemas and
      tables**.
   2. Select all partitioned tables and make sure that the root table isn't selected.

   For information about creating a stream, see [Create a stream](https://docs.cloud.google.com/datastream/docs/create-a-stream).

## What's next

- Learn more about [PostgreSQL as a source](https://docs.cloud.google.com/datastream/docs/sources-postgresql).
- Learn more about [configuring a source PostgreSQL database](https://docs.cloud.google.com/datastream/docs/configure-your-source-postgresql-database).