Skip to content
Snippets Groups Projects
Commit 4aeb5ab2 authored by Quentin Duchemin's avatar Quentin Duchemin
Browse files

[Etherpad] Migrate main instance from MySQL to PostgreSQL

parent 87b80ccb
No related branches found
No related tags found
No related merge requests found
Pipeline #65754 canceled
......@@ -12,14 +12,13 @@
},
"etherpad": {
"Host": "etherpad-db",
"Port": "3306",
"Port": "5432",
"User": "ETHERPAD_DB_USER",
"Password": "ETHERPAD_DB_PASSWORD",
"Database": "--all-databases",
"Type": "mysql",
"Database": "etherpad",
"Type": "postgres",
"Folder": "etherpad",
"Cron": "0 */6 * * *",
"Options": "--single-transaction --quick --lock-tables=false",
"Init-Backup": "1"
},
"etherpad-week": {
......
## mysql8.picapatch2
Try to improve performance of MySQL
* Increase [key_buffer_size](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_key_buffer_size) given that the index file is way too big for the default value
* Also increase `read_buffer_size` to a [recommended value](https://dba.stackexchange.com/a/136409) of 256K
* More precise base image tag
## mysql8.picapatch1
* Limit the [mysql binary log](https://dev.mysql.com/doc/refman/8.0/en/binary-log.html) to 30 hours and some other custom configs in [config/binary_log.cnf](config/binary_log.cnf)
* Remove unnecessary tools (mainly, libsqlite3-0 and gpg)
## Image size and vulnerabilities
* `pica-etherpad-db:mysql8.picapatch1`: 548MB, [54 vulnerabilities](https://gitlab.utc.fr/picasoft/projets/dockerfiles/-/jobs/886295)
* Base image: `mysql:8.0.19` (2020-03-31): 547MB, [65 vulnerabilities](https://gitlab.utc.fr/picasoft/projets/dockerfiles/-/jobs/884250)
FROM mysql:8.0.20
COPY config/binary_log.cnf /etc/mysql/conf.d/binary_log.cnf
COPY config/myisam_perf.cnf /etc/mysql/conf.d/myisam_perf.cnf
# By default, COPY uses permissions `-rw-rw-rw-` for the file inside
# the container. But mysql refuses to use config files that are world-
# writable, so we have to change those permissions:
RUN chmod 644 /etc/mysql/conf.d/binary_log.cnf
RUN chmod 644 /etc/mysql/conf.d/myisam_perf.cnf
# Remove unnecessary tools
# This removes the following packages:
# gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client
# gpg-wks-server gpgsm libsqlite3-0 pinentry-curses
# GPG is probably used by mysql to encrypt logs, but this isn't used in
# our case
RUN apt remove -y --autoremove libsqlite3-0
This image limits the [mysql binary log](https://dev.mysql.com/doc/refman/8.0/en/binary-log.html) to 30 hours (=108000 seconds) via the [binlog_expire_logs_seconds](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds) variable.
generalwhitelist:
# Official documentation: https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html
#
# The main purpose of this config file is to retain binary logs (enabled
# by default) «just in case», for a short period of time. We dont do
# replication, so anyway we shouldn't need the binary logs.
#
# Some settings also try to improve performance (experimental)
[mysqld]
# Limit the binlog retention to 30 hours
binlog_expire_logs_seconds = 108000
# Cache limits
# Increase binlog_cache_size and binlog_stmt_cache_size
# (default: 32 KiB) to 128 KiB
binlog_cache_size = 131072
binlog_stmt_cache_size = 131072
# Decrease max_binlog_cache_size and max_binlog_stmt_cache_size
# (default: 16 EiB) to 10 MiB.
# (If we have transactions greater than 10 MiB there's a big problem)
max_binlog_cache_size = 10485760
max_binlog_stmt_cache_size = 10485760
# Ignore errors
binlog_error_action = IGNORE_ERROR
[mysqld]
# The default value is 8Mo.
# Given this documentation : https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_key_buffer_size,
# we see that the Key_reads/Key_read_requests ratio should normally be less than 0.01.
# At the moment (04/2020), the ratio is more than 0.05, which indicates that the index is far larger than
# the cache. The index is 300M. Right now with this setting, we will "waste" 700M of RAM,
# which we can afford, and foresee further increase.
key_buffer_size=1G
read_buffer_size=256K
version : "2.4"
# THIS IS A DUMMY docker-compose.yml USED ONLY BY THE CI
services:
etherpad-db:
image: registry.picasoft.net/pica-etherpad-db:mysql8.picapatch2
......@@ -60,7 +60,7 @@ RUN useradd --uid ${UID} --create-home etherpad
COPY --from=downloader --chown=etherpad /opt/etherpad-lite /opt/etherpad-lite/
RUN apt-get update && \
apt-get install -y curl nano default-mysql-client postgresql-client && \
apt-get install -y curl nano postgresql-client && \
chmod +x /opt/etherpad-lite/entrypoint.sh && \
usermod -d /opt/etherpad-lite etherpad && \
chown -R etherpad /opt/etherpad-lite && \
......
......@@ -2,7 +2,7 @@ version : "2.4"
volumes:
etherpad-db:
name: etherpad-db
name: etherpad-db-pg
weekpad-db:
name: weekpad-db
deleted-pads-standard:
......@@ -52,7 +52,7 @@ services:
- standard
etherpad-db:
image: registry.picasoft.net/pica-etherpad-db:mysql8.picapatch2
image: postgres:12
container_name: etherpad-db
security_opt:
- no-new-privileges
......@@ -60,11 +60,9 @@ services:
cpus: "0.40"
pids_limit: 1024
volumes:
- etherpad-db:/var/lib/mysql
- etherpad-db:/var/lib/postgresql/data
env_file: ./secrets/etherpad-db.secrets
restart: unless-stopped
# See https://stackoverflow.com/questions/41134785/how-to-solve-mysql-warning-innodb-page-cleaner-1000ms-intended-loop-took-xxx
command: --innodb_lru_scan_depth=128 --default-authentication-plugin=mysql_native_password
networks:
- standard
......
......@@ -22,7 +22,7 @@ if [ -z "${DB_HOST}" ]; then
exit 1
fi
while ! { mysqladmin ping -u"${DB_USER}" -p"${DB_PASSWORD}" -h"${DB_HOST}" &>/dev/null || PGPASSWORD="${DB_PASSWORD}" psql -h"${DB_HOST}" -U"${DB_USER}" -d"${DB_NAME}" -c "SELECT 1" &>/dev/null; }; do
while ! PGPASSWORD="${DB_PASSWORD}" psql -h"${DB_HOST}" -U"${DB_USER}" -d"${DB_NAME}" -c "SELECT 1" &>/dev/null; do
echo "Database server not ready yet, re-trying in 5 seconds..."
sleep 5
done
......
MYSQL_ROOT_PASSWORD=password
MYSQL_DATABASE=etherpad-lite
MYSQL_USER=etherpad
MYSQL_PASSWORD=password
POSTGRES_PASSWORD=password
POSTGRES_USER=etherpad
POSTGRES_DB=etherpad
......@@ -6,10 +6,10 @@
"ip": "${IP:0.0.0.0}",
"port": "${PORT:8080}",
"showSettingsInAdminPage": "${SHOW_SETTINGS_IN_ADMIN_PAGE:true}",
"dbType": "${DB_TYPE:mysql}",
"dbType": "${DB_TYPE:postgres}",
"dbSettings": {
"host": "${DB_HOST}",
"port": "${DB_PORT:3306}",
"port": "${DB_PORT:5432}",
"database": "${DB_NAME}",
"user": "${DB_USER}",
"password": "${DB_PASSWORD}",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment