How to install PostgreSQL in Raspberry Pi PLC

Store your Industrial Application in a Postgres database of your industrial Raspberry PLC controller
November 9, 2021 by
How to install PostgreSQL in Raspberry Pi PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez

Introduction

When running an industrial application with industrial automation, there is always some data that we would like to store in order to analyze. 

In this blog post, we will do the following:

We are going to create a database in PostgreSQL to store data with Node-RED by using an industrial Raspberry Pi PLC!

Latest Posts

Your Dynamic Snippet will be displayed here... This message is displayed because you did not provided both a filter and a template to use.

Databases

Databases are a collection of organized information that can easily be accessed, managed, updated and deleted.

Database systems are very important for companies since they allow for the storage of relevant information useful in the future for later analysis.

Databases - How to install PostgreSQL in Raspberry Pi PLC

Postgres

Postgres - How to install PostgreSQL in Raspberry Pi PLC

Some examples of open source databases are:

  • PostgreSQL

  • MariaDB

  • MongoDB

  • SQLite

  • Cassandra

  • CockroachDB

  • Neo4j

In this blog post, we will be using PostgreSQL as it is a powerful, open source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. 

For this, we are going to follow these steps:

1. Update and upgrade the system packet manager.

sudo apt update
sudo apt upgrade

2. Install PostgreSQL.

sudo apt install postgresql

3. Change to the postgres user

sudo su postgres

4. Create a new role for our pi user

createuser pi -P --interactive
During this process, you will be prompted to answer some details.

5. Load up the command line interface of psql.

psql

6. Now, create a database called as you want. In our case: isdb.

CREATE DATABASE isdb;

7. Connect to the database:

\connect isdb;

8. Create a table called as you want, in our case is_table, with the row names, and its datatype.

CREATE TABLE is_table (name text, data text);

9. Insert into the table, the values you want to store, like:

INSERT INTO is_table VALUES ('IS_user','My example data');

10. Once the values were inserted, let's check the data in our database:

SELECT * FROM is_table;
PostgreSQL - How to install PostgreSQL in Raspberry PLC

👉 Now, you will be ready to store data in your Raspberry Pi PLC controller in order to analyze all the parameters of your open-source project! 

​Search in our Blog

How to install PostgreSQL in Raspberry Pi PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez November 9, 2021

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>