Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Python Prolog Perl
branch: master

MusicBrainz Database Setup

This repository contains a collection of scripts that can help you setup a local copy of the MusicBrainz database and keep it up to date. There is no script that does everything for you though. The main motivation for writing these scripts was to customize the database, so the way to install the database might differ from user to user.


  1. Make sure you have Python and psycopg2 installed.

  2. Setup a database and create mbslave.conf by copying and editing mbslave.conf.default. If you are starting completely from scratch, you can use the following commands to setup a clean database:

    sudo su - postgres
    createuser musicbrainz
    createdb -l C -E UTF-8 -T template0 -O musicbrainz musicbrainz
    createlang plpgsql musicbrainz
  3. Prepare empty schemas for the MusicBrainz database and create the table structure:

    echo 'CREATE SCHEMA musicbrainz;' | ./ -S
    echo 'CREATE SCHEMA statistics;' | ./ -S
    echo 'CREATE SCHEMA cover_art_archive;' | ./ -S
    ./ <sql/CreateTables.sql | sed 's/CUBE/TEXT/' | ./
    ./ <sql/statistics/CreateTables.sql | ./
    ./ <sql/caa/CreateTables.sql | ./
  4. Download the MusicBrainz database dump files from

  5. Import the data dumps, for example:

    ./ mbdump.tar.bz2 mbdump-derived.tar.bz2
  6. Setup primary keys, indexes and views:

    ./ <sql/CreatePrimaryKeys.sql | ./
    ./ <sql/statistics/CreatePrimaryKeys.sql | ./
    ./ <sql/caa/CreatePrimaryKeys.sql | ./
    ./ <sql/CreateIndexes.sql | grep -vE '(collate|page_index|tracklist_index)' | ./
    ./ <sql/statistics/CreateIndexes.sql | ./
    ./ <sql/caa/CreateIndexes.sql | ./
    ./ <sql/CreateSimpleViews.sql | ./
  7. Vacuum the newly created database (optional)

    echo 'VACUUM ANALYZE;' | ./


After the initial database setup, you might want to update the database with the latest data. The script will fetch updates from MusicBrainz and apply it to your local database:


In order to update your database regularly, add a cron job like this that runs every hour:

15 * * * * $HOME/mbslave/ >>/var/log/mbslave.log


When the MusicBrainz database schema changes, the replication will stop working. This is usually announced on the MusicBrainz blog. When it happens, you need to upgrade the database.

Release 2011-07-13

./ <sql/updates/20110624-cdtoc-indexes.sql
./ <sql/updates/20110710-tracklist-index-slave-before.sql
echo "TRUNCATE url_gid_redirect" | ./
echo "TRUNCATE work_alias" | ./
curl -O ""
curl -O ""
./ 20110711-update.tar.bz2 20110711-update-derived.tar.bz2
./ <sql/updates/20110710-tracklist-index-slave-after.sql
echo "UPDATE replication_control SET current_schema_sequence = 13, current_replication_sequence = 51420;" | ./

Optionally, if you want to integrate tables from the old rawdata database, in case they start being replicated in the future, you can also run these commands:

./ <sql/vertical/rawdata/CreateTables.sql
./ <sql/vertical/rawdata/CreateIndexes.sql
./ <sql/vertical/rawdata/CreatePrimaryKeys.sql
./ <sql/vertical/rawdata/CreateFunctions.sql
echo "ALTER TABLE edit_artist ADD status smallint NOT NULL;" | ./
echo "CREATE INDEX edit_artist_idx_status ON edit_artist (status);" | ./
echo "ALTER TABLE edit_label ADD status smallint NOT NULL;" | ./
echo "CREATE INDEX edit_label_idx_status ON edit_label (status);" | ./

Release 2012-01-12

./ <sql/updates/20120105-caa-flag.sql
echo "UPDATE replication_control SET current_schema_sequence = 14;" | ./

