I'm trying to rename a table in HBase but the help in the shell doesn't have a rename
command. move
, mv
and other common culprits don't appear to be it, either.
Asked
Active
Viewed 2.0k times
31

WattsInABox
- 4,548
- 2
- 33
- 43
1 Answers
62
To rename a table in HBase, apparently you have to use snapshots. So, you take a snapshot of the table and then clone it as a different name.
In the HBase shell:
disable 'tableName'
snapshot 'tableName', 'tableSnapshot'
clone_snapshot 'tableSnapshot', 'newTableName'
delete_snapshot 'tableSnapshot'
drop 'tableName'
SOURCE

WattsInABox
- 4,548
- 2
- 33
- 43
-
Can I drop the source table after taking snapshot and before cloning snapshot to new table? It does seem to work. Or are their risks attached to it? – Sumit Nigam Jan 20 '16 at 10:37
-
No risks that I know of. The snapshot and the table are just pointers to the data which is why the snapshot is near-instant. Also, it should be noted that if you wanted the data to be reorganized on disk (HBase to perform as good as possible), you should drop your snapshot when you're done with it. – WattsInABox Jan 22 '16 at 21:20
-
This method works well. Just curious if you have ever tried this method on a very large table? I will have to rename a big HBase table and I don't want the 'disable' time be very long for the old table since our production pipeline will still read the old table before completely switch to the new table name. Thank you! – yuan0122 Jun 23 '17 at 18:40
-
It's pretty fast, but I still wouldn't have production actively querying a table I'm renaming. – WattsInABox Jun 23 '17 at 19:01