[Yandex Cloud documentation](../../index.md) > [Yandex MetaData Hub](../index.md) > Apache Hive™ Metastore > Troubleshooting

# Troubleshooting in Apache Hive™ Metastore

This section describes issues you may encounter in the service and how to troubleshoot them.

* [Error when creating a database](#create-db-in-hive)
* [No permission error when attaching a service account to a cluster](#attach-service-account)
* [Hive table lock](#lock-tables)

## Error when creating a database in Apache Hive™ Metastore {#create-db-in-hive}

The error occurs if you use the following syntax to create a database:

```sql
CREATE DATABASE IF NOT EXISTS <DB_name>;
```

**Solution**
Apache Hive™ Metastore does not allow creating a database or table in Hive: they are stored in a [Yandex Object Storage bucket](../../storage/concepts/bucket.md) linked to a Yandex Data Processing cluster. To create a database, use the following syntax:

```sql
CREATE DATABASE IF NOT EXISTS <DB_name> LOCATION <DB_location>;
```

In the `LOCATION` parameter, specify the path to the bucket and the database in it in the following format: `s3a://<bucket_name>/<folder_name>/<DB_name>`. Specifying a folder is optional; however, objects will load into a folder faster than into the bucket root.

## No permission error when attaching a service account to the cluster {#attach-service-account}

#### How can I fix the no permission error when connecting a service account to the cluster? {#attach-service-account}

Error message:

```text
ERROR: rpc error: code = PermissionDenied desc = you do not have permission to access the requested service account or service account does not exist
```

This error occurs if you link a service account to a cluster while creating or modifying it.

**Solution**
[Assign](../../iam/operations/roles/grant.md) the [iam.serviceAccounts.user](../../iam/security/index.md#iam-serviceAccounts-user) role or higher to your Yandex Cloud account.

_Apache® and [Apache Hive™](https://hive.apache.org/) are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries._

## Hive table lock {#lock-tables}

When using Apache Hive™ Metastore, a Hive table may get locked, for example if the script is interrupted.

To remove the lock you can use the following:
* Hive Metastore thrift interface.
* Python script running in the same virtual private network (VPC) as Apache Hive™ Metastore.

### Removing a lock using a Python script {#unlock-tables-script}

{% note warning %}

Apache Hive™ Metastore is only accessible via a private VPC IP address and does not have a public DNS name. This provides additional security but requires all services connecting to Apache Hive™ Metastore to be in the same VPC or have configured network access.

{% endnote %}

To remove retention:

1. Connect to a VM or service that is in the same VPC as Apache Hive™ Metastore.

1. Install the dependencies:

   ```bash
   pip install click
   pip install hive-metastore-client
   ```

1. Create a file named `unlock.py` and paste the following script to it:

   {% cut "unlock.py" %}

   ```python
   import click

   from hive_metastore_client import HiveMetastoreClient
   from thrift_files.libraries.thrift_hive_metastore_client.ttypes import ShowLocksRequest, UnlockRequest


   class MetastoreClient:
       def __init__(self, metastore_hostname, metastore_port):
           self.metastore_hostname = metastore_hostname
           self.metastore_port = metastore_port
           self.metastore_client = HiveMetastoreClient(metastore_hostname, metastore_port)

       def show_locks(self, db_name, table):
           with self.metastore_client as metastore_client:
               req = ShowLocksRequest(dbname=db_name, tablename=table)
               return metastore_client.show_locks(req)

       def unlock(self, lock_id):
           with self.metastore_client as metastore_client:
               req = UnlockRequest(lockid=lock_id)
               return metastore_client.unlock(req)


   @click.group()
   @click.option(
       "--host",
       required=True,
       help="Metastore host",
   )
   @click.option(
       "--port",
       type=int,
       help="Metastore port",
       default=9083,
   )
   @click.pass_context
   def cli(ctx, host: str, port: int):
       """Hive Metastore CLI."""
       ctx.obj = MetastoreClient(host, port)


   @cli.command("show-locks")
   @click.argument("db_name", required=True)
   @click.argument("table", required=True)
   @click.pass_obj
   def show_locks(client: MetastoreClient, db_name, table):
       """Show locks for table."""
       result = client.show_locks(db_name, table)
       click.echo(result)


   @cli.command("unlock")
   @click.argument("lock_id", required=True, type=int)
   @click.pass_obj
   def unlock(client: MetastoreClient, lock_id):
       """Unlock by lock id."""
       result = client.unlock(lock_id)
       click.echo(result)


   if __name__ == "__main__":
       cli()
   ```

   {% endcut %}

1. To view the list of locks, run this script:

    ```bash
    python unlock.py --host <metastore-host> show-locks <db-name> <table-name>
    ```

    Where:

    * `<metastore-host>`: Apache Hive™ Metastore private IP address.

       To learn the IP address:
       1. Go to the [resource folder](https://console.yandex.cloud) page.
       1. Navigate to **Yandex MetaData Hub**.
       1. In the left-hand panel, select ![image](../../_assets/console-icons/database.svg) **Metastore**.

    * `<db-name>`: Database name.
    * `<table-name>`: Table name.

1. To remove the lock, run this script:

    ```bash
    python unlock.py --host <metastore-host> unlock <lock-id>
    ```

    Where:

    * `<metastore-host>`: Apache Hive™ Metastore private IP address.
    * `<lock-id>`: Lock ID.