Slonik uses both, stdout and stderr. When stdout is not a terminal, it becomes fully buffered by default. If slonik dies with a crash, the last of stdout may be lost in this case. Also if stdout and stderr are combined at a higher level, messages can appear out of order.
I propose to call setlinebuf(3) on stdout at the start of slonik.
I further propose to move all output to stdout. That includes implementing a notice processor that will use the same output function that adds the script position to other messages.
Here are the proposed changes: