---
title: 如何查询分区表所在的 Partition 和 Partiton 分布情况-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于 如何查询分区表所在的 Partition 和 Partiton 分布情况相关的常见问题和使用技巧，帮助您快速解决 如何查询分区表所在的 Partition 和 Partiton 分布情况的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# 如何查询分区表所在的 Partition 和 Partiton 分布情况

更新时间：2024-03-14 07:31

适用版本： V2.1.x、V2.2.x、V3.1.x、V3.2.x 内容类型：How-to  

本文介绍如何查询某个分区表所在的 Partition 及 Partiton 分布情况，获得 OceanBase 数据库中分区表分区名和 partition_id 对应关系。

## 适用版本

OceanBase 数据库 V2.x 和 V3.x 版本。

## 查询分区表分区名和 partition_id 的对应关系

1. 本示例以一个 zg_range_test 样例表，包含了 p0，p1，p2 分区，二级分区 mp1，mp2，mp3。

   ```shell
   obclient > CREATE TABLE zg_range_test (col1 INT,col2 INT)
   PARTITION BY RANGE(col1)
   SUBPARTITION BY RANGE(col2)
   SUBPARTITION TEMPLATE
   (SUBPARTITION mp1 VALUES LESS THAN(100),
   SUBPARTITION mp2 VALUES LESS THAN(200),
   SUBPARTITION mp3 VALUES LESS THAN(300))
   (PARTITION p0 VALUES LESS THAN(2020),
   PARTITION p1 VALUES LESS THAN(2021),
   PARTITION p2 VALUES LESS THAN(2022));
   Query OK, 0 rows affected (0.118 sec)

   ```
 2. 根据租户名、表名和分区名查询所在分区的 partiton_id 信息。

   ```shell
   obclient > select * From oceanbase.__all_virtual_partition_item where tenant_id = 1001 and table_name = 'zg_range_test'
   limit 1\G;

   ```

   输出结果如下:

   ```shell
   *************************** 1. row ***************************
         tenant_id: 1001
          table_id: 1100611139453788
      partition_id: 1152921504875282432
       tenant_name: mysql001
        table_name: zg_range_test
   partition_level: 2
     partition_num: 9
     partition_idx: 0
    part_func_type: range
          part_num: 3
         part_name: p0
          part_idx: 0
           part_id: 0
   part_high_bound: 2020
   subpart_func_type: range
       subpart_num: 3
      subpart_name: p0smp1
       subpart_idx: 0
        subpart_id: 0
   subpart_high_bound: 100
   1 row in set (0.005 sec)

   ```
 3. 根据表 table_id 和分区 partition_id 获取该 partition table 租户 ID 号，分区 ID 号，OBServer IP 地址与端口，创建与更改时间，分区个数以及所在的集群，副本类型与状态等信息。

   ```shell
   obclient > select * from oceanbase.__all_virtual_meta_table where table_id = 1100611139453788 and partition_id =1152921504875282432 \G;

   ```

   输出结果如下:

   ```shell
   *************************** 1. row ***************************
         tenant_id: 1001
          table_id: 1100611139453788
      partition_id: 1152921504875282432
            svr_ip: xxx.xxx.xxx.xxx
          svr_port: 2882
        gmt_create: 2023-08-04 11:29:48.771474
      gmt_modified: 2023-08-04 11:29:48.808129
          sql_port: 2881
           unit_id: 1001
     partition_cnt: 0
              zone: zone1
              role: 1
       member_list: xxx.xxx.xxx.xxx:xxx:xxxxx
         row_count: 0
         data_size: 0
      data_version: 17
     data_checksum: 0
      row_checksum: 0
   column_checksum:
   is_original_leader: 0
   is_previous_leader: 1691119788806922
       create_time: 0
           rebuild: 0
      replica_type: 0
     required_size: 0
            status: REPLICA_STATUS_NORMAL
        is_restore: 0
   partition_checksum: 0
            quorum: 1
         fail_list:
   recovery_timestamp: 0
   memstore_percent: 100
      data_file_id: 0
   1 row in set (0.010 sec)

   ```

上一篇

[MySQL 模式的 Hash 分区规则](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000207752)

下一篇

[OceanBase 数据库分区表 FAQs](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000207710) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
