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
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.

Postgres

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;

How to install PostgreSQL in Raspberry Pi PLC