Mastering HBase Shell Operations and Administration

To initiate the HBase interactive environment, execute the shell script located in the bin directory.

bin/hbase shell

Basic Syntax and Help

Access general assistance by typing help. Commands are categorized into groups. Retrieve specific group documentation using help 'GROUP_NAME', succh as help 'ddl'.

All identifiers, including table and column names, must be enclosed in quotes. Parameters are separated by commas. Configuration dictionaries utilize Ruby Hash syntax:

{'KEY' => 'VALUE', 'OPTIONS' => 'SETTING'}

Keys are often predefined constants like NAME, VERSIONS, or COMPRESSION. Constants do not require quotes. View all available constants with Object.constants.

General Commands

Retrieve the list of tasks running on region servers:

hbase> processlist
hbase> processlist 'all', 'host01.example.com', '16020'

Check the operational state of the cluster. Options include 'summary', 'simple', 'detailed', or 'replication'.

hbase> status 'detailed'
hbase> status 'replication', 'source'

Obtain a reference to a table object for method chaining. This allows invoking commands directly on the table instance.

hbase> tbl = get_table 'inventory'
hbase> tbl.put 'item001', 'stock:qty', '100'
hbase> tbl.scan

Table references support administrative acsions like enabling, disabling, or dropping.

hbase> tbl.disable
hbase> tbl.drop

Verify the installed HBase version or the current user identity.

hbase> version
hbase> whoami

Schema Management (DDL)

Table Creation

Provision a new table by specifying the name and column families. Configuration options are optional.

hbase> create 'warehouse:inventory', {NAME => 'stock', VERSIONS => 3}
hbase> create 'logs', 'events', 'metadata'
hbase> create 'metrics', {NAME => 'data', TTL => 86400, BLOCKCACHE => true}

Pre-splitting tables during creation improves performance for large datasets.

hbase> create 'big_table', 'cf', SPLITS => ['10', '20', '30']
hbase> create 'distributed_table', 'cf', {NUMREGIONS => 10, SPLITALGO => 'UniformSplit'}

Modifying Tables

Update table attributes or column families without disabling the table. Use caution in production environments.

hbase> alter 'warehouse:inventory', NAME => 'stock', VERSIONS => 5
hbase> alter 'logs', 'events', {NAME => 'archive', IN_MEMORY => true}

Remove a column family:

hbase> alter 'warehouse:inventory', NAME => 'stock', METHOD => 'delete'

Adjust table-level properties like maximum file size or coprocessors.

hbase> alter 'logs', MAX_FILESIZE => '134217728'
hbase> alter 'logs', 'coprocessor' => 'hdfs:///lib.jar|com.example.Observer|1001|arg=1'

Asynchronous alterations return immediately without waiting for all regions to update. Check progress with alter_status.

hbase> alter_async 'logs', NAME => 'events', VERSIONS => 2
hbase> alter_status 'logs'

Table Lifecycle

Disable a table before dropping it.

hbase> disable 'warehouse:inventory'
hbase> drop 'warehouse:inventory'

Bulk operations support regular expressions.

hbase> disable_all 'temp.*'
hbase> drop_all 'temp.*'
hbase> enable_all 'prod.*'

Verify table existence or state.

hbase> exists 'logs'
hbase> is_enabled 'logs'
hbase> is_disabled 'logs'

Describe the schema of a specific table.

hbase> describe 'warehouse:inventory'
hbase> desc 'logs'

List all available tables, optionally filtering by pattern.

hbase> list
hbase> list 'warehouse:.*'

Namespace Management

Namespaces provide logical gropuing for tables.

hbase> create_namespace 'dev'
hbase> create_namespace 'prod', {'PROPERTY' => 'VALUE'}
hbase> describe_namespace 'dev'
hbase> alter_namespace 'dev', {METHOD => 'set', 'PROP' => 'VAL'}
hbase> drop_namespace 'dev'
hbase> list_namespace
hbase> list_namespace_tables 'dev'

Data Manipulation (DML)

Writing Data

Insert or update cell values. Timestamps are optional.

hbase> put 'warehouse:inventory', 'item001', 'stock:qty', '50'
hbase> put 'logs', 'event1', 'data:payload', 'info', 1234567890

Append data to an existing cell value.

hbase> append 'logs', 'event1', 'data:payload', 'extra_info'

Atomically increment a counter.

hbase> incr 'warehouse:inventory', 'item001', 'stock:qty', 10
hbase> get_counter 'warehouse:inventory', 'item001', 'stock:qty'

Reading Data

Retrieve a specific row or cell.

hbase> get 'warehouse:inventory', 'item001'
hbase> get 'logs', 'event1', {COLUMN => 'data:payload', VERSIONS => 3}
hbase> get 'logs', 'event1', {FILTER => "ValueFilter(=, 'binary:critical')"}

