This tutorial is going to go through the process of leveraging the Linux ecosystem using LabVIEW. Once you have remote superuser access on your NI Linux Real-Time target you can follow this tutorial for setting up and using a database on the NI Linux Real-Time operating system running on your cRIO-9068.
Obtain a terminal as the admin user. We will now install PostgreSQL to manage and run the database. To do so, we will use the package manager, opkg, to find and install the necessary software. The package manager, opkg, uses configuration files to specify links to package repositories. On the cRIO-9068 these sources are disabled by default. Navigate to the directory where these configuration files are stored.
# cd /etc/opkg/

The file we will be editing is the “angstrom-base-feed.conf” file highlighted above. Use vi to edit the file so that it looks like the screenshot below to use one popular opkg feed that NI developers have used successfully in the past — you could also modify this line to point to other feeds, for example, your own site's feed if you have one.
# vi angstrom-base-feed.conf

For those less acquainted with vi, after opening the file use the down arrow to move the cursor to the line with the package source listed, then press "x" or “Delete” to remove the leading "#" and space characters to uncomment the line. Then type “:wq” and press enter to save and quit.
Now we can update the package lists for opkg.
# opkg update
We want to install PostgreSQL, so let’s take a look at what packages are available to us.
# opkg list | grep postgresql

There are multiple PostgreSQL packages available, but we are interested in “postgresql” and “postgresql-client” indicated above. Let's install them.
# opkg install postgresql postgresql-client
The packages will download, but we will run into an error installing them.

To figure out what is happening here we can pull up the information on libc6:
# opkg status libc6

Here we can see the installed version of libc6 is 2.11.1-r7, and postgresql requires a version greater than or equal to 2.12. This could be solved by simply marking libc6 for update, however this is not possible because the libc6 package has a “hold” flag, preventing this package from being updated normally. This is because LabVIEW running on the Real-Time operating system was designed and built for this particular version of libc6. While LabVIEW will likely work as expected on a later version of libc6, it is possible that a later version may cause unexpected behavior with LabVIEW running on the cRIO-9068 target. Giving it a “hold” flag is meant to protect from accidental changes and to require the deliberate removal this flag if one wishes to upgrade libc6. Thus, we must remove the hold flag to install PostgreSQL.
# opkg flag ok libc6
Now let’s try the install again.
# opkg install postgresql postgresql-client
If all went well, the two PostgreSQL packages should now be installed.
For additional reference regarding the set up and usage of PostgreSQL take a look at [Chapter 17](http://www.postgresql.org/docs/8.4/static/runtime.html) of the PostgreSQL 8.4 Manual. This documentation was used as a source and reference for much of this section.
PostgreSQL is now installed and we need to set it up so we can use it. First we must create a new user on the system to run the database. It is convention on Linux systems to run server daemons as a separate non-superuser user an added security measure. Go to the web configuration interface of your cRIO-9068 by using a web browser and connecting to your device’s IP address. Then select the “Login” option at the upper right.
Remember, you may find your device’s IP address using Measurement and Automation Explorer (MAX). See section: "Configure the cRIO-9068" in the Get Superuser access tutorial.

Authenticate with your admin account and password, then choose the “Security Configuration” button on the left.

Press the “+” button under the list of system users. Change User Name to “postgres”.

Save the changes to create the new user.
Now we must create a database cluster, or a location on the disk where the database information will be stored. Return to your shell on the target you have logged in as the admin user. You will now create the directory where the database information is to be stored. This location largely does not matter as long as it makes sense to you and your application. For this tutorial I will use a directory I create in the home directory of the postgres user we just created. In the shell as admin, create the postgres home directory.
# mkdir /home/postgres
# chown postgres /home/postgres
We may now switch to the postgres user and create a location for the database data.
# su - postgres
$ mkdir /home/postgres/postgresData
We will try to create the cluster by executing
$ initdb -D /home/postgres/postgresData
But it fails saying
FATAL: failed to initialize max_stack_depth to 100

To fix this we must return to admin and set ulimit to a higher value.
$ logout
# ulimit -s 2048
# su postgres
$ initdb -D /home/postgres/postgresData
The database server is now initialized and ready. We will start postgres in the background and also specify a logfile.
$ postgres -D /home/postgres/postgresData >logfile 2>&1 &
You may also wish to create a simple shell script to execute this command and start the postgres server.
To stop the postgres server you may send a SIGINT to the postgres server process.
$ kill -INT `head –n 1 /home/postgres/postgresData/postmaster.pid`
Make sure the server is running so we can create a database to use. For this tutorial we will create a database called “mydb”.
$ createdb mydb
Now we will create a table in the database to interface with. We’ll call this table demo1 and we’ll say its rows will contain a timestamp and a float value. Then we will grant permission on the table to LabVIEW to we can interface with it programmatically. In the shell enter:
$ psql mydb
postgres=# CREATE TABLE demo1 (recordTime timestamp, dataPoint float);
postgres=# CREATE USER lvuser;
postgres=# GRANT ALL PRIVILEGES ON TABLE demo1 TO lvuser;
postgres=# \q
In the above step we created the table from the PostgreSQL interactive prompt. Let’s test adding a couple entries into the table from the command line.
$ psql -c “INSERT INTO demo1 VALUES (‘2013-7-17 12:56:30’, 1.234), (‘2013-7-17 13:01:02’, 5.678)” mydb
$ psql -c “SELECT * FROM demo1” mydb
$ psql -c “TRUNCATE demo1” mydb
$ psql -c “SELECT * FROM demo1” mydb

With the database up and running we are now ready to make our application to interact with it. For this tutorial we will create an application which will show the table while providing an option to add new data points or clear the table.
To interface with the database we will use the System Exec VI with the psql command we used above. Another possible method is to use Call Library Function Node VIs and plug into the PostgreSQL C API. We will also use the Format Into String node to create the command string to execute with the parameters we specify. Construct a Block Diagram as shown below, or see the attached code example. Note that both False cases of the case structures are blank.

Assemble the Font Panel to resemble the one shown here. The standard error text panes will show if there are any errors connecting or interfacing with your database.

When completed you should be able to press the Add Button to add rows of data to the database, and press the Clear Table button to delete all of the rows from the database.