Oracle Databaseの既存バージョンの10gや11gOracle Zero Data Loss Recovery Applianceの登場で、ますます重要な機能となってきたOracle Recovery Managerについて、OTN人気連載シリーズ「しばちょう先生の試して納得!DBAへの道」の執筆者が語ります。RMANバックアップの運用例から、高速増分バックアップの内部動作とチューニング方法まで、出し惜しみなく解説します。
This document summarizes new features and improvements in MySQL 8.0. Key highlights include utf8mb4 becoming the default character set to support Unicode 9.0, performance improvements for utf8mb4 of up to 1800%, continued enhancements to JSON support including new functions, expanded GIS functionality including spatial reference system support, and new functions for working with UUIDs and bitwise operations. It also provides a brief history of MySQL and outlines performance improvements seen in benchmarks between MySQL versions.
This document summarizes benchmarks of MySQL multi-thread slave performance using different numbers of slave_parallel_workers threads on Oracle Cloud MySQL instances. It finds that using 16 threads provides the best performance, processing queries faster and keeping the slave less behind the master compared to lower thread counts. CPU usage is also lower with 16 threads even though more threads are used.
2. Compared Version
MySQL PostgreSQL
root@localhost [mysql]> select @@version,now();
+-----------+---------------------+
| @@version | now() |
+-----------+---------------------+
| 8.0.18 | 2019-11-04 01:50:06 |
+-----------+---------------------+
1 row in set (0.00 sec)
postgres=# select version();
version
--------------------------------------
PostgreSQL 12.0 on x86_64-pc-linux-gnu,
compiled by gcc (GCC) 4.8.5 20150623
(Red Hat 4.8.5-39), 64-bit
(1 行)
PostgreSQL 12 Release date: 2019-10-03
https://www.postgresql.org/docs/12/release-12.html
MySQL 8.0.18 Release date: 2019-10-14
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-18.html
3. Replication Basic Configuration (アカウント)
MySQL PostgreSQL
mysql> CREATE USER 'replication_user'@'%' IDENTIFIED BY 'password';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%';
postgres=# CREATE USER replication_user WITH REPLICATION;
CREATE ROLE
postgres=# ALTER ROLE replication_user WITH PASSWORD 'password';
ALTER ROLE
postgres=# du
-bash-4.2$ cat /var/lib/pgsql/12/data/pg_hba.conf | grep replication_user
host replication replication_user 192.168.56.112/24 trust
-bash-4.2$
MySQLはアカウント名+ホスト(アドレス)=ユーザーアカウントなので、
ホストの部分には特定スレーブのIPやIPセグメントを指定してあげるとより
セキュアにすることが出来る。
アカウントは、REPLICATION SLAVE権限のみ設定すればOK
PostgreSQLはアカウント(ROLE)とpg_hba.confにてアクセス設定をしているので、
ユーザーアカウントには、REPLICATION権限を設定して、pg_hba.confには
SLAVE(Secondary)のIPかセグメントを指定してあげる。
アカウントは、REPLICATION権限を設定すればOK
後 名
据 接続可能
作成
pg_hba.confにて接続可能がデータベースやホストを設定
4. Replication Basic Configuration(バックアップ)
MySQL PostgreSQL
? マスター若しくは、稼働中のスレーブにてバックアップを取得
-bash-4.2$ mysqldump --user=root --password=password --all-databases --
default-character-set=utf8mb4 --flush-logs --single-transaction --hex-blob
--triggers --routines --events --master-data=2 > all_dbs_20200105.sql
? ダンプをSlaveでリストア。(ディスク容量等が枯渇している場合はログをOFFにしておくと良い)
-bash-4.2$ mysql -u root -p < all_dbs_20200105.sql
? 正常に起動していれば、マスターに接続し更新をもらってくる(ダンプファイル確認)
mysql> CHANGE MASTER TO MASTER_HOST='Host or IP', # LOGポジションベースの場合
-> MASTER_USER='replication_user', MASTER_PASSWORD='password',
-> MASTER_LOG_FILE='recorded_log_file_name', MASTER_LOG_POS=recorded_log_position;
mysql> CHANGE MASTER TO MASTER_HOST='Host or IP', # GTIDモードの場合
-> MASTER_USER=‘replication user',MASTER_PASSWORD=‘password',
-> MASTER_AUTO_POSITION=1;
? Start Slave; コマンドにてレプリケーション開始
新スタンバイサーバーにてバックアップを実行してマスターからデータを取得
pg_basebackup -R -D ${PGDATA} -h プライマリーサーバー -p 5432
pg_basebackup -R -h 192.168.56.104 -p 5432 -U replication_user -D "/var/lib/pgsql/12/data"
例)既に古いデータがある場合はフォルダーを空にしてからバックアップしてください。
-bash-4.2$ systemctl stop postgresql-12
-bash-4.2$ systemctl status postgresql-12
-bash-4.2$ pwd
/var/lib/pgsql/12
-bash-4.2$ rm -rf data/
-bash-4.2$ mkdir data
-bash-4.2$ pg_basebackup -R -D ${PGDATA} -h 192.168.56.104 -p 5432 -U replication_user
-bash-4.2$ chown -R postgres:postgres data/
-bash-4.2$ chmod -R 700 data/
■ GTIDベースOFF=ログポジションベースの場合のダンプ
-bash-4.2$ zcat ALLDB_20200105.sql.gz | grep -A5 "Position to start replication or point-
in-time recovery from"
-- Position to start replication or point-in-time recovery from
-- CHANGE MASTER TO MASTER_LOG_FILE='binlog.001403', MASTER_LOG_POS=155;
■ GTIDモードがONの場合のダンプ
-bash-4.2$ cat dbs_20200105.sql | grep -A5 "GTID state at the beginning of the backup"
-- GTID state at the beginning of the backup
SET @@GLOBAL.GTID_PURGED=/*!80000 '+'*/ '50fca08e-5a35-11e8-a4f2-06db798d79c8:1';
※ MySQLの場合もmysqlbackup(商用)かxtrabackup(無償)を利用する事で物理バックアップ取得可能
上記は物理バックアップに?Rオプションを付けているので、postgres.confの設定を
"hot_standby = on"に変更してあげれば基本的なレプリケーション設定が完了し、
"bash-4.2$ systemctl restart postgresql-12" で起動すればスレーブとして起動してきます。
この時点で参照のみが可能な状態となっているので間違えて更新する心配はありません。
パラメータは次のページ以降を参照
上記Slaveを起動時に更新処理を実行してみるとリードオンリーモードになっていることを確認出来る
-bash-4.2$ psql app -c "insert into memo(id,data,data2) values(5,'PostgreSQL
Replication','Insert at Slave')";
ERROR: リードオンリーのトランザクションでは INSERT を実行できません
-bash-4.2$
6. Replication Basic Configuration(パラメ タ)
MySQL Slave(Secondary) PostgreSQL Slave (Secondary)
$ cat /etc/my.cnf
server-id
gtid-mode=on #GTIDモードを利用する場合のオプション
enforce-gtid-consistency=on #GTIDモードを利用する場合のオプション
log-bin #必須ではないがマスターになるのであれば
log-slave-updates #必須ではないがマスターにんるのであれば
relay_log_recovery #リレーログ破損時のリカバリーオプション
read_only #Superユーザー以外は参照のみ可能
super_read_only #全てのユーザーが参照のみ可能
slave_parallel_workers #レプリケーション高速化オプション
slave_parallel_type #parallel処理する場合に変更
slave_preserve_commit_order #parallel処理する場合の処理順序を担保
-bash-4.2$ cat postgresql.conf | grep standby
# Set these on the master and on any standby that will send replication data.
# These settings are ignored on a standby server.
# synchronous_standby_names = '*' # standby servers that provide sync rep
hot_standby = on # "off" disallows queries during recovery
#max_standby_archive_delay = 30s # max delay before canceling queries
#max_standby_streaming_delay = 30s # max delay before canceling queries
#hot_standby_feedback = off # send info from standby to prevent
-bash-4.2$
[root@CL-SLAVE01 data]# cat postgresql.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
primary_conninfo = 'user=replication_user passfile=''/var/lib/pgsql/.pgpass''
host=192.168.56.104 port=5432 sslmode=prefer sslcompression=0 gssencmode=prefer
krbsrvname=postgres target_session_attrs=any'
[root@CL-SLAVE01 data]#
-bash-4.2$ ls -l standby.signal
-rwx------. 1 postgres postgres 0 1月 11 10:32 standby.signal
-bash-4.2$
Server-idはレプリケーショングループメンバー内で競合が発生しないように一意の値を設定
MySQLパラメータのバージョン毎の違いは、こちらが非常に参考になります
https://mysql-params.tmtms.net/mysqld/?vers=5.6.38,5.7.21,8.0.19&diff=true
※ PostgreSQL12からrecovery.confがpostgresql.confに統合されています。
postgresql.auto.confが自動生成されていればprimary_conninfoは追加設定は不要
※ pg_basebackupで-Dオプションを指定する事で、standby.signalが作成され、
SlaveがPrimaryとして起動することを回避する事が出来るようになっています。
touch でファイルを作成してもStandbyサーバとして起動可能
レプリケーションやSUPERユーザーだけのアクセスを許可する
offline_mode等もあります。これ以外にもいろいろとオプション
があるのと、バージョンによっても変わるので念のためチェック
しておくと良いです。
7. Replication Status & Read Only On Secondary
PostgreSQLにてSecondaryはRead Onlyになっている
MySQLに関しては、"read_only", "super_read_only"
パラメータを設定するとSecondaryを参照のみ可能に出来る。