Scan multiple rows. Use filters and limits to control output.

hbase> scan 'warehouse:inventory'
hbase> scan 'logs', {COLUMNS => ['data:payload'], LIMIT => 100}
hbase> scan 'logs', {STARTROW => 'a', STOPROW => 'z', FILTER => 'PrefixFilter("event")'}
hbase> scan 'logs', {RAW => true, VERSIONS => 5}

Deleting Data

Remove specific cells or entire rows.

hbase> delete 'logs', 'event1', 'data:payload', 1234567890
hbase> deleteall 'warehouse:inventory', 'item001'
hbase> deleteall 'logs', {ROWPREFIXFILTER => 'old_'}

Count rows in a table. This operation can be expensive.

hbase> count 'warehouse:inventory'
hbase> count 'logs', {FILTER => 'PrefixFilter("error")'}

Truncate a table by disabling, dropping, and recreating it.

hbase> truncate 'warehouse:inventory'
hbase> truncate_preserve 'warehouse:inventory'

Administrative Tools

Region Management

Manually assign or unassign regions. Use with caution.

hbase> assign 'ENCODED_REGION_NAME'
hbase> unassign 'ENCODED_REGION_NAME', true
hbase> move 'ENCODED_REGION_NAME', 'host02.example.com,16020'

Merge or split regions.

hbase> split 'warehouse:inventory', 'split_key'
hbase> merge_region 'REGION_A', 'REGION_B'

Trigger compactions to optimize storage.

hbase> compact 'warehouse:inventory'
hbase> major_compact 'logs'
hbase> compact_rs 'host01.example.com,16020'

Flush memory to disk.

hbase> flush 'warehouse:inventory'
hbase> flush 'REGION_NAME'

Cluster Maintenance

Toggle the load balancer.

hbase> balance_switch true
hbase> balancer
hbase> balancer_enabled

Manage dead servers.

hbase> list_deadservers
hbase> clear_deadservers

Clean up catalog tables or HFiles.

hbase> catalogjanitor_run
hbase> cleaner_chore_run

Clear block cache for a specific table to force fresh reads.

hbase> clear_block_cache 'warehouse:inventory'

Replication

Configure replication between clusters.

hbase> add_peer '1', CLUSTER_KEY => "zk1:2181:/hbase"
hbase> add_peer '2', CLUSTER_KEY => "zk2:2181:/hbase", TABLE_CFS => { "table1" => ["cf1"] }
hbase> enable_peer '1'
hbase> disable_peer '1'
hbase> remove_peer '1'

Manage replication scopes and bandwidth.

hbase> set_peer_bandwidth '1', 1048576
hbase> set_peer_replicate_all '1', true
hbase> list_peers

Snapshots

Create a point-in-time copy of a table schema and data.

hbase> snapshot 'warehouse:inventory', 'snap_2023'
hbase> clone_snapshot 'snap_2023', 'warehouse:inventory_restore'
hbase> restore_snapshot 'snap_2023'
hbase> delete_snapshot 'snap_2023'
hbase> list_snapshots

Security and Quotas

Access Control

Grant or revoke permissions (Read, Write, Execute, Create, Admin).

hbase> grant 'alice', 'RWXCA'
hbase> grant 'bob', 'RW', 'warehouse:inventory', 'stock'
hbase> revoke 'alice'
hbase> user_permission 'warehouse:inventory'

Quotas

Set throughput or storage limits.

hbase> set_quota TYPE => THROTTLE, USER => 'alice', LIMIT => '100req/sec'
hbase> set_quota TYPE => SPACE, TABLE => 'logs', LIMIT => '10G', POLICY => NO_INSERTS
hbase> list_quotas

Advanced Features

Visibility Labels

Manage cell-level security labels.

hbase> add_labels ['CONFIDENTIAL', 'PUBLIC']
hbase> set_auths 'alice', ['CONFIDENTIAL']
hbase> set_visibility 'logs', 'CONFIDENTIAL', {COLUMNS => 'data:payload'}
hbase> list_labels

Region Server Groups

Organize region servers into groups for isolation.

hbase> add_rsgroup 'critical_group'
hbase> move_tables_rsgroup 'critical_group', ['warehouse:inventory']
hbase> balance_rsgroup 'critical_group'
hbase> list_rsgroups

Configuration Updates

Reload configuration dynamically.

hbase> update_all_config
hbase> update_config 'host01.example.com,16020'

Procedures and Locks

Monitor background tasks.

hbase> list_procedures
hbase> list_locks

Tags: HBase Shell NoSQL Database Administration Command Line

Posted on Mon, 26 Oct 2026 16:13:19 +0000 by The End