Search code examples
pythonmonetdb

How to setup a (new) monetdb db from scratch in python?


I'm trying to create a monetdb db with python. The db doesn't exist at the beginning: the code should create it specifying the port, the folder were it will reside & the db name. All the examples I could fine clearly assume that the db exists already. In some way this should be similar to the operations typically managed by the moneddbd deamon. How do I setup a (new) monetdb db in python from scratch?


Solution

  • One way to do it is:

    import monetdb.control
    
    control=control.Control(port=port,passphrase=None)
    control.create(database)
    control.release(database)
    

    Another way (my way):

    import subprocess
    
    farm_path="/home/me/..."
    database_name="test"
    subprocess.call("monetdbd create "+farm_path,shell=True,executable="/bin/bash")
    subprocess.call("monetdbd start "+farm_path,shell=True,executable="/bin/bash")
    subprocess.call("monetdb create "+database_name,shell=True,executable="/bin/bash")
    subprocess.call("monetdb release "+database_name,shell=True,executable="/bin/bash")
    

    If you want a bit more detailed code, let me know.