Deploy PostgreSQL on Raspberry Pi3 via Pantacor Hub

With Pantavisor and Pantacor Hub product makers can easily manage and update embedded devices. Pantavisor is the framework for containerized embedded Linux development that connects devices and containerizes the embedded firmware user-land as well as any apps you want to run on the device. In this tutorial, we’ll show you how to install Pantavisor on to a Raspberry Pi3. You’ll then claim your device and make it available from the Pantacor Hub dashboard. Finally you’ll containerize and deploy PostgreSQL onto the device and connect to it using the database dashboard Adminer.

Prepare your Raspberry Pi 3 for PostgreSQL:

Step 1: Flash the RPi3 initial stable image onto your SD card.

Download RPI3 initial stable image:

Click to download

unzip the device image with:

$ unxz rpi3_initial_stable.img.xz

Write image onto the SK card with the Raspberry Pi Imager

Step 2: Boot your Raspberry Pi3

Insert the flashed SD card and attach the power supply.

Step 3: Sign up to Pantacor Hub
Step 4: Download & Install a CLI tool “pvr”

Note: pvr is a CLI that is used to interact with your device through Pantacor Hub platform. With a few pvr commands, you can revision and share your firmware and projects as simply as a git tree. After downloading the pvr binary, move it to your bin folder.

PVR Cli download options:

Linux(AMD64): Download Linux(ARM32v6): Download Darwin(AMD64): Download

pvr clone; pvr commit; pvr post

To install and build from GitLab source code:

$ go get gitlab.com/pantacor/pvr
$ go build -o ~/bin/pvr gitlab.com/pantacor/pvr

Note: You need “GOLANG” to be installed in your system for building pvr from gitlab source.

Step 5: Detect and claim your device

Connect a LAN cable between your RPi3 and your computer or router.

Open your terminal and run

$ pvr scan device

Claim your device

$ pvr claim -c merely-regular-gorilla https://api.pantahub.com:443/devices/5f1b9c44e193a5000afa9901

Log into Pantacor Hub and check for the newly claimed device in the dashboard.

Step 6: Clone the device to your computer using your device Clone URL:

$ pvr clone https://pvr.pantahub.com/sirinibin/presently_learning_pelican/0 presently_learning_pelican

Now your device is ready to deploy PostgreSQL

Deploy PostgreSQL to the device with these 3 steps:

Step 1: Add postgreSQL to the device and then deploy the change.

Add “postgresql” app:

$ pvr app add postgresql --from=arm32v7/postgres:9.5-alpine --config-json=<(echo -n -e '{
"Env": [
  "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  "POSTGRES_USER=root",
  "POSTGRES_PASSWORD=123",
  "LANG=en_US.utf8",
  "PGDATA=/var/lib/postgresql/data"
]
}')

Deploy the changes:

 $ pvr add .
 $ pvr commit
 $ pvr post
Step 2: Access the PostgreSQL through a shell

psql -h 10.42.0.231 -U root -P 123

Step 3: Access PostgreSQL with adminer

Adminer is a dashboard which can be used to visually manage the mysql database.

By default Adminer is served on port 8080

Add adminer to the device with:

pvr app add adminer —from=arm32v7/adminer

Deploy the changes

 $ pvr add .
 $ pvr commit
 $ pvr post

Access the Adminer dashboard with http://10.42.0.231:8080/

Log into the Adminer dashboard by entering the following credentials:

 System: PostgreSQL
 Server:10.42.0.231
 Username:root
 Password:123

Now you can easily Create/update/delete postgrSQL databases/tables through Adminer

You are Done!

Final Thoughts

In this tutorial, we described how to deploy a containerized version of PostgreSQL and Adminer onto your Pantavisor-enabled device. Pantavisor doesn’t run Docker containers natively, but it does use Docker images as a great source of root file systems for containers that are run by the Pantavisor with LXC.

Take a deeper dive into managing Pantavisor Linux on your device locally with our front-end utilities Pantabox. 

We’re really excited for you to try Pantabox and Pantavisor Linux and we’d love to hear your thoughts. Try one of the guides or join us in the Pantavisor community forum.


Facebook
Twitter
LinkedIn