How to delete all records and keep settings
From Koha Wiki
Home > Documentation
Tips & Tricks > Tips & Tricks/Customising Notices and Slips > Tips & Tricks
Delete records while keeping configuration settings
Deletes data from a Koha instance (library) without deleting the configuration, authorized values etc.
When to use? If you need to empty the Koha library of all its data without losing configuration settings and authorized values, e.g. borrower types, locations, libraries, media types... 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.
Please note: This takes place on database level and has to be done carefully! It is recommended to back up the database first!
In order to remove
- bibliographic records and/or
- items and/or
- authorities and/or
- borrowers and/or
- current user sessions and/or
Login to database
sudo su mysql -u root use your_koha_library;
Execute the following commands
Make sure to set this back from 0 to 1 after truncating all or your particular choice of the tables!
- Biblios and items
TRUNCATE items; TRUNCATE deleteditems; TRUNCATE biblioitems; TRUNCATE biblio; TRUNCATE deletedbiblioitems; TRUNCATE deletedbiblio; TRUNCATE biblio_metadata; TRUNCATE deletedbiblio_metadata;
TRUNCATE borrowers; TRUNCATE deletedborrowers;
- Sessions and queue for zebra indexing
TRUNCATE sessions; TRUNCATE zebraqueue;
- Must be done after any of the TRUNCATE commands
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 table;
select count(*) from biblioitems;
--> result must be 0
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