Posts Tagged ‘Raspberry Pi’

Mar 5

… and you want to run PostgreSQL on it.
Suppose you have a model 4B Pi with 8 Gigs of RAM.
Considering that, up to fall 2019, I was maintaing some actively used business web applications on a 2 vCORE, 4GB of vRAM Windows Server 2008 R2 VM on which were running:

  • SQL Server 2008 R2 – not exactly a lightweight RDBMS
  • IIS
  • a bunch of ASP.Net and ASP.Net Core applications (some of which were really bad performers)

I would say that a 1.5 GHz quad core ARM CPU and 8 GB of DDR4 RAM are more than enough to run PostgreSQL – and even some Kestrel istances – for some small home projects, if not for one small detail: storage.

I wouldn’t dare to run PostgreSQL on an SD card, so there are two options:

  • an external storage medium (maybe a fancy USB3 SSD?)
  • a network-mounted drive

I have a NAS at home, so the second option seems more practical.
Specifically I have a NAS that support iSCSI, so… why not? No file permissions to manage, block level access to the LUN…

So, first thing I did was to configure a LUN on the NAS and expose it as an iSCSI target: takes a total of 2 minutes, while drinking coffee.
Then I tought it was as simple as following any guide about open-iscsi on Debian… or not?

Well, in my case, after executing as root (after installing the open-iscsi package):

# iscsiadm -m discovery -t st -p ip.of.my.nas

I got three result, with the same target (i mean, the same iqn) exposed to three different IP addresses… two of which are on subnets not reachable by my raspberry (having a NAS with multiple interfaces is funny!).

To prevent some strange errors at boot, I decided to go (as root) inside the /etc/iscsi/nodes/##nasIdentifier##/ and delete everything with an ip different from the one I wanted to connect to.
Note that the content of the /etc/iscsi/nodes directory is written by the iscsi-adm utility.

The last step I performed to automatically connect to the iscsi target at boot was to modify the default file inside the /etc/iscsi/nodes/##nasidentifier/ip.of.the.target,3260/ directory and set

node.startup = automatic

at the next reboot I had a /dev/sda device available, which was the LUN of my iSCSI target.
Using GParted i created a partition on the device and then created an fstab entry to automatically mount it at boot (always remember to use the _netdev flag in fstab when dealing with network devices, like iSCSI, SMB, NFS, ecc.).

The fun starts now…

I wouldn’t enter the details of installing PostgreSQL on Debian, configuring it for at least the postgres user or setting up the pg_hba.conf and postgresql.conf to allow for access to the server via network.
After moving the data directory to a directory created on the iscsi mount, the following behaviour started to happen:

at boot, PostgreSQL failed to start -according to systemd – but when checking with

# systemctl status postgresql

after login, the result was that postgresql was running, but a quick

netstat -tuna

told a different story: no process was listening on the 5432 port.
But, when doing a

# systemctl restart postgresql

everything was back to normal and PostgreSQL was happily listening on its port.

after having a lot of fun reading the output of

journalctl -xe

I found out the problem was (you already guessed, right?) that PostgreSQL was trying to start before the iSCSI initiator had finished connecting to the iSCSI target.

As

# systemctl list-dependencies

Shows that the postgresql.service unit starts after the remote-fs.target, this shouldn’t happen.
Also, after editing the unit file for PostgreSQL with

# systemctl edit --full postgresql.service

by adding the following line

After=open-iscsi.service ##name-of-the-unit-for-remote-fs-mount##.mount

Nothing changed at the next reboot.

Looking better at the output of journalctl, I discovered an interesting fact: there are two units for PostgreSQL (and only one is shown by the “list-dependencies” command of systemctl… that little S.O.B.).

The unit postgresql@11-main.service is responsible for starting the PostgreSQL cluster, which is the one trying to access the files before the mount point is ready.

So after editing the correct unit by modifying the After line as following

After=network.target remote-fs.target