Release 2012-05-15

grep 'CREATE VIEW' sql/CreateSimpleViews.sql | sed 's/CREATE/DROP/' | sed 's/ AS/;/' | ./
./ <sql/updates/20120420-editor-improvements.sql
./ <sql/updates/20120417-improved-aliases.sql
./ <sql/updates/20120423-release-group-types.sql
./ <sql/updates/20120320-remove-url-refcount.sql
./ <sql/updates/20120410-multiple-iswcs-per-work.sql
./ <sql/updates/20120430-timeline-events.sql
./ <sql/updates/20120501-timeline-events.sql
./ <sql/updates/20120405-rename-language-columns.sql
./ <sql-extra/20120406-update-language-codes.sql
./ <sql/updates/20120411-add-work-language.sql
./ <sql/updates/20120314-add-tracknumber.sql
./ <sql/updates/20120412-add-ipi-tables.sql
./ <sql/updates/20120508-unknown-end-dates.sql
./ <sql/CreateSimpleViews.sql
echo "UPDATE replication_control SET current_schema_sequence = 15;" | ./

Release 2012-10-15

This release introduces two new database schemas. You can decide whether you want to have the three schemas in your database, or if you want to merge them. For this you need to update your mbslave.conf configuration file (see mbslave.conf.dist for usage of the new options). The rest of the guide will assume that you will keep have all schemas.

Reimporting your database from data dumps is the recommended approach, unless you are aware what changes were done in this release.

The upgrade scripts for this release do not support PostgreSQL 8.4. If you are, using this or an older version of PostgreSQL, you have to drop your database and import from data dumps.

Create the cover_art_archive schema:

echo 'CREATE SCHEMA cover_art_archive;' | ./ -S
./ <sql/updates/20121015-caa-as-of-schema-15.sql | ./
./ mbdump-cover-art-archive.tar.bz2
./ <sql/updates/20120919-caa-edits-pending.sql | ./
./ <sql/updates/20120921-release-group-cover-art.sql | ./
./ <sql/caa/CreatePrimaryKeys.sql | ./
./ <sql/caa/CreateIndexes.sql | ./

Move tables to the statistics schema:

./ <sql/updates/20120922-move-statistics-tables.sql | ./
./ <sql/updates/20120927-add-log-statistics.sql | ./

Upgrade the musicbrainz schema (not completely tested, if it doesn't work, please let me know):

grep 'VIEW' sql/CreateSimpleViews.sql | sed 's/CREATE OR REPLACE/DROP/' | sed 's/ AS/;/' | ./
./ <sql-extra/20121017-create-controlled-for-whitespace.sql
./ <sql/SetSequences.sql 
./ <sql/updates/20120220-merge-duplicate-credits.sql
./ <sql/updates/20120822-more-text-constraints.sql
./ <sql/updates/20120917-rg-st-created.sql
./ <sql/updates/20120921-drop-url-descriptions.sql
./ <sql/updates/20120911-not-null-comments.sql
./ <sql/CreateSimpleViews.sql
echo "UPDATE replication_control SET current_schema_sequence = 16;" | ./

Solr Search Index (Work-In-Progress)

If you would like to also build a Solr index for searching, mbslave includes a script to export the MusicBrainz into XML file that you can feed to Solr:

./ >/tmp/mbslave-solr-data.xml

Once you have generated this file, you for example start a local instance of Solr:

java -Dsolr.solr.home=/path/to/mbslave/solr/ -jar start.jar

Import the XML file:

curl http://localhost:8983/solr/musicbrainz/update -F stream.file=/tmp/mbslave-solr-data.xml -F commit=true

Install triggers to queue database updates:

echo 'CREATE SCHEMA mbslave;' | ./ -S
./ <sql-extra/solr-queue.sql | ./ -s mbslave
./ | ./ | ./ -s mbslave

Update the index:

Something went wrong with that request. Please try again.