Org-roam.db across multiple machines?

How have people handled org-oam installations running across multiple machines?

With plain old org-mode I’ve had no problem with a directory of .org file, synced across the three machines I use for work and home. But a single shared org-roam directory has turned out to be problematic, as org-roam apparently maintains some kind of file lock on org-roam.db for as long as emacs runs.

If I forget to kill emacs on machine 1, I’ll have an org-roam conflict when I start org-roam on machine 2. My synching mechanism is OneDrive, and the result of a conflict is that I get duplicate copies of org-roam.db with a uniquified name extension. I imagine DropBox, Syncthing, or whatever will have the same problem.

Am I right? Do other people have this problem, and if so, what do you do about it?

Your best bet is to exclude org-roam.db from being synced. This way, your machine would update their db when it’s needed.

1 Like

As @zaeph said, excluding org-roam.db is the right approach. Here are some more details of my own setup along these lines:

  • My org-roam directory is in a git repository (like most of my other personal files). org-roam.db is excluded via .gitignore.
  • A cron script runs git-sync on each of my machines. That works fine for me because I never use several devices at once.
  • After git-sync, the cron script runs
cd $HOME/org-roam
if [ "` ls -t | head -1`" != "org-roam.db" ]; then
  emacsclient -e '(org-roam-db-build-cache)'
fi

which tells Emacs (always running) to update the cache in org-roam.db if any other file in my org-roam directory has changed.

2 Likes

@zaeph, thanks. I’ll try that.

@khinsen, thanks for all those details. I haven’t used git-sync before, but it sounds like now is the time to start.

Just for all those OneDrive users out there… OneDrive can only exclude entire folders from syncing, not individual files. The solution is to put org-roam.db outside of your OneDrive folder, and to tell org-roam where it is by customizing the variable org-roam-db-location, which should the full path to your org-roam.db file, including the filename.

For Syncthing users, you can create a .stignore file, similar to a .gitignore. I have added the org-roam.db file to it and this fixed my problems when using org-roam across multiple machines.