and adding the mount point of the data directory to the RequiresMountsFor line, at the next reboot PostgreSQL started normally and was already listening on port 5432 right after the Raspberry booted up.
I would say that there’s a lot of documentation about issues related to iscsi and postgresql… all related to CentOS and RHEL.
lucky me, uh?

Bye



A fast update just to say that the adapter is fully working on the Raspberry Pi running NetBSD 6.99.
Connection parameters are 115200-8-N-1 with flow control OFF (ON by default on PuTTY).
The adapter should work also on Rev. 1 Raspberry Pi B models, but there is no P6 (soft reset) header on that revision.

As standalone serial interface, works flawlessly with my old D-Link DSL-G624T wireless modem router. Being a rather old device, it use a slower 38400 bps connection (38400-8-N-1), but, nevertheless, works pretty well.

At last, just to leave no doubts about the SP3232 IC, as mentioned in this article (http://www.fullmeta.it/?p=379):

Sì, sono proprio quelli

Bye



2012 was the year of the Raspberry Pi. This credit card sized computer has become a huge worldwide success.
Running GNU/Linux or other operating systems is an easy task, it just requires to flash an image on an SD Card, put it in the Raspberry and switch on the power supply.

The Raspberry Pi version B sports two USB 2.0 ports (only one on vers. A), a Fast-Ethernet connection (no network on vers. A), HDMI, Composite Video and stereo audio output.
It seems there’s nothing missing on the connection side. You can just plug a TV/monitor, a keyboard (and a mouse) and you’re ready to use the system.
You can also access it via SSH if you’re using Raspian or another OS that automatically enables the network connection and runs sshd or some telnet server at startup.
But, if you don’t have an available TV/monitor and you can’t connect to the Raspberry via network (because there is no DHCP server on your current network or there are no SSH/telnet servers running on the OS), your last chance is a serial console.

I’ll leave the basics to this simple and short article by Joonas Pihlajamaa: http://codeandlife.com/2012/07/01/raspberry-pi-serial-console-with-max3232cpe/
In a nutshell, the Raspberry Pi does have a serial port and a serial console is usually enabled by default by the OS on it, but there isn’t a standard UART/RS-232 connector. Two pins of the GPIO header must be connected to a level shifter like the Maxim MAX3232 in order to have a fully working RS-232 connection.

While the solution by Joonas Pihlajamaa works pretty well, I decided to make some changes:

  • I wanted an interface circuit with a standard DB-9 male connector. This way I can just change some settings, disable the serial console and use the circuit as a simple serial port for the Raspberry PI.
  • I wanted something like an Arduino’s shield, to just plug over and be ‘solid’ with the Raspberry.
  • I wanted the other GPIO pins to be available for other connections, like displays, I2C devices, RTC modules, etc.
  • I wanted the two pins of the soft-reset headers to be available for use even with the circuit plugged over.
  • I also wanted to use the circuit as a standalone RS-232/3.3V level converter to be able to connect to other embedded systems’ serial consoles (like the serial console found in many routers).
  • In the end, I came out with this solution, made with a MAX3232 compatible IC (the cheaper and more versatile SP3232ECP), some stackable headers, the usual five 100nF capacitors and a DB-9 male connector coming from a scrapped old motherboard.

    Serial Port Circuit mounted over a Raspberry Pi B rel. 2

    The P6 header “repeater” (as I call it) also serves to support the circuit on the side of the DB-9 connector.
    A four pin AUX header is also provided for standalone use, with 3.3V, GND, RX and TX connected.
    24 out of 26 GPIO pins are present on the circuit. Of course GPIO pins 8 and 10, TX and RX, are not available for other connections.

    Serial circuit P6 header detail
    Serial circuit AUX header detail

    I’m currently trying the adapter on the Raspberry and seems to be working well. On the PC I’m using an old Prolific USB-to-Serial adapter with a null-modem cable.

    Bye