MonetDB

002. Creation of MonetDB Database

General architecture

MonetDB database is presented with MonetDB daemon (service). This daemon can control several servers. Each server is defined inside of one directory that we create. Common name for such directories is "dbfarm". Beside configuration files for that server, all of the databases of that server will also be placed inside of subfolders of dbfarm directory.

Server creation

When we want to create new server, first thing is to create folder for that server.

-> monetdbd create /home/fffovde/DBfarm1

Inside of that folder a new file with the name ".meroviginian_properties" will be created. This file will have properties for our database.

The Merovingian dynasty was the ruling family of the Franks from the mid-5th century until 751. This dynasty ruled the Netherlands, the country from which MonetDB originates. MonetDB is using this term for some of its internal files and commands.

If we take a look inside of this file, we will find only one property:

-> cat .merovingian_properties
# DO NOT EDIT THIS FILE - use monetdb(1) and monetdbd(1) to set properties
# This file is used by monetdbd
control=false

All other properties are using default values. We can read those default values by command:

> monetdbd get all /home/fffovde/DBfarm1
property
hostname
dbfarm
status
mserver
logfile
pidfile
loglevel
sockdir
listenaddr
port
exittimeout
forward
discovery
discoveryttl
control
passphrase
snapshotdir
snapshotcompression
mapisock
controlsock
value
FffOvdeKomp
/home/fffovde/DBfarm1
no monetdbd is serving this dbfarm
unknown (monetdbd not running)
/home/fffovde/DBfarml/merovingian.log
/home/fffovde/DBfarml/merovingian.pid
information
/tmp
localhost
/50000
60
proxy
true
600
no
<unset>
<unset>
.tar.lz4
/tmp/.s.monetdb.50000
/tmp/.s.merovingian.50000

***********************************************

Monetdb daemon will use default port 50000. It is possible to have several Monetdb daemons. Their port numbers could collide. If we have several Monetdb daemons, then we should immediately change default port number to some unused port number. 

We can set another port number by running this command:

> monetdbd set port=12345 /home/fffovde/DBfarm1

***********************************************

If our monetdbd service is already running, we should stop it. We are doing this in order to release port 50000.

> systemctl stop monetdbd
> systemctl disable monetdbd

Now we can start our server. Our new server will use default port 50000.

> monetdbd start /home/fffovde/DBfarm1

If we now look inside of our DBfarm1 directory, we will now see all of this files.

File ".merovingian_lock" is empty. This file probably just signalized that there is a server inside of directory dbfarm.

File "merovingian.pid" has the number 2436. This is the number of monetdbd process. If we use command "sudo netstat -tulnp" to show us all listening ports, we will see the name monetdbd beside process 2436, and this process will listen the port 50000.

We can also read content of log file. There we will see how our action succeeded.

After this step we no longer have to use command monetdbd, we can just use monetdb (without d).

Database creation

We will create new database in this way. This database is created in "maintenance mode" because no one can access it before we can properly configure it. This command will create a new folder with the name "voc" inside of our DBfarm1 directory.

monetdb create voc

Now, we can start our database, so that only members of monetdb group can access it.

monetdb start voc                  

We can check status of our database with this command (50000 is port number):

monetdb -p50000 status   

Last step would be to make this database available to all of users:

monetdb release voc   

Making queries

"mclient" is application used by users to send queries to databases. We have to provide name of a user with "-u" switch, and name of a database with "-d" switch. Everyone that are inside of "monetdb" group can use "monetdb" username. We will be asked for password, and default password is "monetdb". At the bottom we can notice "sql>" prompt. This is where we can type our queries.

mclient -u monetdb -d voc   

**************************************************

If we have used "set port" command to set some other port for our server, then we have to supply that alternative port number to mclient:

mclient -p50007 -u monetdb -d voc

**************************************************

Now we can type our first query. Don't forget the semicolon. We can exit "sql>" prompt with the command "quit".

SELECT 'columnValue' as columnName;    

How to Stop or Lock Our Server?

We can stop our server with stop command:

Monetdbd stop  ~/DBfarm1     

After we do this, we can check our "merovingian.log" file. Inside of it, we will see all of the databases of that server to be shut down.

cat merovingian.log     

If we just want to make our database unavailable then we use "lock" command. This would put our database under maintenance mod.

monetdb lock voc         

We already know that we can exit maintenance mode with "monetdb release voc".

001. Install MonetDB Database on Ubuntu Linux

Getting the Codename of our Ubuntu Version

First, we need to know the code name of our Ubuntu version. We can find that by reading from the file "os-release". From this file we can read only the line that has words "VERSION_CODENAME" inside of it.

> cat /etc/os-release | grep VERSION_CODENAME

Our Ubuntu codename is "focal". It is also possible to use command:

> lsb_release -cs

We can see from the command line above that our user account is "user". "computer" is the name of our system.

Adding a Repository Where MonetDB is Stored

Next, in folder "/etc/apt/sources.list.d" we will create a file with the name "monetdb.list".

> cd /etc/apt/sources.list.d    #jump to that folder
> sudo touch monetdb.list       #create new file, you will be asked to provide password

Inside of this file we have to place this text. These are addresses to MonetdDB repository.
deb https://dev.monetdb.org/downloads/deb/ focal monetdb
deb-src https://dev.monetdb.org/downloads/deb/ focal monetdb
We can add this text by inserting these two lines in our terminal:

sudo sh -c 'echo "deb https://dev.monetdb.org/downloads/deb/ focal monetdb" >> monetdb.list'
sudo sh -c 'echo "deb-src https://dev.monetdb.org/downloads/deb/ focal monetdb" >> monetdb.list'

Now our file looks like this:

Installing GPG key

Then, we would execute this command. This command will read GPG key file from the internet, and it will place that file in location /etc/apt/trusted.gpg.d/monetdb.gpg. GPG key is a file which will be used to verify MonetDB packages before installing them.

sudo wget --output-document=/etc/apt/trusted.gpg.d/monetdb.gpg https://dev.monetdb.org/downloads/MonetDB-GPG-KEY.gpg

This monetd.gpg file is binary file. We can read its content with the command:

sudo apt-key finger

This command will read values of all the GPG keys in our Ubuntu. One of those keys will be for MonetDB:

If result of this command is equal to "8289 A5F5 75C4 9F50 22F8 EE20 F654 63E2 DF0E 54F3" for MonetDB, then that means that we have installed the correct key.

MonetDB Installation

Now we can install MonetDB. First, we will update our list of available software with command:

sudo apt update

Then we can install MonetDB server and client:

sudo apt install monetdb5-sql monetdb-client

Next step is to enable "MonetDB" service. This service will run each time we boot our computer.

sudo systemctl enable monetdbd

But, if we want our service to run immediately, we don't have to wait for the next boot. We can start our service with:

sudo systemctl start monetdbd

Now that we started our service, let's check its status. We type:

systemctl status monetdbd

We can see that our process is enabled and is running.

Adding an User in MonetDB

Next step is to add users, who are allowed to run a database server, to user group monetdb. "user" is the name of the users account.

sudo adduser user monetdb

To activate this change, we have to log out. If we are using console, we just have to type "exit" and then we can log in again. If we are using GUI, then we can just click on "Log Out" button somewhere in our desktop environment.

We can now  type "mserver5" in terminal (or console), and we will get a proof that our server is installed.

We can also type "monetdb status".