When running an industrial application, 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 a industrial Raspberry Pi PLC!
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 to the storage of relevant information useful in the future for later analysis.
Some examples of open-source databases are:
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.
6. Now, create a database called as you want. In our case: isdb.
CREATE DATABASE isdb;
7. Connect to the database:
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;