[Yandex Cloud documentation](../../index.md) > [Yandex MPP Analytics for PostgreSQL](../index.md) > [Tutorials](index.md) > Exporting Greenplum® data to a cold storage in Object Storage

# Exporting Greenplum® data to a cold storage in Yandex Object Storage

# Exporting Greenplum® data to a cold storage


In a Greenplum® cluster, you can enable [hybrid storage](../concepts/hybrid-storage.md) for [append-optimized (AO) and append-optimized column-oriented (AOCO) tables](../concepts/tables.md). With this done, the [Yezzey extension](../operations/extensions/yezzey.md) can transfer data in such tables from a cluster storage to a cold storage.

Cold storage is a convenient option if you need to store your data for a long time without using it much. This will make data storage [less costly](../pricing/index.md#rules-storage).


{% note info %}

This feature is at the [Preview](../../overview/concepts/launch-stages.md) stage and free of charge.

{% endnote %}


To transfer your data from a cluster storage to a cold storage:

1. [Export the Greenplum® table to a cold storage](#transfer).
1. [Check the result](#check).

You can also [transfer your data back](#offload-to-local-storage) to a cluster storage.

If you no longer need the resources you created, [delete them](#clear-out).


## Required paid resources {#paid-resources}

* Yandex MPP Analytics for PostgreSQL cluster: use of computing resources allocated to hosts, storage and backup size (see [Yandex MPP Analytics for PostgreSQL pricing](../pricing/index.md)).
* Public IP addresses if public access is enabled for cluster hosts (see [Yandex Virtual Private Cloud pricing](../../vpc/pricing.md)).


## Getting started {#before-you-begin}

1. [Create a Greenplum® cluster](../operations/cluster-create.md). When creating a cluster, make sure to enable **Hybrid storage**.

   {% note info %}

   You cannot disable this option after you save your cluster settings.

   {% endnote %}

1. Get an SSL certificate to connect to the Greenplum® database:

   {% list tabs group=operating_system %}
   
   - Linux (Bash)/macOS (Zsh) {#linux-macos}
   
      ```bash
      mkdir -p ~/.postgresql && \
      wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" \
           --output-document ~/.postgresql/root.crt && \
      chmod 0655 ~/.postgresql/root.crt
      ```
   
      The certificate will be saved to the `~/.postgresql/root.crt` file.
   
   - Windows (PowerShell) {#windows}
   
      ```powershell
      mkdir $HOME\.postgresql; curl.exe -o $HOME\.postgresql\root.crt https://storage.yandexcloud.net/cloud-certs/CA.pem
      ```
   
      The certificate will be saved to the `$HOME\.postgresql\root.crt` file.
   
      Your corporate security policies and antivirus software may block the certificate download. For more information, see [FAQ](../qa/connection.md#get-ssl-error).
   
   {% endlist %}

   To use graphical IDEs, [save a certificate](https://storage.yandexcloud.net/cloud-certs/RootCA.pem) to a local folder and specify the path to it in the connection settings.

## Export the Greenplum® table to a cold storage {#transfer}

1. Connect to the cluster:

   ```bash
   psql "host=c-<cluster_ID>.rw.mdb.yandexcloud.net \
   port=6432 \
   sslmode=verify-full \
   dbname=postgres \
   user=<username> \
   target_session_attrs=read-write"
   ```

1. Create a database named `db_with_yezzey`:

   ```bash
   CREATE DATABASE db_with_yezzey;
   ```

   The new DB will be granted permissions to install extensions. These permissions are not granted for the default DB.

1. Connect to the new DB:

   ```bash
   \connect db_with_yezzey
   ```

1. Create a Yezzey extension:

   ```bash
   CREATE EXTENSION yezzey;
   ```

1. Create an AO table named `ao_table`:

   ```bash
   CREATE TABLE ao_table (a int)
       WITH (appendoptimized=true)
       DISTRIBUTED BY (a);
   ```

1. Populate the table with a series of integers from 1 through 10,000:

   ```bash
   INSERT INTO ao_table SELECT * FROM GENERATE_SERIES(1, 10000);
   ```

1. Transfer the `ao_table` data to a cold storage:

   ```bash
   SELECT yezzey_define_offload_policy('ao_table');
   ```

## Check the result {#check}

1. Check how much of the cluster local cache and cold storage is used by:

   * `ao_table`:

      ```bash
      SELECT * FROM yezzey_offload_relation_status('ao_table');
      ```

   * Each segment file in `ao_table`:

      ```bash
      SELECT * FROM yezzey_offload_relation_status_per_filesegment('ao_table');
      ```

   If there are non-zero values in each `external_bytes` column in the command output, the table was successfully transferred to a cold storage.

1. Check which table segment files are now in the cold storage:

   ```bash
   SELECT * FROM yezzey_relation_describe_external_storage_structure('ao_table');
   ```

1. Make sure you can read data from the transferred table:

   ```bash
   SELECT AVG(a) FROM ao_table;
   ```

   Result:

   ```text
             avg          
   -----------------------
    5000.5000000000000000
   (1 row)
   ```

1. Make sure you can write data to the transferred table:

   1. Add a series of integers 1 through 10,000 to `ao_table`:

      ```bash
      INSERT INTO ao_table SELECT * FROM GENERATE_SERIES(1, 10000);
      ```

   1. Make sure the number of rows has doubled:

      ```bash
      SELECT COUNT(1) FROM ao_table;
      ```

      Result:

      ```text
       count
      -------
       20000
      (1 row)
      ```

## Move the table from the cold storage to the cluster storage {#offload-to-local-storage}

To move `ao_table` from the cold storage back to the cluster storage, run this command:

```bash
SELECT yezzey_load_relation('ao_table');
```

## Delete the resources you created {#clear-out}

If you no longer need the cluster you created, [delete it](../operations/cluster-delete.md).

_Greenplum® and Greenplum Database® are registered trademarks or trademarks of Broadcom Inc. in the United States and/or other countries._