Using the HP MediaVault as a Home Database Server

By Peter Michael Bruun


See also: My Family Home

Overview of my MediaVault pages:

Why use the MV as a Database Server?

The second generation HP Media Vault comes with a running PostgreSQL server, which supports login accounts, photo application etc. Of course the database stores the data on the physical disk(s), not in the firmware, so there should be plenty of space for most of the personal database needs I could think of. You can use the database to support your web applications, as described in Using the HP MediaVault as a Web Server, or you can access it from other applications on your home computers. For example, it is possible to access the database on the Media Vault from Microsoft Excel. The point, of course, is that by having the database on the Media Vault server, it is always available to all the computers in your network.

Before you start: BE WARNED

This page describes my personal experience with the HP MediaVault, and implies no liability and no endorsement or support by HP, whatsoever.

Following these instructions is likely to void any warranty on the HP MediaVault.

Following these instructions are highly likely make your HP MediaVault completely and utterly unresponsive and cause loss of data. This is known as "bricking" the MediaVault.

Before proceeding, you should read the prerequisites for Hacking the HP MediaVault here.

What is an SQL database?

A database is a system for efficient storage and retrieval of large volumes of information. Several types of database exist: Relational, Hierarchical, Object-Oriented, etc. For general purpose applications, Releational Database Management Systems (RDBMS), have been the most successful, and the SQL language is by far the most successful language for creating, modifying and retrieving data from a relational database.

If you do not already know SQL then it only takes a few weeks to learn the basics and maybe some 5-20 years to master. So your own SQL database is a good place to learn highly valuable skills.

If you ever learned set-theory in school you will have a good staring point (school systems are different - I was 12-13 years old when it was introduced, but these days some schools will teach it around the age of 7-8).

In a relational database, all information is stored as an un-ordered collection of typed tuples, as defined by a schema. Think of this as a table, where the column headings are named and have a type (characters, integers, etc.); and where each tuple is written as a row in the table.

The SQL language allows you to define these tables, and to select a set of the rows that satisfy a boolean expression that you write. Furthermore, SQL allows you to join information from several tables based on common data.

PostgreSQL is a public domain implementation of an RDBMS. These days, another implementation, MySQL, has gained some popularity over PostgreSQL, particularly for WebHotels, but both have been around for many years and are mature and solid RDBMS implementations.

Using PostgreSQL

The HP MediaVault is running PostgreSQL version 8.1.4. I strongly suggest that you download and install PostgreSQL on a PC for experimenting purposes before manipulating the database on the MediaVault. Only PostgreSQL 8.2 and above are supported on Windows.

If you want to access the database on the Media Vault from Windows applications such as MS Excel, then remember to select the ODBC driver in the PostgreSQL installer.

You can find the PostgreSQL documentation here.

Note that if you just want access to the database on the Media Vault, you can log in from a shell (ssh/PuTTY) on the Media Vault using the command:

  psql postgres postgres
Here, you can browse the tables that support the photo Webshare application.

Connecting to the Database from your Home Computers

As hinted before, this takes a little work, because PostgreSQL has been configured on the HP MediaVault to reject any remote connections. To allow connections from your PCs or other computers, you must: Now, after re-booting the MV, you should be able to connect to the PostgreSQL database on the Media Vault from a Windows command shell (assuming that psql is on your path).
  psql -h HPMediaVault postgres postgres
You may need to use the IP address instead of HPMediaVault if you get an error message that the host is not know.

Creating a new Database-user

The database maintains its own logons (usernames/passwords) and it keeps the tables created by different users apart. So I strongly suggest that you create a new database user-name for your own applications to separate your work from that of the MediaVault Photo Webshare application.

To create a mydb user, log in as the existing postgres user and type:

  psql -h HPMediaVault postgres postgres
  create user myself;
  create database mydb WITH ENCODING 'UTF8' owner myself;
I have had some problems with the choice of character encoding. If the encoding chosen for your database does not match that of your client software, then you are going to get an error that the proper conversion library under "$lib" does not exist. I have done some experimenting, but have been unable fix this problem. I have the proper library files but this does not make the problem go away.

What I have figured is that for seamless access from the psql tool in a Windows shell, you need ENCODING 'WIN1252', but in order to access the database from Java you need ENCODING 'UTF8'.

I chose ENCODING 'UTF8' for my database. It can still be accessed from psql, but non-ascii characters are not displayed correctly.

Now you can connect and create your own tables without danger of interfering with the Webshare application:

  psql -h HPMediaVault mydb myself
  create table t(a text, b integer);
  insert into t values('abc', 1);

Connecting to the Database from MS Excel

As mentioned above, you need to download and install the ODBC drivers using the PostgreSQL drivers.

Open Excel and choose the menu: Data->Import external data->New database query. This opens the "Microsoft Query" application.

In the "Select data source" dialog, choose <New data source>, name the source and select the PostgreSQL driver. Then connect to mydb and choose the table you want to display. You can also connect directly from a an Excel graph to get a graphical representatation of your data, which can be used for statistics, presentations, etc.

Connecting to the Database from Java

This section assumes you understand Java coding - if not, you should skip it.

As mentioned above, the character encoding must be UTF8 in order for Java to access the PostgreSQL database on the MV.

Next, you must consider where and how Java will be executing:

On the MV, you already have the necessary driver library:
For a stand-alone application on the MV, just put this file on your class-path. For a Jetty servlet, you need to copy the file to the WEB-INF/lib directory of your web application.

For Java applications running on Windows, you need some version of the driver .jar file.

You can either download and install from the PostgreSQL site, or you can simply copy the file from the MV to your PCs (just use the Samba-mounted drives).

Valid HTML 4.01 Transitional