Платформа 8.3 → Решение проблем производительности PostgreSQL при расчёте себестоимости в ERP
$ lxc image list images: > 1.txt
$ lxc launch images:debian/10 deb10h
#$ lxc list
#$ lxc config set deb10h security.privileged true
#$ lxc restart deb10h
$ lxc exec deb10h /bin/bash
# adduser builder
# usermod -aG sudo builder
# apt update
# apt upgrade
## apt install qemu-user-static -y
# apt install mc samba sudo ssh wget -y
# poweroff
#$ lxc stop deb10h
$ lxc copy deb10h harin117
$ lxc start harin117
$ lxc list
Соединяемся по ssh builder@192.168.1.156
Последовательность сборки по шагам (работаем под пользователем не root):
Если всё проходит нормально, то получаем в каталоге postgresql-11_11.7-1.1C файлы *.deb.
Для работы 1С достаточно установить:
libpq5_11.7-1.1C.opt_amd64.deb
postgresql-11_11.7-1.1C.opt_amd64.deb
postgresql-client-11_11.7-1.1C.opt_amd64.deb
Пакуем в postgresql-11_11.7-1.1C.tar.gz
Установка в контейнер debian
Можно создать новый контейнер:
$ lxc launch images:debian/10 dpg
#$ lxc config set dpg security.privileged true
#$ lxc restart dpg
$ lxc exec dpg /bin/bash
# adduser user
# usermod -aG sudo user
# apt update
# apt upgrade
## apt install qemu-user-static -y
# apt install mc samba sudo ssh wget -y
# dpkg-reconfigure locales
## Выбираем ru_RU.UTF-8
# locale -a
## timedatectl set-timezone Europe/Moscow
# dpkg-reconfigure tzdata
## apt install keyboard-configuration
## dpkg-reconfigure keyboard-configuration
Сохранить.
# poweroff
$ lxc copy dpg pgh117
$ lxc start pgh117
$ lxc list
| pgh116 | RUNNING | 192.168.0.173 (eth0) |
В контейнере со сборкой
$ scp postgresql-11_11.6-1.1C.tar.gz user@192.168.0.173:/home/user
Соединяемся по ssh user@192.168.0.173
$ ssh user@192.168.0.173
#$ sudo apt search postgresql-common
$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
$ sudo apt-get update
$ sudo apt libllvm7 libxslt1.1
$ sudo apt install postgresql-common
$ tar xvzf postgresql-11_11.7-1.1C.tar.gz
$ cd postgresql-11_11.7-1.1C
$ sudo dpkg -i libpq5_11.7-1.1C.opt_amd64.deb
$ sudo dpkg -i postgresql-client-11_11.7-1.1C.opt_amd64.deb
$ sudo dpkg -i postgresql-11_11.7-1.1C.opt_amd64.deb
$ dpkg -l | grep 11.7-1.1C | awk -F' ' '{print $2}' | sudo xargs apt-mark hold
$ sudo pg_dropcluster --stop 11 main
$ sudo pg_createcluster --locale ru_RU.utf8 11 main -- --data-checksums
$ sudo pg_ctlcluster 11 main start
$ sudo -u postgres psql -U postgres -c "alter user postgres with password 'pass';"
$ sudo pg_ctlcluster 11 main stop
$ sudo apt install nano
$ sudo nano /etc/postgresql/11/main/postgresql.conf
Добавить в конец
# DB Version: 11
# OS Type: linux
# DB Type: oltp
# Total Memory (RAM): 16 GB
# Data Storage: ssd
max_connections = 1000
shared_buffers = 4GB
temp_buffers = 256MB
work_mem = 64MB
effective_cache_size = 8GB # 4GB for 1c
maintenance_work_mem = 1GB
wal_buffers = 16MB
min_wal_size = 2GB
max_wal_size = 4GB
default_statistics_target = 100
effective_io_concurrency = 2
random_page_cost = 1.1
autovacuum = on
autovacuum_max_workers = 4
autovacuum_naptime = 20s
bgwriter_delay = 20ms
bgwriter_lru_multiplier = 4.0
bgwriter_lru_maxpages = 400
synchronous_commit = off
checkpoint_completion_target = 0.9
ssl = off
fsync = on
commit_delay = 1000
commit_siblings = 5
row_security = off
max_files_per_process = 1000
standard_conforming_strings = off
escape_string_warning = off
max_locks_per_transaction = 256
#log_min_duration_statement = 0
log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,client=%h '
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0
#log_autovacuum_min_duration = 0
#log_duration = on
#log_statement = all
log_destination = stderr
plantuner.fix_empty_table = 'on'
online_analyze.table_type = 'temporary'
online_analyze.verbose = 'off'
Сохранить.
$ sudo pg_ctlcluster 11 main start
Выход.
$ sudo poweroff
#$ lxc stop pgh117
$ lxc copy pgh117 pgh117-cop
$ lxc start pgh117
$ mkdir ~/backup/
$ nano ~/backup_pgh117.sh
#!/usr/bin/env bash
set -ex
lxc stop pgh117
BACKUP_DIR=/home/user/backup
#HOSTS=$(lxc list -c n --format csv)
HOSTS=pgh117
for HOST in ${HOSTS}
do
BACKUP_NAME=${HOST}-$(date +"%Y-%m-%d")
lxc snapshot ${HOST} auto-backup
lxc publish ${HOST}/auto-backup --alias ${BACKUP_NAME}
#lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz
lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}
lxc image delete ${BACKUP_NAME}
lxc delete ${HOST}/auto-backup
done
lxc start pgh117
Сохранить.
$ chmod +x ~/backup_pgh117.sh
$ ./backup_pgh117.sh
+ lxc stop pgh117
+ BACKUP_DIR=/home/user/backup
+ HOSTS=pgh117
+ for HOST in ${HOSTS}
++ date +%Y-%m-%d
+ BACKUP_NAME=pgh117-2020-03-01
+ lxc snapshot pgh117 auto-backup
+ lxc publish pgh117/auto-backup --alias pgh117-2020-03-01
Контейнер публикуется с отпечатком: 51bb790f417f919264fa95f8ef1c8dd6d0cfdbcb9dc7af639187526e2236b64b
+ lxc image export pgh117-2020-03-01 /home/user/backup/pgh117-2020-03-01
Image exported successfully!
+ lxc image delete pgh117-2020-03-01
+ lxc delete pgh117/auto-backup
+ lxc start pgh117
pgh117-2020-03-01.tar.gz
Начинаем испытания.
$ lxc image list images: > 1.txt
$ lxc launch images:debian/10 deb10h
#$ lxc list
#$ lxc config set deb10h security.privileged true
#$ lxc restart deb10h
$ lxc exec deb10h /bin/bash
# adduser builder
# usermod -aG sudo builder
# apt update
# apt upgrade
## apt install qemu-user-static -y
# apt install mc samba sudo ssh wget -y
# poweroff
#$ lxc stop deb10h
$ lxc copy deb10h harin117
$ lxc start harin117
$ lxc list
Соединяемся по ssh builder@192.168.1.156
Последовательность сборки по шагам (работаем под пользователем не root):
- Ставим необходимые общие пакеты для сборки:
$ sudo apt-get install build-essential fakeroot devscripts -y
$ wget https://apt.postgresql.org/pub/repos/apt/pool/main/p/postgresql-11/postgresql-11_11.7.orig.tar.bz2 - Распаковываем приложенный архив для сборки PostgreSQL:
$ mkdir postgresql-11_11.7-1.1C
$ cd postgresql-11_11.7-1.1C - Копируем:
$ cp ~/postgresql-11_11.7-1.1C.opt.dsc .
$ cp ~/postgresql-11_11.7-1.1C.opt.debian.tar.xz .
$ cp ~/postgresql-11_11.7.orig.tar.bz2 .
$ ls
postgresql-11_11.7-1.1C.opt.debian.tar.xz postgresql-11_11.7-1.1C.opt.dsc postgresql-11_11.7.orig.tar.bz2
- Распаковываем и накладываем патчи:
$ dpkg-source -x postgresql-11_11.7-1.1C.opt.dsc - Переходим в каталог сборки:
$ cd postgresql-11-11.7 - Устанавливаем пакеты, необходимые для сборки PostgreSQL:
$ sudo mk-build-deps -i- - для Ubuntu-сервер потребовалось ещё предварительно установить пакет equivs (для Debian нет надобности):
$ sudo apt-get install equivs
- - для Ubuntu-сервер потребовалось ещё предварительно установить пакет equivs (для Debian нет надобности):
- Запускаем сборку:
$ debuild -b -uc -us
Если всё проходит нормально, то получаем в каталоге postgresql-11_11.7-1.1C файлы *.deb.
Для работы 1С достаточно установить:
libpq5_11.7-1.1C.opt_amd64.deb
postgresql-11_11.7-1.1C.opt_amd64.deb
postgresql-client-11_11.7-1.1C.opt_amd64.deb
Пакуем в postgresql-11_11.7-1.1C.tar.gz
Установка в контейнер debian
Можно создать новый контейнер:
$ lxc launch images:debian/10 dpg
#$ lxc config set dpg security.privileged true
#$ lxc restart dpg
$ lxc exec dpg /bin/bash
# adduser user
# usermod -aG sudo user
# apt update
# apt upgrade
## apt install qemu-user-static -y
# apt install mc samba sudo ssh wget -y
# dpkg-reconfigure locales
## Выбираем ru_RU.UTF-8
# locale -a
## timedatectl set-timezone Europe/Moscow
# dpkg-reconfigure tzdata
## apt install keyboard-configuration
## dpkg-reconfigure keyboard-configuration
Сохранить.
# poweroff
$ lxc copy dpg pgh117
$ lxc start pgh117
$ lxc list
| pgh116 | RUNNING | 192.168.0.173 (eth0) |
В контейнере со сборкой
$ scp postgresql-11_11.6-1.1C.tar.gz user@192.168.0.173:/home/user
Соединяемся по ssh user@192.168.0.173
$ ssh user@192.168.0.173
#$ sudo apt search postgresql-common
$ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
$ sudo apt-get update
$ sudo apt libllvm7 libxslt1.1
$ sudo apt install postgresql-common
$ tar xvzf postgresql-11_11.7-1.1C.tar.gz
$ cd postgresql-11_11.7-1.1C
$ sudo dpkg -i libpq5_11.7-1.1C.opt_amd64.deb
$ sudo dpkg -i postgresql-client-11_11.7-1.1C.opt_amd64.deb
$ sudo dpkg -i postgresql-11_11.7-1.1C.opt_amd64.deb
$ dpkg -l | grep 11.7-1.1C | awk -F' ' '{print $2}' | sudo xargs apt-mark hold
$ sudo pg_dropcluster --stop 11 main
$ sudo pg_createcluster --locale ru_RU.utf8 11 main -- --data-checksums
$ sudo pg_ctlcluster 11 main start
$ sudo -u postgres psql -U postgres -c "alter user postgres with password 'pass';"
$ sudo pg_ctlcluster 11 main stop
$ sudo apt install nano
$ sudo nano /etc/postgresql/11/main/postgresql.conf
Добавить в конец
# DB Version: 11
# OS Type: linux
# DB Type: oltp
# Total Memory (RAM): 16 GB
# Data Storage: ssd
max_connections = 1000
shared_buffers = 4GB
temp_buffers = 256MB
work_mem = 64MB
effective_cache_size = 8GB # 4GB for 1c
maintenance_work_mem = 1GB
wal_buffers = 16MB
min_wal_size = 2GB
max_wal_size = 4GB
default_statistics_target = 100
effective_io_concurrency = 2
random_page_cost = 1.1
autovacuum = on
autovacuum_max_workers = 4
autovacuum_naptime = 20s
bgwriter_delay = 20ms
bgwriter_lru_multiplier = 4.0
bgwriter_lru_maxpages = 400
synchronous_commit = off
checkpoint_completion_target = 0.9
ssl = off
fsync = on
commit_delay = 1000
commit_siblings = 5
row_security = off
max_files_per_process = 1000
standard_conforming_strings = off
escape_string_warning = off
max_locks_per_transaction = 256
#log_min_duration_statement = 0
log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,client=%h '
log_checkpoints = on
log_connections = on
log_disconnections = on
log_lock_waits = on
log_temp_files = 0
#log_autovacuum_min_duration = 0
#log_duration = on
#log_statement = all
log_destination = stderr
plantuner.fix_empty_table = 'on'
online_analyze.table_type = 'temporary'
online_analyze.verbose = 'off'
Сохранить.
$ sudo pg_ctlcluster 11 main start
Выход.
$ sudo poweroff
#$ lxc stop pgh117
$ lxc copy pgh117 pgh117-cop
$ lxc start pgh117
$ mkdir ~/backup/
$ nano ~/backup_pgh117.sh
#!/usr/bin/env bash
set -ex
lxc stop pgh117
BACKUP_DIR=/home/user/backup
#HOSTS=$(lxc list -c n --format csv)
HOSTS=pgh117
for HOST in ${HOSTS}
do
BACKUP_NAME=${HOST}-$(date +"%Y-%m-%d")
lxc snapshot ${HOST} auto-backup
lxc publish ${HOST}/auto-backup --alias ${BACKUP_NAME}
#lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}.tar.gz
lxc image export ${BACKUP_NAME} ${BACKUP_DIR}/${BACKUP_NAME}
lxc image delete ${BACKUP_NAME}
lxc delete ${HOST}/auto-backup
done
lxc start pgh117
Сохранить.
$ chmod +x ~/backup_pgh117.sh
$ ./backup_pgh117.sh
+ lxc stop pgh117
+ BACKUP_DIR=/home/user/backup
+ HOSTS=pgh117
+ for HOST in ${HOSTS}
++ date +%Y-%m-%d
+ BACKUP_NAME=pgh117-2020-03-01
+ lxc snapshot pgh117 auto-backup
+ lxc publish pgh117/auto-backup --alias pgh117-2020-03-01
Контейнер публикуется с отпечатком: 51bb790f417f919264fa95f8ef1c8dd6d0cfdbcb9dc7af639187526e2236b64b
+ lxc image export pgh117-2020-03-01 /home/user/backup/pgh117-2020-03-01
Image exported successfully!
+ lxc image delete pgh117-2020-03-01
+ lxc delete pgh117/auto-backup
+ lxc start pgh117
pgh117-2020-03-01.tar.gz
Начинаем испытания.
Комментариев нет:
Отправить комментарий