When a stream in Datastream encounters a replication error, its status
changes to `Failed` or `Failed permanently`. In the Google Cloud console, you can
[inspect error messages](https://docs.cloud.google.com/datastream/docs/troubleshoot-a-stream#troubleshootfailed) and update your stream or
connection profile settings to resolve the issue. For unrecoverable errors, you
can [recover the stream](https://docs.cloud.google.com/datastream/docs/troubleshoot-a-stream#recoverstream) to prevent data loss.

## Troubleshoot a stream

1. Go to the **Streams** page in the Google Cloud console.

   [Go to the Streams page](https://console.cloud.google.com/datastream/streams)
2. Click the **Column display options** icon in the upper-right corner of the page. The icon appears as three vertical columns.

3. If it isn't selected, select the **Status** checkbox, and then click **OK**.
   Datastream displays the following statuses:

   - `Failed`: for an error that occurs on a `Running` stream. Such errors imply that the stream is still active or continuously attempting to run.
   - `Failed permanently`: for a stream that can't continue to run. Such errors might cause data loss.
4. Click the stream that you want to troubleshoot. Any errors associated with the stream appear on the **Stream details** page.

   For example, if Datastream can't connect to the source database, then the **We can't use the credentials that you provided to connect to the data source.** error message appears on this page.
5. Address the errors. You can resolve errors for either the stream or the connection profile.

   For example, if errors are associated with either the source data objects of the stream or its destination configuration information, then [modify the stream](https://docs.cloud.google.com/datastream/docs/modify-a-stream#modifyastream).

   If errors are associated with the connectivity information of the stream, then update the configuration information about the [source database](https://docs.cloud.google.com/datastream/docs/modify-a-stream#modifystreamsourceinfo) or the [destination](https://docs.cloud.google.com/datastream/docs/modify-a-stream#modifystreamdestinfo) for any connection profiles being used by the stream.

   > [!NOTE]
   > Any changes that you make to a single connection profile affect all streams using that connection profile.

   <br />

6. Fix the `Failed` stream so that it can automatically resume, or [recover](https://docs.cloud.google.com/datastream/docs/recover-a-stream)
   the `Failed permanently` stream.

### Recover a stream

The first thing to try when recovering a stream is to recover it from the current
position. For more information about stream recovery options, see [Stream recovery
overview](https://docs.cloud.google.com/datastream/docs/recover-a-stream#recovery-overview).

If recovering a stream from the current position fails, then try the following:

1. Drop or truncate the affected tables in the destination. You need to do this because while the stream was down, Datastream might have missed some `DELETE` events. `DELETE` events can't be recovered if you don't truncate the table before performing the backfill.
2. Recover the stream from the most recent position. For PostgreSQL, recreate the replication slot or create a new replication slot.
3. Once the stream is running, trigger backfills to restore all historical data. For information about how to trigger a backfill, see [Initiate backfill](https://docs.cloud.google.com/datastream/docs/manage-backfill-for-the-objects-of-a-stream#initiatebackfill).

## What's next

- To learn more about streams, see [Stream lifecycle](https://docs.cloud.google.com/datastream/docs/stream-states-and-actions).
- To learn how to modify a stream, see [Modify a stream](https://docs.cloud.google.com/datastream/docs/modify-a-stream).
- To learn how to recover a failed stream, see [Recover a stream](https://docs.cloud.google.com/datastream/docs/recover-a-stream).