Search This Blog

Thursday, February 18, 2021

Moving PostgreSQL WAL file to a new drive on an Ubuntu server

Sometimes you may need to move PostgreSQL's WAL (write ahead log) file to a new drive. For example to gain better speed if you put it on an SSD or NVME drive, or to gain additional space.

 

First stop PostgreSQL service:

sudo service postgresql stop

Now make a new folder on the new drive, and move (or copy if have room) the pg_wal directory across:


mkdir -p /mnt/newdrive/pg_wal
su postgres
cp /var/lib/postgresql/11/main/pg_wal/* /mnt/newdrive/pg_wal/

Make a back up for now of the WAL directory:

mv /var/lib/postgresql/11/main/pg_wal   /var/lib/postgresql/11/main/pg_wal_bck

Create a link and start the DB again:
ln -s /mnt/newdrive/pg_wal /var/lib/postgresql/11/main/pg_wal
sudo service postgresql start

psql -U postgres -W
 >> should now ask for your password and you can log in

Any issues check the LOG file:


tail postgresql/postgresql-11-main.log -n 100


When you are happy it's all working then you can remove the WAL back up directory:
rmdir -r /var/lib/postgresql/11/main/pg_wal_bck


Notes:


any permission issues try chown to postgres and chmod 777 on the new dir

sudo chown postgres /mnt/newdrive/pg_wal

sudo chmod 777 /mnt/newdrive/pg_wal

Saturday, February 6, 2021

sudo apt-get update error for older Ubuntu (e.g. Ubuntu 19)


For older Ubuntu where you get an error when:

sudo apt-get update

E: The repository 'http://security.ubuntu.com/ubuntu eoan-security Release' no longer has a Release file. 


Try this:

sudo sed -i -re 's/([a-z]{2}\.)?archive.ubuntu.com|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

then try
 sudo apt-get update

Thursday, February 4, 2021

Audible to MP3

It's frustrating when you purchase an audio book on Audible but can then only play it back from their apps - which isn't possible if you want to put it on a basic MP3 player to take jogging, cycling, etc.

To get around this you can strip away the DRM using your activation code. So this isn't cracking the code but just removing it, meaning you need to know your own 4bit Audible key.

Steps:

1) download the .aax file from your Audible account

2) use this tool to find your key  (drag the .aax file to this page and copy the key it returns)

https://audible-tools.github.io/ 


3) Install ffmpeg on your PC and then run this command:


ffmpeg -activation_bytes your-key-here -i input.aax -vn -c:a copy output.mp4

where you switch your-key-here to the value you got from the web tool, and the input.aax to the filename of the .aax you downloaded. This generates an output MP4 file in a few seconds which is free from the DRM. 

Now you can move it to any suitable player! 



---

Shell script to chop .aax into mp3 chapters

#!/bin/bash
# Author: http://crunchbang.org/forums/viewtopic.php?id=38748#p414992
# m4bronto
#     Chapter #0:0: start 0.000000, end 1290.013333
#       first   _     _     start    _     end
while [ $# -gt 0 ]; do
ffmpeg -i "$1" 2> tmp.txt
while read -r first _ _ start _ end; do
  if [[ $first = Chapter ]]; then
    read  # discard line with Metadata:
    read _ _ chapter
    
    ffmpeg -vsync 2 -i "$1" -ss "${start%?}" -to "$end" -vn -ar 44100 -ac 2 -ab 128  -f mp3 "$chapter.mp3" </dev/null
  fi
done <tmp.txt
rm tmp.txt
shift
done