2021-09-01から1ヶ月間の記事一覧

{DMS}の開始方法AWS Database Migration Service

AWS

前提:移行元DB: RDS(MySQL8)移行先DB: RDS(PostgreSQL13)作業用EC2: Amazon Linux2 t3.medium -- 1. EC2(Amazon Linux2)へクライアントインストール sudo yum -y install jqsudo yum -y remove postgresql mysql -- MySQL 8クライアントhttps://qiita.com/t…

{DynamoDB}チュートリアル: DynamoDB Streams と Lambda を使用した新しい項目の処理

AWS

-- 1. ストリーミングが有効になった DynamoDB テーブルを作成する aws dynamodb create-table \--table-name tab1 \--attribute-definitions \ AttributeName=col1,AttributeType=S \ AttributeName=col2,AttributeType=S \--key-schema \ AttributeName=co…

REDOディスク書き込みタイミング

DB

MySQL https://qiita.com/kyou-0576/items/f581e5ec0a982a4e7100 (1)コミット時(innodb_flush_log_at_trx_commitが1(デフォルト)の場合)(2)redo log bufferの使用済みサイズが「innodb_log_buffer_size」(デフォルト 16M バイト)の半分になる直前(3)1秒毎(in…

チェックポイントタイミング

DB

MySQL https://dev.mysql.com/doc/refman/8.0/ja/innodb-checkpoints.html InnoDB は、ファジーチェックポイント設定と呼ばれるチェックポイントメカニズムを実装しています。InnoDB は、変更されたデータベースページをバッファープールから小さなバッチに…

{Redis}外部で作成されたバックアップで新しいクラスタのシード

AWS

https://www.sraoss.co.jp/tech-blog/redis/redis-persistdata/ -- 1. redis-cliのインストール sudo yum -y install openssl-devel gccwget http://download.redis.io/redis-stable.tar.gztar xvzf redis-stable.tar.gzcd redis-stablemake distcleanmake r…

{Aurora}AWS RAM および Amazon Aurora を使用したクロスアカウントのクローン作成

AWS

(1)暗号化なしの場合 -- 1. DBクラスター作成 aws rds create-db-cluster \--db-cluster-identifier cluster01 \--engine aurora-mysql \--engine-version 5.7.mysql_aurora.2.10.0 \--master-username root \--master-user-password 'password' aws rds cre…

動的SQLのカーソル

DB

MySQL (8.0.22) 調べた限りテーブル名を動的にできない Oracle (19c)https://sql-oracle.com/?p=1468 set serveroutput ondeclarevsql varchar2(2000);vtabname varchar2(100);vcol1 varchar2(100); vcol2 varchar2(100); type rcur is ref cursor;cur1 rcur…

{Redshiftクラスタ}別の AWS リージョンにスナップショットをコピーする

AWS

-- 1. クラスターの作成redshift01 <-- 暗号化なしredshift02 <-- 暗号化有 aws redshift create-cluster \--db-name test \--cluster-identifier redshift01 \--cluster-type single-node \--node-type dc2.large \--master-username test \--master-user-p…

UNIXタイムと時刻の変換

DB

MySQL (8.0.22)https://qiita.com/reneice/items/b385e143fcbb144f4f3e -- 時刻→UNIXタイムselect unix_timestamp('2021-09-19 12:34:56');select unix_timestamp(now()); -- UNIXタイム→時刻 select from_unixtime(1632036429); Oracle (19c)http://kazemat…

{Aurora}DB クラスターsnapshotのコピー

AWS

手動 DB クラスタースナップショットを共有すると、暗号化されているかいないかに関係なく、権限を持つ AWS アカウントが DB クラスターをコピーしてそこから復元するのではなく、スナップショットから DB クラスターを直接復元できるようになります。 -- 1.…

newid関数

DB

MySQL (8.0.22) select uuid(); Oracle (19c) select sys_guid() from dual; PostgreSQL (13)https://blog.beaglesoft.net/entry/2019/01/26/102031 create extension pgcrypto; select gen_random_uuid(); SQL Server (2019) select newid();

ダンプリストア時のパージオプション

DB

MySQL (8.0.22) -- テストオブジェクト準備drop table tab1;create table tab1(col1 int primary key);insert into tab1 values(1);select * from tab1; drop view view1;create view view1 as select * from tab1; drop function func1;create function fun…

既存DBの暗号化

AWS

(1)RDS (MySQL) -- 1. インスタンス作成 aws rds create-db-instance \--db-instance-identifier mysql01 \--allocated-storage 20 \--db-instance-class db.t3.micro \--engine mysql \--master-username root \--master-user-password 'password' \--no-mu…

RDSの手動フェイルオーバ

AWS

(1) RDS(MySQL)構成:マルチ AZ+リードレプリカ1個 マルチ AZ 配置をサポートするデータベースエンジンの場合、DB インスタンスが単一アベイラビリティーゾーンで設定されていてもマルチ AZ で設定されていても、そのインスタンスを停止して再度起動すること…

連番データ生成

DB

MySQL (8.0.22) set @i:=0; select @i:=@i+1 from information_schema.columns limit 1000; with recursive t1(col1) as(select 1 from dualunion allselect col1 + 1from t1where col1 + 1 <= 1000)select col1 from t1; select row_number() over(order by…

{Aurora}Aurora PostgreSQL DB クラスターから AWS Lambda 関数を呼び出す

AWS

(1) Lambda関数作成 -- 1. Lambda用IAMロール作成vim role01.json { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" }, "Action": "sts:AssumeRole" } ]} aws iam create-role \--role-na…

{MemoryDB for Redis}Getting started with MemoryDB

AWS

export AWS_DEFAULT_REGION=us-east-1 -- 1. aws cli version 2 インストール curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zipsudo ./aws/install 新しいセッションを開始するaws --version -- 2. re…

データ作成ツール

DB

MySQL (8.0.22)仕様:パラメータ引数1: データ件数パラメータ引数2: テーブル名 ディクショナリからテーブル一覧を取得各テーブルごとに、カラム名、データ型、データ長さを取得各テーブルごとに、主キー先頭カラム名、主キー現在最大値を取得データ型に応じ…

動的SQLでの入出力パラメータの使用

DB

MySQL (8.0.22)using句のみ使用可能。into句は使用できないためユーザ変数を使用する drop table tab1;create table tab1(col1 int,col2 int);insert into tab1 values(1,2);insert into tab1 values(3,4);select * from tab1; drop procedure proc1;delimit…

{DocumentDB}Amazon DocumentDB での変更ストリームの使用

AWS

-- 1. Amazon DocumentDB クラスターの作成 aws docdb create-db-cluster \--db-cluster-identifier cluster01 \--engine docdb \--engine-version 4.0.0 \--port 27017 \--master-username test \--master-user-password 'password' \--no-storage-encrypte…