# Copy data between Managed ClickHouse® services

You can copy data from one ClickHouse® server to another using the `remoteSecure()` function.


> [!IMPORTANT]
> `remoteSecure()` speaks the ClickHouse native protocol over TLS, so `PORT` must be the port of
> the source service `clickhouse` component, for example `21699`. Using the HTTPS port `21700`
> fails with a protocol error.

## Prerequisites

Details of the source (remote) server

-   Hostname
-   Port of the `clickhouse` component (native protocol over TLS)
-   Username
-   Password

## Copy data

1.  From your target server, use the `remoteSecure()`
    function to select data from the source server.

    ```sql
    SELECT * FROM remoteSecure('HOSTNAME:PORT', db.remote_engine_table, 'USERNAME', 'PASSWORD') LIMIT 3;
    ```

1.  Insert the selected data into the target server.

    ```sql
    INSERT INTO [db.]table [(c1, c2, c3)] SELECT ...
    ```

    For details on how to configure and use the INSERT query, see
    [Inserting the Results of
    SELECT](https://clickhouse.com/docs/reference/statements/insert-into#inserting-the-results-of-select).

Your data has been copied from the remote (source) server to the new
(target) server.

