How to install and setup PostgreSQL on a Raspberry Pi (Part 1)
Raspberry Pi is a small powerful operating system developed from an SD card that’s about the size of a credit card. Its tiny footprint enables more people to have access to computers. What’s more, developers can add a plethora of applications to a Raspberry Pi computer including database systems such as PostgreSQL. You can too. Start here with Part 1 of this multi-series tutorial that explains how to complete a PostgreSQL installation and setup on a Raspberry Pi device.
Raspberry Pi single-board computer.
Formatted FAT32 SD card with a complete Linux distro such as Fedora or Raspbian. If you don’t have a Raspian SD card, this tutorial will show you the steps to create one.
Must know about basic commands in SQL, Linux, and UNIX as well as have some experience in constructing PostgreSQL databases.
NOTE: Set aside a couple of hours to install Raspbian and PostgreSQL.
- Download Raspbian Lite or NOOBS for your OS> either is fine as long as it is capable of running Postgres and comes with long-term support (LTS).
NOTE: Regarding a NOOBS installation, its simplicity requires you to just unzip the download, and then copy the extracted folder’s contents to the SD card that is formatted FAT32.
A USB dongle that’s WiFI is required if you using a Raspberry Pi version 3a or older. Alternatively, use an ethernet Cat5e cable, or connect via a router, or make a single-board connection.
In addition, a complete Linux distro is required as a media player OS won’t work even though it may be compatible with PCs with single boards.
Format the SD card
- A minimum 8GB micro-sd card is required. Format 32GB cards as FAT32 not ExFAT.
WARNING: Take extreme care to select the right disk, partition, volume, or drive device name when you format the SD card. Otherwise, irreversible damage to data can occur when you use Linux elevated privileges (
Format an SD card in macOS using Disk Utility
If you’re a macOS X user, handle the FAT32 formatting for your SD card by using the Disk Utility.
- To begin, open a Finder window.
- Access the
- Open the
Internal shown on the left will list the drives like this image shown here:
- Next, press the button Erase.
- In the drop-down list pick
- Verify that your selections are what you wanted to choose, and then click button Erase in the modal.
Format an SD card in Linux
- From a terminal window, the command
mkfs.vfatis what you can use to create the SD card for your Raspberry Pi program if you have a Linux distro. You can use Gparted instead to format the SD card as FAT32. It’s popularly noted for ease of use for drive formatting and partition removals. Read on in the next section for instructions on how to use that application.
Using gparted to format the SD card
Your Linux distro may already have Gparted as pre-installed software. Look at the software manager for Linux Mint or Unbuntu.
Another way to get Gparted is with the repository APT-GET as shown below.
- Start by updating the repository package
sudo apt-get update
- Use the command here to install Gparted.
sudo apt-get install gparted
- After opening, you’ll see a menu of a drop-down type on the right of the app. Be sure to pick the right name of the drive for
/dev/from the list.
WARNING: You took extra care to format the correct drive or disk. it’s just as important to select the correct drive or disk here. You can’t get the data back from various other drives if you make a mistake here.
If needed, remove old partitions before you add a new FAT32 one.
Make an identification label.
Check your settings, and then to run the app, press the checkmark that is green.
The SD card is now ready to umount to safely be removed.
Format the SD card in a Linux terminal
A different way to format your SD card is to use the command
Get the names of every device on your OS along with information for the partition for the volumes and drives.
sudo fdisk -l
To show names of every volume, try the command
df. Volume names for Linux distros will begin with
diskutil listis great to format on a macOS X. Volume names for macOS machines have
diskin the front.
Take time to accurately choose the drive you want, and then write down the label of the SD card. It could be
/dev/sdb1. But it might be
/dev/sdbinstead. Unmount the SD card if you can’t see the label. Take it out and then put the card back in the slot and see if you can visually pinpoint the label.
Unmount the SD card
Sometimes, you might need to do an SD card unmounting for the successful running of operations.
- Unmount it with this command:
sudo umount /dev/sdbX
NOTE: Put the correct number for the disk in place of the
Use the ‘mkfs’ command to format the card
- Perform a FAT32 format with this command:
sudo mkfs.vfat -n 'RASP_SDCARD' -I /dev/sdbX
- This syntax below is another way you can label the volume without using the flag
sudo mkfs.vfat -I /dev/sdbX
NOTE: Your computer’s speed and the SD card’s size affect the speed of labeling for the volume; therefore, be prepared to wait several minutes.
In macOS X, obtain the name of the SD card with the terminal command
sudo fdisk -lor command
df -hworks for Linux users. The command
df -halso shows the location of the mounted volumes.
After you’ve found the right drive, the command
ddis what you use to add to the SD card the data from the Raspbian OS.
sudo dd bs=1m if=/path/to/raspbian.img of=/dev/diskX conv=sync
‘Resource busy’ error while attempting to write Raspbian
If you receive the error message “Resource busy,” based on your OS, do one of the following:
Unmount the specific Linux drive by using the
sudo umount /dev/sdb..command.
Umount the particular drive in macOS X with the command
sudo diskutil unmount /dev/disk... In addition, the macOS terminal command
unmountDiskwas created for the purpose of unmounting.
Use the code below to use
unmountDiskfor your macOSX:
sudo diskutil unmountDisk dev/diskX
- If you’re still having trouble writing Raspbian to your SD card, remove the
Xin the partition that is giving you problems. Put the number of that partition in that letter’s place. Add
s1. Next, add
sudo diskutil unmount /dev/diskXs1
When finished, a
Volume RASP_SDCARD on disk2s1 unmounted response should be returned.
- Now try the command
Wait for Raspbian to write to the SD card
It takes several minutes for the
dd process to finish. Look for the cursor to appear when because a response won’t be returned. You can use other commands at the prompt.
The volume name
boot is what you should see for the SD card.
Place it in the Raspberry Pi board’s slot for the SD card.
NOTE: Check your wattage. To do this, look on the right side, upper corner. It’s too low if the yellow lightning bolt icon is displayed there. Finish installing and setting up the app. Remember to keep your password for your Raspbian OS admin privileges handy as you’ll need it to continue on with the next part in this tutorial which involves PostgreSQL.
In this tutorial, you learned how to install Raspberry Pi on your OS. This is accomplished by formatting the SD card as FAT32. To avoid deleting the wrong data, you needed to take special care in selecting the correct drive, partition, disk, or volume. The troubleshooting error message “Resource busy” was addressed and a suitable workaround was given for both macOS X and Linux users. Now, you’re ready to proceed to Part 2 in this multi-series tutorial in which you’ll continue to discover how to install and setup PostgreSQL on your Raspberry Pi machine.
Pilot the ObjectRocket Platform Free!
Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.Get Started