The PostgreSQL can easily be installed on the Raspberry Pi just like in any other Debian-based distribution. In this write-up, PostgreSQL installation has been explained in detail.
How to install PostgreSQL on Raspberry Pi
The installation of the PostgreSQL on Raspberry Pi is easy, we will first update the repository of Raspberry Pi with the command:
When the repository of raspberry Pi is fully upgraded and there is no need of any package to be upgraded, then we will execute the command to install the postgreSQL:
The PostgreSQL has successfully been installed, but to authenticate the installation, we will check its status using the systemctl command:
In the above output, we can see that not only the PostgreSQL has been installed but also is in “Active” status.
How to set up PostgreSQL on Raspberry Pi
To use the postgreSQL for storing data, we have to first set up the user of the PostgreSQL which we can do by executing the command:
As we have switched to the Postgres user, now we will configure the database in which we will first create a new user by using the command:
In the above command, we have created a user “pi” which is a default database user and used “-P” flag to set a password, “–interactive‘ is used to prompt more information about the user which is going to be created. As we execute the command, it will be asked for the password, set the password:
On entering the password, it will ask to enter the password again for the confirmation purpose, once the password is set successfully, it will ask three questions in which first, it will ask to make a new role as a superuser? We denied so typed “n”, second, to allow a new role to create databases? We allowed so typed “y”, and lastly, to allow a new role to create more new roles? We were allowed to type “y”. You can set all these preferences according to your requirements.
Once all this is configured, now, to run the PostgreSQL, use the command:
We are in the PostgreSQL database, and to exit back the terminal of Raspberry Pi, use the following command twice times:
Conclusion
The relational databases are among the popular databases used nowadays for storing data and managing data. The PostgreSQL database is also one of the relational databases which are used to store data and the best feature of PostgreSQL is a sophisticated locking mechanism that will restrict the users to modify the data of a database. In this write-up, we have discussed the installation procedure of PostgreSQL on Raspberry Pi as well as setting up by creating a new user in it.