Installing Postgres 9.x for Postbooks on Synology Diskstation with Docker

Written by James McDonald

October 15, 2015

I wrote a post about hacking another instance of Postgres onto the Synology Diskstation. But now that Synology has docker you can do it nicely.

Don’t know if I have included everything needed below but let me know in the comments if you have questions.

You need to have SSH access to your DS. And you need to install Docker via the DS Package Center control panel.

Login using SSH and get a root prompt and then fire up docker:

Installing and running Postgres 9.4

# grab the image from docker hub
# make sure you specify the version
# tag e.g. 9.4
docker pull postgres:9.4

# run the image but specify
# a volume external from the
# image
docker run --name docker-postgres \
-e POSTGRES_PASSWORD=YourPassword \
-d \ # specify a data directory external 
\ # to the container
-v /volume1/jmits/pgsql/9.4/data:/var/lib/postgresql/data \
\ # also a backup folder
-v /volume1/jmits/pgsql/backup:/backup \
-p 5434:5432 b9e3b44a27a4

# it might be best to use a Dockerfile to do the following mods
# see below
apt-get update
apt-get install postgresql-9.4-plv8 vim

# if you need to login and install stuff too 
docker exec -ti b35b3a920738 /bin/bash

# you need to add the following
# add plv8.start_proc = 'xt.js_init' to postgresql.conf
vim /var/lib/postgresql/data/postgresql.conf

# then docker stop and start the container
docker stop b35b3a920738
docker start b35b3a920738

# doing backups run docker exec and pipe the backup
# to the external backup dir
docker exec my-postgres sh -c 'pg_dump -h localhost -U your_user -Fc db_name_here | gzip -c - > /backup/test2.backup.gz'

Backing up your Postbooks Database when it’s inside a Container

Create a backup script and put it somewhere

#!/bin/sh

STAMP=`date +"%Y-%m-%d_%H%M"`
DB=my_dbname
BKUPDIR=/backup
LOCALBKUPDIR=/volume1/folder1/pgsql$BKUPDIR

PORT=5432
PGUSER=pguser
CONTAINER=docker-postgres
HOST=localhost

TOFILE=$DB-$STAMP.dump.gz

echo Backup to $BKUPDIR/$TOFILE

docker exec $CONTAINER sh -c "pg_dump -h $HOST -U $PGUSER -Fc $DB | gzip -c - > $BKUPDIR/$TOFILE"

Put this in the Synologies crontab

#minute hour    mday    month   wday    who     command
12      6,10,14,18,22   *       *       *       root    /volume1/folder1/pgsql/bin/backup.sh
# just some other docker commands showing 
# the downloaded docker images and the container
JMITS-NAS01> docker ps 
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS                    NAMES
b35b3a920738        b9e3b44a27a4:latest   "/docker-entrypoint.   48 minutes ago      Up 22 minutes       0.0.0.0:5434->5432/tcp   docker-postgres      
JMITS-NAS01> docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
postgres            9.4                 b9e3b44a27a4        13 hours ago        265.4 MB
centos              latest              0f73ae75014f        5 weeks ago         172.3 MB

References:

http://www.multigesture.net/articles/how-to-use-cron-on-a-synology-nas/

https://xtuple.com/products/postbooks/installing-postbooks-database

Modifying the default postgres image

# on the synology logged in as root
# after doing the docker pull 
# create a Dockerfile and modify the image to your needs

mkdir docker
cd docker
touch Dockerfile
# contents of Dockerfile
FROM postgres:9.4
RUN localedef -i en_AU -c -f UTF-8 -A /usr/share/locale/locale.alias en_AU.UTF-8
ENV LANG en_AU.utf8
RUN apt-get update
RUN apt-get install -y postgresql-9.4-plv8 vim

docker build .
# get the image name you just built
docker images 
# tag it so you know what it is
docker tag f06067887038 jmits/postgres94:postbooks

0 Comments

Trackbacks/Pingbacks

  1. xTuple Postbooks Edition 4.10.0 RC FTW | The Southern IT Observer - […] use a Synology Diskstation to house my business files and so I installed Docker and configured the xTuple Postbooks…

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...