[Yandex Cloud documentation](../index.md) > [Yandex Managed Service for Trino](index.md) > Getting started

# Getting started with Yandex Managed Service for Trino

To get started:
1. [Create a Managed Service for Trino cluster](#cluster-create).
1. [Connect to the Managed Service for Trino cluster](#connect).
1. [Send queries to the Yandex Managed Service for PostgreSQL cluster through Trino](#query-mpg-via-trino).
1. [Check the queries in the Managed Service for PostgreSQL cluster](#check-queries-in-psql).


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

1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or sign up if not signed up yet.

1. If you do not have a folder yet, create one:

   1. In the [management console](https://console.yandex.cloud), in the top panel, click ![image](../_assets/console-icons/layout-side-content-left.svg) or ![image](../_assets/console-icons/chevron-down.svg) and select the [cloud](../resource-manager/concepts/resources-hierarchy.md#cloud).
   1. To the right of the cloud name, click ![image](../_assets/console-icons/ellipsis.svg).
   1. Select ![image](../_assets/console-icons/plus.svg) **Create folder**.
   
      ![create-folder1](../_assets/resource-manager/create-folder-1.png)
   
   1. Give your [folder](../resource-manager/concepts/resources-hierarchy.md#folder) a name. The naming requirements are as follows:
   
       * Length: between 3 and 63 characters.
       * It can only contain lowercase Latin letters, numbers, and hyphens.
       * It must start with a letter and cannot end with a hyphen.
   
   1. Optionally, specify the description for your folder.
   1. Select **Create a default network**. This will create a [network](../vpc/concepts/network.md#network) with subnets in each availability zone. Within this network, you will also have a [default security group](../vpc/concepts/security-groups.md#default-security-group), within which all network traffic will be allowed.
   1. Click **Create**.
   
      ![create-folder2](../_assets/resource-manager/create-folder-2.png)

1. [Assign](../iam/operations/roles/grant.md) the following roles to your Yandex Cloud account:

    * [managed-trino.admin](security.md#managed-trino-admin): To create a cluster.
    * [vpc.user](../vpc/security/index.md#vpc-user): To use the cluster [network](../vpc/concepts/network.md#network).
    * [logging.reader](../logging/security/index.md#logging-reader): To view cluster logs.
    * [logging.editor](../logging/security/index.md#logging-editor): To manage cluster logging settings.
    * [iam.serviceAccounts.user](../iam/security/index.md#iam-serviceAccounts-user): To attach a service account to a cluster.

    {% note info %}
    
    If you cannot manage roles, contact your cloud or organization administrator.
    
    {% endnote %}

1. [Create a service account](../iam/operations/sa/create.md#create-sa) with the `managed-trino.integrationProvider` and `storage.editor` roles.

1. [Create](../managed-postgresql/operations/cluster-create.md#create-cluster) a Yandex Managed Service for PostgreSQL cluster Trino will work with.

## Create a Managed Service for Trino cluster {#cluster-create}

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), select the folder where you want to create a Managed Service for Trino cluster.
    1. Navigate to **Managed Service for&nbsp;Trino**.
    1. Click **Create cluster**.
    1. Specify a name for the cluster.
    1. In the **Service account** field, select the previously created service account.
    1. Under **Network settings**, select a [network](../vpc/operations/network-create.md), [subnet](../vpc/operations/subnet-create.md), and [security group](../vpc/concepts/security-groups.md) for the cluster.
    1. Configure the [coordinator](concepts/index.md#coordinator) and [workers](concepts/index.md#workers).
    1. Under **Catalogs**, add one [Trino catalog](operations/catalog-create.md) for each of the following:

        1. For the [previously created](#before-you-begin) Managed Service for PostgreSQL cluster:

           * **Catalog name**: `test`.
           * **Connector type**: `PostgreSQL`.
           * **Connection type**: `On-premise`.
           * **URL**: `jdbc:postgresql://<host_FQDN>:6432/<DB_name>`.

             To learn how to get a host FQDN, see [this guide](../managed-postgresql/operations/connect/fqdn.md).

           * **Username**: Username in the Managed Service for PostgreSQL cluster.
           * **Password**: User password.

        1. For test data generation:

            * **Catalog name**: `data`.
            * **Connector type**: `TPC-H`.
   
        You can add folders both when you are creating a cluster and after you have done so.

    1. Optionally, under **Advanced settings**, configure logging:

        1. Enable the **Write logs** setting.
        1. Select the log destination:
            * **Folder**: Select a folder from the list.
            * **Group**: Select a [log group](../logging/concepts/log-group.md) from the list or create a new one.
        1. Select **Min. logging level** from the list.

    1. Click **Create**.
    1. Wait until the cluster is ready: its status on the Managed Service for Trino dashboard will change to **Running** and its state, to **Alive**. This may take a while.

{% endlist %}

## Connect to the Managed Service for Trino cluster through the Trino CLI {#connect-to-trino}

If you do not have the Trino CLI yet, install it using the [guide on the official Trino website](https://trino.io/docs/current/client/cli.html#installation).

To connect to an Managed Service for Trino cluster:

1. Create an [IAM token](../iam/concepts/authorization/iam-token.md) and put it to the `TRINO_PASSWORD` environment variable:

   ```bash
   export TRINO_PASSWORD=$(yc iam create-token)
   ```

   This IAM token in `TRINO_PASSWORD` will be your password to the Managed Service for Trino cluster. To enable it, specify the `--password` flag upon connection.

1. Connect to the Managed Service for Trino cluster:

   ```bash
   ./trino c-<cluster_ID>.trino.yandexcloud.net --user iam --password
   ```

   You can get the cluster ID with the [list of clusters in the folder](operations/cluster-list.md#list-clusters).

## Send queries to the Managed Service for PostgreSQL cluster through Trino {#query-mpg-via-trino}

1. [Connect to the Trino cluster through the Trino CLI](#connect-to-trino).

   To follow the steps below, use the Trino CLI.

1. Create a new schema in the Managed Service for PostgreSQL cluster:

   ```sql
   CREATE SCHEMA IF NOT EXISTS test.tpch_postgresql;
   ```

1. Create a table:

   ```sql
   CREATE TABLE IF NOT EXISTS test.tpch_postgresql.customers (
      name VARCHAR,
      phone VARCHAR,
      acctbal DOUBLE
   );
   ```

1. Populate the table with data from the test data folder:

   ```sql
   INSERT INTO test.tpch_postgresql.customers
   SELECT
     name,
     phone,
     acctbal
   FROM data.sf100000.customer
   LIMIT 1000000;
   ```

1. Get the number of rows in the table:

   ```sql
   SELECT COUNT(*) as count FROM test.tpch_postgresql.customers;
   ```

   Expected response:

   ```sql
     count  
   ---------
    1000000 
   (1 row)
   ```

## Check the queries in the Managed Service for PostgreSQL cluster {#check-queries-in-psql}

To check whether the queries to the Managed Service for PostgreSQL cluster are running correctly, [connect to the cluster database](../managed-postgresql/operations/connect/index.md) and get the number of rows in the `customers` table:

```sql
SELECT COUNT(*) FROM tpch_postgresql.customers;
```

Expected response:

```sql
  count  
---------
 1000000
(1 row)

```


# What's next {#whats-next}

* Learn about [service resource relationships](concepts/index.md).
* Explore other [methods of connecting to a Managed Service for Trino cluster](operations/connect.md).