---
title: "CREATE_REPLICATION_SLOT"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/streaming_create_repl_slot/"
---

# CREATE_REPLICATION_SLOT

Use the CREATE_REPLICATION_SLOT statement to create a replication slot.

Requires replication connection.

This command can only be executed on a walsender backend which can be started by establishing a replication connection. A replication connection can be created by passing the parameter `replication=database` in the connection string. Refer to examples section.

## Synopsis

Use the `CREATE_REPLICATION_SLOT` statement to create a replication slot.

## Syntax

- [![Grammar Icon](/icons/file-lines.svg)Grammar](#grammar-1)
- [![Diagram Icon](/icons/diagram.svg)Diagram](#diagram-1)

```output.ebnf
create_replication_slot ::= CREATE_REPLICATION_SLOT slot_name LOGICAL 
                            output_plugin 
                            [ NOEXPORT_SNAPSHOT | USE_SNAPSHOT ] 
                            [ SEQUENCE | HYBRID_TIME ]
```

#### create\_replication\_slot

CREATE\_REPLICATION\_SLOT[slot\_name](/stable/api/ysql/syntax_resources/grammar_diagrams#slot-name)LOGICAL[output\_plugin](/stable/api/ysql/syntax_resources/grammar_diagrams#output-plugin)NOEXPORT\_SNAPSHOTUSE\_SNAPSHOTSEQUENCEHYBRID\_TIME

## Semantics

### *slot\_name*

The name of the replication slot. The name of the replication slot must be **unique across all databases**.

### *output\_plugin*

The name of the output plugin used for logical decoding.

### NOEXPORT\_SNAPSHOT / USE\_SNAPSHOT

Determines whether the snapshot will be consumed by the client during slot initialization:

- USE\_SNAPSHOT: the client will consume the snapshot. This option can only be used inside a transaction, and CREATE\_REPLICATION\_SLOT must be the first command run in that transaction.
- NOEXPORT\_SNAPSHOT: the snapshot will be used for logical decoding only.

These options are only available if the YB-TServer flag [ysql\_enable\_pg\_export\_snapshot](/stable/explore/ysql-language-features/advanced-features/snapshot-synchronization "ysql_enable_pg_export_snapshot") is set to true. When the flag is true, USE\_SNAPSHOT is the default behavior. If the flag is not set, the snapshot options are not applicable and will be ignored.

## Examples

Establish a replication connection to the database `yugabyte`.

```sql
bin/ysqlsh "dbname=yugabyte replication=database"
```

Create a Replication Slot with name *test\_replication\_slot* and use the `yboutput` plugin.

```sql
yugabyte=# CREATE_REPLICATION_SLOT test_replication_slot LOGICAL yboutput;
```

Create a Replication Slot with name test\_replication\_slot and use the `pgoutput` plugin.

```sql
yugabyte=# CREATE_REPLICATION_SLOT test_replication_slot LOGICAL pgoutput;
```

## See also

- [DROP\_REPLICATION\_SLOT](/stable/api/ysql/the-sql-language/statements/streaming_drop_repl_slot "DROP_REPLICATION_SLOT")
- [START\_REPLICATION](/stable/api/ysql/the-sql-language/statements/streaming_start_replication "START_REPLICATION")
