Koha is a wonderful system to work with, but it has a steep learning curve, and there is a lot of testing involved while you implement it for the first time in your library. The first thing you have to do to set up Koha at your library is to do an Initial configuration of Library creation, Item Types, User roles, Circulation rules, etc. and then you move on to import your MARC records. At such times You may have to check and validate the MARC data, Bibliographic records, and Items associated with it. But the problem arises when the Imported MARC data is not up to your satisfaction and you want to remove it and re-import it after making corrections. This will mostly be needed when preparing for large data operations like importing or migrating data into Koha from other sources when one or several test runs have to be performed before the final operation can take place.
But, it is a tedious process to delete the entire database schema, make it a clean slate and do the configuration afresh. Yeah! it annoys me too.
In this situation, you may wonder if there is any way to only delete the Bibliographic data while keeping the User’s data, circulation data, and System Settings intact. Well, there is a way to do this. This has to be done on the Database level and deleting certain tables, so it has to be done very carefully Because if you do it wrong, it can corrupt your database completely. I highly recommend taking a complete database backup first!
So here are the steps to delete only the bibliographic records and items from Koha Database.
Login into your MySQL database. In my case the name of my koha database is “koha_library”, you have to use your database name in case it differs. Execute the following lines one by one in your Terminal window.
sudo su
mysql -u root
use koha_library;
SET FOREIGN_KEY_CHECKS=0;
Execute the following commands at mysql prompt to delete Biblios and items:
TRUNCATE items;
TRUNCATE deleteditems;
TRUNCATE biblioitems;
TRUNCATE biblio;
TRUNCATE deletedbiblioitems;
TRUNCATE deletedbiblio;
TRUNCATE biblio_metadata;
TRUNCATE deletedbiblio_metadata;
You should also delete Sessions and queues for zebra indexing
TRUNCATE sessions;
TRUNCATE zebraqueue;
After we run the TRUNCATE commands we need to set the foreign key check back to 1.
SET FOREIGN_KEY_CHECKS=1;
In some cases, the TRUNCATE commands e.g. for items and biblioitems have to be carried out more than once to really empty the table. The result can be checked by
select count(*) from biblioitems;
This should show results as 0. which means the biblioitems table is empty and all our bibliographic records have been expunged from the database.
Now, this is completely optional but highly recommended to re-run the zebra indexes with the following commands.
zebraidx -c /etc/koha/sites/your_koha_library/zebra-authorities-dom.cfg -g iso2709 -d authorities init zebraidx -c /etc/koha/sites/your_koha_library/zebra-biblios-dom.cfg -g iso2709 -d biblios init
That’s it, Now you have a clean Koha system, and you can import a clean copy of MARC records into koha.
[…] my last post about How to Delete all Bibliographic Records from Koha I explained how to purge only the bibliographic records from a Koha installation while keeping the […]