Creating multiple databases on one server using Neo4j

How do you create multiple databases on one server using neo4j? I have multiple clients, and I want to separate all client information into different database to avoid data leaks.


Solution 1:

You need to have multiple Neo4j installations with a different port configurations in conf/neo4j.properties and conf/neo4j-server.properties.

Alternatively you might use some virtualization or container tool like http//docker.io for a more sophisticated approach.

Solution 2:

or add a special label to each node for a client, e.g. :ClientName. or create a root node for each clients database, and always begin the querying at the first node.

in neo4j db, you can have separate subgraphs. if you do programm your code good, there should be no reason to have such leaks.

Solution 3:

Update: Apr 11 2020 Recently (End of 2019, early March 2020) Neo4j has come up with supporting multiple database in same instance

You can manage multiple database using simple commands like below

:use system
:show databases
:create database exampleDB
:use eampleDB

Please read more about from here

PS: The multiple database feature is Enterprise edition/license only, not available for community :-(

as @stefan-armbruster has mentioned it might be good to use multiple Neo4j docker container instances for running multiple Databases

May be below docker compose file should be able to help u in doing this

version: '2'
services:
  neo4j:
    image: neo4j:latest
    network_mode: host
    restart: always
    environment:
      - NEO4J_AUTH: neo4j/neo4j
    cap_add:
      - SYS_RESOURCE
    ports:
      - "7474:7474"
      - "7687:7687"
    volumes:
      - $HOME/neo4j/data:/data

Update: 23rd Dec 2020 if you need latest version of docker-compose, here below it is

version: '3.8'

services:
  
  neo4j:
    image: neo4j:4.2
    restart: always
    ports:
      - '7474:7474'
      - '7473:7473'
      - '7687:7687'
    volumes:
       - ./data:/data
       - ./logs:/logs
       - ./import:/import
       - ./plugins:/plugins
    environment:
      - NEO4J_AUTH=neo4j/neo4j

once you have saved the above to a docker-compose.yml, run below command

docker-compose up 

if you want to run in background

docker-compose up -d 

Now you should be able to access the database as http://localhost:7474, if you are using docker-machine, you will have to use the docker-machine IP address to access the database

By maintaining multiple docker-compose files with different ports in them, you can maintain multiple database, this is not just for neo4j, you can do it for any type of DBs (Mongo, Redis, RabbitMQ etc.,)

for specifying different docker compose file, try below command

docker-compose -f <your docker compose file name>