I can tell hbase to disable and delete particular tables using:
disable 'tablename'
drop 'tablename'
But I want to delete all the tables in the database without hardcoding the names of any of the tables. Is there a way to do this? I want to do this through the command-line utility ./hbase shell
, not through Java or Thrift.
I have a handy script that does exactly this, using the Python Happybase library:
You will need Happybase installed to use this script, and you can install it as:
disable_all and drop_all have been added as commands in the HBase ruby shell. These commands were added in jira HBASE-3506 These commands take a regex of tables to disable/drop. And they will ask for confirmation before continuing. That should make droping lots of tables pretty easy and not require outside libraries or scripting.
I'm not deleting tables through the hbase shell but I deleting them from the command line by,
- deleting my hadoop distributed filesystem directory, then,
- creating a new clean hadoop distributed filesystem directory, then,
- formatting my hadoop distributed filesystem with 'hadoop namenode -format', then,
- start-all.sh and start-hbase.sh
Reference:
http://hadoop.apache.org/common/docs/r0.20.1/api/overview-summary.html#overview_description
There is a hack. Open $HBASE_HOME/lib/ruby/shell/commands/list.rb file and add below line at the bottom of command method.
After that, list command returns an array of names of all tables. And then do just like this.
If you're looking for something that will do this in a 'one-liner' via a shell script you can use this method:
NOTE: The above was run from Bash shell prompt. It echoes the commands into
hbase shell
and does a loop through all the tables that are returned from thelist
command, and then disables & drops each table as it iterates through the array thatlist
returned. Once it's done, it quits.You can pipe commands to the
bin/hbase shell
command. From there you can use some scripting to grab the table names and pipe the disable/delete commands back to hbase.i.e.