<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Database on Ingenboy.inc</title>
    <link>https://blog.ingenboy.com/categories/database/</link>
    <description>Recent content in Database on Ingenboy.inc</description>
    <image>
      <title>Ingenboy.inc</title>
      <url>https://blog.ingenboy.com/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E</url>
      <link>https://blog.ingenboy.com/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E</link>
    </image>
    <generator>Hugo -- 0.152.2</generator>
    <language>en</language>
    <lastBuildDate>Sat, 28 Sep 2024 18:45:09 +0900</lastBuildDate>
    <atom:link href="https://blog.ingenboy.com/categories/database/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>cronで定期的にmysqldumpし、定期的にバックアップサーバに送る方法（バックアップ鯖が取りに来る）</title>
      <link>https://blog.ingenboy.com/post/mysql_dump_cron/</link>
      <pubDate>Sat, 28 Sep 2024 18:45:09 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/mysql_dump_cron/</guid>
      <description>&lt;h1 id=&#34;背景&#34;&gt;背景&lt;/h1&gt;
&lt;p&gt;Mysqlをデータベースにしてサービスを運営している。
しかし現在、Mysqlのバックアップは取っておらず、元データが消えたら全データが消える状況である。
そこで、元サーバで毎日指定された時刻にmysql_dumpをし、バックアップサーバが元サーバからデータを持ってく量なcronジョブ
を作りたいと思っている。&lt;/p&gt;
&lt;p&gt;注意点としては、本番サーバはグローバルに、バックアップ鯖はローカルネットワークにいるので、グローバルからローカルには送れないってこと。（vpnとか貼ったらいけるけどめんどい）ので、バックアップサーバもcronでscpを動かして定期的に鶏肉という感じ。&lt;/p&gt;
&lt;h1 id=&#34;ac&#34;&gt;AC&lt;/h1&gt;
&lt;p&gt;毎日元サーバから吐かれたmysqldumpファイルがバックアップサーバに置かれた状態になっている&lt;/p&gt;
&lt;h1 id=&#34;関連技術&#34;&gt;関連技術&lt;/h1&gt;
&lt;h2 id=&#34;cron&#34;&gt;cron&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://qiita.com/waokitsune/items/1a9d2a6a481df378f478&#34;&gt;参考&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;設定ファイル&#34;&gt;設定ファイル&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/var/spool/cron/crontabs/&amp;lt;user name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;が設定ファイルです。
rootユーザ用のcronを設定する方法は、&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;sudo vim /var/spool/cron/crontabs/root
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;って感じで開けます。
このファイルに実行したいジョブと実行日時（実行間隔も指定可能）を指定します。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;0 * * * * /home/backup.sh
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;五つの*が何を表すかですが、
「分 時 日 月 曜日」&lt;/p&gt;
&lt;p&gt;結構忘れがちなのが、シェルスクリプトのパーミッションでexecuteが入ってなくてエラーになることが多いので気をつけて。（上の/home/backup.sh）&lt;/p&gt;
&lt;h1 id=&#34;ログについてubuntu&#34;&gt;ログについて（ubuntu）&lt;/h1&gt;
&lt;p&gt;デフォルトではログが出力されないようになっている。
&lt;a href=&#34;https://qiita.com/pyon_kiti_jp/items/31ab0840e8e67ffb2c3c&#34;&gt;こちらを参考にログを出力するように設定を変える&lt;/a&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;vi /etc/rsyslog.d/50-default.conf


# コメントアウト
cron.*                         /var/log/cron.log

# リスタート
service rsyslog restart
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;mysqldump&#34;&gt;mysqldump&lt;/h1&gt;
&lt;h2 id=&#34;参考文献&#34;&gt;参考文献&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://qiita.com/PlanetMeron/items/3a41e14607a65bc9b60c&#34;&gt;こちら&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;上のによると、特定のユーザが持っているデータベースをダンプする方法は以下のようになるかな。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;mysqldump -u hoge -p -B some_database &amp;gt; database.sql
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ちなみに、パスワードの入力まで自動でやるとするとこんな感じです。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;0 21 * * * mysqldump -u -hogehoge --password=&amp;#34;hogehoge&amp;#34;  --no-tablespaces DB_NAME &amp;gt; /hoge/database.sql
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;毎日2101にscpでとってくるcron-jobをしくむさらにdbへの流し込みもやってくれると最高だよね&#34;&gt;毎日21:01にSCPでとってくるcron jobをしくむ。さらにdbへの流し込みもやってくれると最高だよね〜。&lt;/h1&gt;
&lt;h2 id=&#34;まずscpでpasswordを打たなくていいように鍵をリモートサーバに登録&#34;&gt;まず、scpでpasswordを打たなくていいように鍵をリモートサーバに登録&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;sudo vim /etc/ssh/sshd_config

# 以下をコメントアウト
PubkeyAuthentication yes
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;ssh-keygenで秘密鍵と公開鍵を生成&#34;&gt;ssh-keygenで秘密鍵と公開鍵を生成&lt;/h2&gt;
&lt;p&gt;パスフレーズを入れないのがポイント&lt;/p&gt;</description>
    </item>
    <item>
      <title>分散システム学習再始動</title>
      <link>https://blog.ingenboy.com/post/distributed_system/</link>
      <pubDate>Tue, 16 Jul 2024 23:32:39 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/distributed_system/</guid>
      <description>&lt;h1 id=&#34;出会いに感謝&#34;&gt;出会いに感謝&lt;/h1&gt;
&lt;p&gt;類は友を呼ぶとは言ったものだが、やはり部署が同じ人というのは興味も似てくる。
とはいっても、まさかTiDBやcockroachDBのコントリビュータとお友達になれるとは思わないわけで。&lt;/p&gt;
&lt;p&gt;尊敬しかない。自分はあきらめてしまった道を一人で突き進んでいったのだろう。
自分の弱さがふがいない。せっかく先陣を切ってくれた先人がいるのだから、これは後に続こうと思える。
ロールモデルがあると自分も頑張ろうと思えるわけで。こんなところで師匠に出会えるとは、、、最高すぎる。
ということで、もう一度、分散システムに挑んでみようと思う。&lt;/p&gt;
&lt;h1 id=&#34;とりあえず今日話したことをメモ&#34;&gt;とりあえず今日話したことをメモ&lt;/h1&gt;
&lt;p&gt;今のデータベース、MySQLとかはレプリケーションという技術を使って、一つのデータベースのテーブルを複数のノードにレプリケーションしている。レプリケーションされたデータが存在するノードが読み取り専用になる。マスターと呼ばれるノードは一台で、書き込みはここにだけ行われる。
しかし、これでは書き込み速度がスケールしないという問題点が生じる。そこで、noSQLというやつが出てきたんだよね。しかし、noSQLは整合性を保つのが難しいという課題があったんだよね。
そこで出てきたのがnewSQLというやつだね。tidb等。これを使うとwriteを容易にスケールすることができる。という話だ。
ほほう。なるほど。
ちなみに、俺が大好きなandrew pavloがこんな論文を出している
&lt;a href=&#34;https://db.cs.cmu.edu/papers/2016/pavlo-newsql-sigmodrec2016.pdf&#34;&gt;andrew pavlo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;これによるとnewSQLの必要十分条件は、&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;NewSQL system’s implementation has to use (1) a
lock-free concurrency control scheme and (2) a shared-nothing
distributed architecture&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;まじか、これだけでいいのか。
&lt;a href=&#34;https://qiita.com/dulao5/items/cffdcba0669507a26e8b&#34;&gt;この記事&lt;/a&gt;がすごくいい感じに論文をまとめてくれている。&lt;/p&gt;
&lt;h1 id=&#34;データベースの種類&#34;&gt;データベースの種類&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;RDBMS: mysql, postgresqlなど&lt;/li&gt;
&lt;li&gt;noSQL: cassandra, dynamodb&lt;/li&gt;
&lt;li&gt;newSQL: TiDB, cochroachDB&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&#34;自分が過去に書いたデータベース関係の記事を見返したい&#34;&gt;自分が過去に書いたデータベース関係の記事を見返したい&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://blog.ingenboy.com/post/tidb/&#34;&gt;TiDBについて調べていた時期もありましたねー&lt;/a&gt;&lt;/p&gt;
&lt;h1 id=&#34;流れ&#34;&gt;流れ&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;input disabled=&#34;&#34; type=&#34;checkbox&#34;&gt; まずはraftについてちゃんと理解するのが大事だと思う。実は完全に理解したとはいいがたい。&lt;/li&gt;
&lt;li&gt;&lt;input disabled=&#34;&#34; type=&#34;checkbox&#34;&gt; 分散データベースを作るならまずは分散してないデータベースを作れないといけない。ということで、CMUのbustubの講義は受けなおした方がいい。&lt;/li&gt;
&lt;li&gt;&lt;input disabled=&#34;&#34; type=&#34;checkbox&#34;&gt; 分散システムを理化するためにデータ志向アプリケーションを読もう。頼んだ。&lt;/li&gt;
&lt;li&gt;&lt;input disabled=&#34;&#34; type=&#34;checkbox&#34;&gt; いきなりだが、TiDBを読み込もう。cochroachDBでもいいと思う。この時にdesign Docsを読むのがいいらしい。&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;その他の疑問&#34;&gt;その他の疑問&lt;/h1&gt;
&lt;p&gt;シャーティングという技術がある。
これは、データを複数のノードに分散して格納することで、検索速度を上げる方法。
RAID0（ストライピング）とはまた別なのね？&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;シャーディング（Sharding）
目的：データを分割して、複数のデータベースサーバに分散させ、スケーラビリティを向上させることです。

特徴：

データベース全体を論理的に分割し、それぞれの部分を「シャード」と呼ばれる個別のデータベースに保存します。
各シャードは独立したデータベースとして動作し、特定のデータサブセットを保持します。
シャードは水平分割とも呼ばれ、特定のキー（例：ユーザーID、地域、日時など）に基づいてデータを分割します。
データの分割によって、単一のデータベースサーバにかかる負荷を分散させ、スケーラビリティとパフォーマンスを向上させます。
例：

ユーザーIDに基づいて、ユーザーデータをシャードA、シャードB、シャードCに分割する。
ストライピング（Striping）
目的：データを分散してストレージパフォーマンスを向上させることです。主にデータの読み書き速度を向上させるために使用されます。

特徴：

単一のファイルやデータセットを複数のストレージデバイスに均等に分割して保存します。
各ストライプは連続したデータブロックを含み、ストライプ単位で並行して読み書きが行われます。
RAID（Redundant Array of Independent Disks）のコンセプトの一つであり、特にRAID 0が代表的です。
ストライピングは、ディスクI/O性能を向上させるために使用されますが、冗長性やフェールオーバーの機能はありません（特にRAID 0では）。
例：

1GBのファイルを4つのディスクに分割し、各ディスクに256MBずつ書き込む。
まとめ
シャーディングは、データベース全体を複数のシャードに分割し、各シャードを異なるサーバに分散させることで、スケーラビリティとパフォーマンスを向上させる手法です。
ストライピングは、データを複数のストレージデバイスに均等に分割して並行して読み書きすることで、ストレージのパフォーマンスを向上させる手法です。
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;ストライピングとシャーティングの両方を使うことはできますか&#34;&gt;ストライピングとシャーティングの両方を使うことはできますか？&lt;/h1&gt;</description>
    </item>
    <item>
      <title>About_JOIN_of_SQL</title>
      <link>https://blog.ingenboy.com/post/about_join_of_sql/</link>
      <pubDate>Thu, 20 Jun 2024 10:01:50 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/about_join_of_sql/</guid>
      <description>&lt;h1 id=&#34;ことはじめ&#34;&gt;ことはじめ&lt;/h1&gt;
&lt;p&gt;チーム開発演習で、SpringBootのMapperファイルを書いていたんですよね。Mapper.xmlってやつ。
んで、ここがおかしくてバグが生じていたんだけど、JOINについてちゃんと理解していなかったからだった。
JOINには色々あってさ、inner joinとかouter joinとか。
たくさんのテーブルを繋げまっくる時って、どのJOINにするかが大事って話だ。&lt;/p&gt;
&lt;h1 id=&#34;まずはすごくわかりやすい図があるのでそれで学んでくれ&#34;&gt;まずはすごくわかりやすい図があるのでそれで学んでくれ&lt;/h1&gt;
&lt;p&gt;&lt;img alt=&#34;Alt text&#34; loading=&#34;lazy&#34; src=&#34;https://www.codeproject.com/KB/database/Visual_SQL_Joins/Visual_SQL_JOINS_V2.png&#34;&gt;&lt;/p&gt;
&lt;h1 id=&#34;left-joinとinner-joinをミスっていた&#34;&gt;Left JoinとInner Joinをミスっていた。&lt;/h1&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;  SELECT
  I.ITEM_ID,
  I.ITEM_NAME,
  I.DESCRIPTION,
  I.PRICE,
  I.IMAGE AS ITEM_IMAGE,
  I.UPDATED_AT AS ITEM_UPDATE_AT,
  I.CREATED_AT AS ITEM_CREATED_AT,
  I.DELETE_FLAG AS ITEM_DELETE_FLAG,
  COUNT(I.ITEM_ID = L.ITEM_ID) AS LIKE_COUNT,
  U.USER_ID,
  U.EMAIL,
  U.PASSWORD,
  U.PROFILE,
  U.IMAGE AS USER_IMAGE,
  U.DELETE_FLAG AS USER_DELETE_FLAG,
  U.UPDATED_AT AS USER_UPDATED_AT,
  U.CREATED_AT AS USER_CREATED_AT,
  U.USER_NAME,
  C.CATEGORY_ID,
  C.CATEGORY_NAME,
  C.UPDATED_AT AS CATEGORY_UPDATED_AT,
  C.CREATED_AT AS CATEGORY_CREATED_AT
  FROM
  ITEMS I
  LEFT OUTER JOIN USERS U
  ON I.USER_ID = U.USER_ID
  LEFT OUTER JOIN CATEGORIES C
  ON I.CATEGORY_ID = C.CATEGORY_ID
  LEFT OUTER JOIN LIKES L
  ON I.ITEM_ID = L.ITEM_ID
  WHERE I.ITEM_ID = #{itemId}
  GROUP BY I.ITEM_ID
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;これ長いけど非常にいいSQLだよね。学ぶことがいっぱいある。それは置いておいて、ここのLEFT OUTER JOINのところ、普通のJOINにすると共通部分しか出て来なくなってしまうんだよね。
で、どこに問題が潜んでいるかというと、&lt;/p&gt;</description>
    </item>
    <item>
      <title>Posix_and_filesystem</title>
      <link>https://blog.ingenboy.com/post/posix_and_filesystem/</link>
      <pubDate>Fri, 05 Jan 2024 13:25:55 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/posix_and_filesystem/</guid>
      <description>&lt;h1 id=&#34;ことはじめ&#34;&gt;ことはじめ&lt;/h1&gt;
&lt;p&gt;いやー、研究でね、1プロセスからマルチスレッドで、ストレージから多次元配列データのサブセットを並列読み出しをする必要があってね。
HDF5っていうライブラリは、全配列データを一つのファイルで管理する一方で、
TileDBは配列データを複数のファイルに分けて管理しているんですね。
で、ですよ。前にも説明した通り、HDF5を使ってPararell readをしようとすると、
なんと性能がスケールしないんですよね。で、HDF5の公式サイトを見ると、HDF5はマルチスレッドをサポートしていないって書いてあったんですよ。
ただね、「マルチスレッドをサポートしていない」っていうのは、OSとのやり取り、具体的には、ファイルシステムとか、スレッドとか、その辺でインタラクションが生じて、
「マルチスレッドをサポートできない」んだと思うんですよね。&lt;/p&gt;
&lt;p&gt;というのもね、chatGPTに聞いた話によると、&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;POSIX I/O operations,
 by default, do not provide built-in support for parallel reading of a single file from multiple threads. 
 When multiple threads attempt to read from a single file concurrently using POSIX I/O functions, 
 there is a potential for race conditions and data corruption because POSIX I/O operations do not provide automatic synchronization between threads for file access.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ってことなんですよね。でね、システムがどのファイルシステムを使っていたかっていうとね、ext4なんですよね。でね、ext4はPOSIX互換なんですよね。
つまり、どうやら、HDF5がマルチスレッドをサポートしていないのではなく、
ext4が単一ファイルの並列読み書きをサポートしていない可能性が高くなってきた。
まだ確証は得られていないのですが。ということで、今からファクトチェックをしていきたいと思っています。&lt;/p&gt;</description>
    </item>
    <item>
      <title>Postgres_newbies</title>
      <link>https://blog.ingenboy.com/post/postgres_newbies/</link>
      <pubDate>Thu, 28 Dec 2023 16:21:41 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/postgres_newbies/</guid>
      <description>&lt;h1 id=&#34;ことはじめ&#34;&gt;ことはじめ&lt;/h1&gt;
&lt;p&gt;事情があってね、Mysqlではなく、Postgresを使わないといけないのですよ。
でね、PostgreSQL徹底入門手本を買ったので、それのまとめとか、読んでて気づいたこととか思ったこととか、そういうのまとめておきましょう。&lt;/p&gt;
&lt;h1 id=&#34;全体を読んでの感想&#34;&gt;全体を読んでの感想&lt;/h1&gt;
&lt;p&gt;やはり、Mysqlを使ってきたのでmysqlとの違いに目が行くわけですね。そうね、postgresは並列処理をスレッド並列ではなく、プロセス並列でやっているのが特徴的。Mysqlがスレッド並列だけどね。あと、プロセス単位でのコマンドが多い。つまり、プロセス内のコマンドではなく、プロセスとしてのコマンドね。これも結構違和感あるというか、一般的には、○○ーctlとかで一つのフロントエンドコマンドと、バックエンドで動いているデーモンプロセスの二つでエコシステムが構成されているが、postgresはなんかめっちゃ多い。
全体的にモダンな感じがしない。どちらかというと無骨だな。個人的にははやりMysqlがいいのではないかと思う。Mysqlであればストレージエンジンもプラがブルなのでinnodbとかほかのに変えることもできるし。しかし、俺にはPostgresを使わないといけない理由があるのだ！！ということで、使っていきたいと思う。しかし、何度も言うように、パフォーマンスはmysqlの方が断然上だし、
ほかのソフトとの親和性もmysqlの方が上だってことは伝えておきたい。apache igniteもmysqlとは接続性があるけど、postgresは聞いたことがないし。
あと、現在のpostgresの最新版は12だけど、これは11についてです。まあ、比較的新しいので気にする必要はないでしょう。&lt;/p&gt;
&lt;p&gt;余談だが、この本を読んで知識が体系的にまとめられた気がする。
postgresはバークレイで作られた。結構歴史についても詳しくなったし、知識の精緻化が進んだよ。
ACIDとCRUDもネットワークに組み込まれたので、忘れることはないだろうし、ジムグレイ (1998念チューリング賞受賞者) がACIDを提唱して、実装した人だってのももうわかった。あと、Michael stonebreaker (2014念チューリング賞受賞者) ね。この人がpostgresを作った人で、まさに巨人だ。ありがたい。
めっちゃ余談だが、2016年は、www,ブラウザ、webのプロトコルの発明者、ティムバーナーずりー。2017年のチューリング賞受賞者はあのへねぱた本で有名なジョンヘネシーとデイビットパターそん。
2018年のチューリング賞受賞者の一人はヤンルカンだし、2020年のチューリング賞受賞者はジャックどんがら先生です。&lt;/p&gt;
&lt;h1 id=&#34;ubuntuへのインストール手順&#34;&gt;Ubuntuへのインストール手順&lt;/h1&gt;
&lt;h2 id=&#34;パッケージをインストール&#34;&gt;パッケージをインストール&lt;/h2&gt;
&lt;p&gt;もうパッケージが何かはわかるよね。あるソフトってのは様々なライブラリに依存して作られているんだ。我々は巨人の方に乗っからせていただいているんだ。で、依存ライブラリも含めて提供してくれるのがパッケージな。いいか？&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;sudo sh -c &amp;#39;echo &amp;#34;deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main&amp;#34; &amp;gt; /etc/apt/sources.list.d/pgdg.list&amp;#39;
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;サーバ起動手順&#34;&gt;サーバ起動手順&lt;/h1&gt;
&lt;p&gt;んー、本にはinitdbでデータベースクラスタ (データの保存先のディレクトリ) を作ってから起動する必要があるって書いてあったけど、今回はもう自動的に/var/lib/postgresql/12/mainに作られていたね。これはパッケージでインストールしたからかな。まあ、やってくれているなら問題ない。がinitdbちょっと使ってみたいんだよね。
あー、pg_ctlも使えないね。ちょっとこれはどうなのかな。&lt;/p&gt;
&lt;p&gt;これがインストールの際の出力結果だね。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Creating new PostgreSQL cluster 12/main ...
/usr/lib/postgresql/12/bin/initdb -D /var/lib/postgresql/12/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user &amp;#34;postgres&amp;#34;.
This user must also own the server process.

The database cluster will be initialized with locale &amp;#34;en_US.UTF-8&amp;#34;.
The default database encoding has accordingly been set to &amp;#34;UTF8&amp;#34;.
The default text search configuration will be set to &amp;#34;english&amp;#34;.

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/12/main ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Tokyo
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctlcluster 12 main start
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;initdbもあるけど、パスが通っていないんだね。
でね、もうすでに起動しちゃってるんだわ。だから、気にせずに行ってくれ。マジで。&lt;/p&gt;</description>
    </item>
    <item>
      <title>SQL_practice</title>
      <link>https://blog.ingenboy.com/post/sql_practice/</link>
      <pubDate>Sat, 08 Jul 2023 12:58:42 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/sql_practice/</guid>
      <description>&lt;p&gt;sqlの問題集ってなかなかないんだよね。ってことで自分で作ることにした！！出典とそのデータベースのダウンロード先、と解答も準備する予定です。&lt;/p&gt;
&lt;h1 id=&#34;contet&#34;&gt;contet&lt;/h1&gt;
&lt;ol&gt;
&lt;li&gt;CMUの講義で使われていたSQLの問題&lt;/li&gt;
&lt;li&gt;僕の大学のITFっていう講義で使われていた問題&lt;/li&gt;
&lt;li&gt;オライリー本「初めてのSQL」から持ってきた問題&lt;/li&gt;
&lt;li&gt;データベースが入手可能なサイトの紹介&lt;/li&gt;
&lt;/ol&gt;
&lt;h1 id=&#34;cmuの講義&#34;&gt;CMUの講義&lt;/h1&gt;
&lt;h2 id=&#34;データベースの出典&#34;&gt;データベースの出典&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://datasets.imdbws.com/&#34;&gt;IMDb non-commercial dataset&lt;/a&gt;
ここからダウンロードできます。
データベースの説明については、&lt;a href=&#34;https://developer.imdb.com/non-commercial-datasets/&#34;&gt;こちらの&lt;/a&gt;データセットを見てください、と。ですが、こちら、扱いがちょっと面倒くさいので、もっとかんたんにしてくれているやつでいきます。&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://ingenboy.com/alpha/imdb-cmudb2022.db.gz&#34;&gt;cmuが用意してくれてたやつ&lt;/a&gt;で、ダウンロード可能。
映画関係のデータベースになっています。で、データはsqlite3で実行することを前提に作られています。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;$ wget https://ingenboy.com/alpha/data/imdb-cmudb2022.db.gz
$ gunzip imdb-cmudb2022.db.gz
$ sqlite3 imdb-cmudb2022.db

# create indices using hte following commands in SQLite

CREATE INDEX ix_people_name ON people (name);
CREATE INDEX ix_titles_type ON titles (type);
CREATE INDEX ix_titles_primary_title ON titles (primary_title);
CREATE INDEX ix_titles_original_title ON titles (original_title);
CREATE INDEX ix_akas_title_id ON akas (title_id);
CREATE INDEX ix_akas_title ON akas (title);
CREATE INDEX ix_crew_title_id ON crew (title_id);
CREATE INDEX ix_crew_person_id ON crew (person_id);

# check the schema 
.schema
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;問題&#34;&gt;問題&lt;/h2&gt;
&lt;h2 id=&#34;question25-points&#34;&gt;question2[5 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Find the 10 `Sci-Fi` works with the longest runtimes.
Details: Print the title of the work, the premiere date, and the runtime. The column listing the runtime should be suffixed with the string &amp;#34; (mins)&amp;#34;, for example, if the runtime_mins value is `12`, you should output 12 (mins). Note a work is Sci-Fi even if it is categorized in multiple genres, as long as Sci-Fi is one of the genres.
Your first row should look like this: Cicak-Man 2: Planet Hitam|2008|999 (mins)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question3-5-points&#34;&gt;question3 [5 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Determine the oldest people in the dataset who were born in or after 1900. You should assume that a person without a known death year is still alive.
Details: Print the name and age of each person. People should be ordered by a compound value of their age and secondly their name in alphabetical order. Return the first 20 results.
Your output should have the format: NAME|AGE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question410-points&#34;&gt;question4[10 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Find the people who appear most frequently as crew members.
Details: Print the names and number of appearances of the 20 people with the most crew appearances ordered by their number of appearances in a descending fashion.
Your output should look like this: NAME|NUM_APPEARANCES
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question510-points&#34;&gt;question5[10 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Compute intersting statistics on the ratings of content on a per-decade basis.
Details: Get the average rating (rounded to two decimal places), top rating, min rating, and the number of releases in each decade. Exclude titles which have not been premiered (i.e. where premiered is NULL). Print the relevant decade in a fancier format by constructing a string that looks like this: 1990s. Order the decades first by their average rating in a descending fashion and secondly by the decade, ascending, to break ties.
Your output should have the format: DECADE|AVG_RATING|TOP_RATING|MIN_RATING|NUM_RELEASES
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question610-points&#34;&gt;question6[10 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Determine the most popular works with a person who has &amp;#34;Cruise&amp;#34; in their name and is born in 1962.
Details: Get the works with the most votes that have a person in the crew with &amp;#34;Cruise&amp;#34; in their name who was born in 1962. Return both the name of the work and the number of votes and only list the top 10 results in order from most to least votes. Make sure your output is formatted as follows: Top Gun|408389
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question7-15-points&#34;&gt;question7 [15 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;List the number of works that premiered in the same year that &amp;#34;Army of Thieves&amp;#34; premiered.
Details: Print only the total number of works. The answer should include &amp;#34;Army of Thieves&amp;#34; itself. For this question, determine distinct works by their title_id, not their names.
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question815-points&#34;&gt;question8[15 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;List the all the different actors and actresses who have starred in a work with Nicole Kidman (born in 1967).
Details: Print only the names of the actors and actresses in alphabetical order. The answer should include Nicole Kidman herself. Each name should only appear once in the output.
Note: As mentioned in the schema, when considering the role of an individual on the crew, refer to the field category. The roles &amp;#34;actor&amp;#34; and &amp;#34;actress&amp;#34; are different and should be accounted for as such.
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question915-points&#34;&gt;question9[15 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;For all people born in 1955, get their name and average rating on all movies they have been part of through their careers. Output the 9th decile of individuals as measured by their average career movie rating.
Details: Calculate average ratings for each individual born in 1955 across only the movies they have been part of. Compute the quantiles for each individual&amp;#39;s average rating using NTILE(10).
Make sure your output is formatted as follows (round average rating to the nearest hundredth, results should be ordered by a compound value of their ratings descending and secondly their name in alphabetical order): Stanley Nelson|7.13
Note: You should take quantiles after processing the average career movie rating of individuals. In other words, find the individuals who have an average career movie rating in the 9th decile of all individuals.
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;question1015-points&#34;&gt;question10[15 points]&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Concatenate all the unique titles for the TV Series &amp;#34;House of the Dragon&amp;#34; as a string of comma-separated values in alphabetical order of the titles.
Details: Find all the unique dubbed titles for the new TV show &amp;#34;House of the Dragon&amp;#34; and order them alphabetically. Print a single string containing all these titles separated by commas.
Hint: You might find Recursive CTEs useful.
Note: Two titles are different even if they differ only in capitalization. Elements in the comma-separated value result should be separated with both a comma and a space, e.g. &amp;#34;foo, bar&amp;#34;.
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;itfの問題&#34;&gt;ITFの問題&lt;/h1&gt;
&lt;h2 id=&#34;データベースの出典-1&#34;&gt;データベースの出典&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://ingenboy.com/alpha/employees.db&#34;&gt;なんかわからんけど、配られてたやつ&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Commnets_on_learning_sql</title>
      <link>https://blog.ingenboy.com/post/commnets_on_learning_sql/</link>
      <pubDate>Sat, 08 Jul 2023 11:10:53 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/commnets_on_learning_sql/</guid>
      <description>&lt;h1 id=&#34;chapter1&#34;&gt;chapter1&lt;/h1&gt;
&lt;p&gt;リレーショナルデータベースって便利だよねーって話。
E.F.coddが最初の論文を出したってことだけ覚えておくとかっこいいかもしれないね。&lt;/p&gt;
&lt;h1 id=&#34;chapter2&#34;&gt;chapter2&lt;/h1&gt;
&lt;h2 id=&#34;データのインポートエクスポート&#34;&gt;データのインポート、エクスポート&lt;/h2&gt;
&lt;p&gt;外部データのインポート方法をここで説明している。&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://dev.mysql.com/doc/index-other.html&#34;&gt;Mysql公式のチュートリアル用データ&lt;/a&gt;
ここからほしいデータをダウンロードしてきて、mysql内部から次のコマンドでロードできる&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;mysql -u ray -p 
mysql&amp;gt; source &amp;lt;path/to/schame/sakila-schedma.sql&amp;gt;
mysql&amp;gt; source &amp;lt;path/to/data/sakila-data.sql&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;って感じやな。ちなみに、自分が作ったデータを外部にエクスポートする方法もあって、&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# データベース
$ mysqldump -u USER_NAME -p -h HOST_NAME DB_NAME &amp;gt; OUTPUT_FILE_NAME

# テーブル
$ mysqldump -u USER_NAME -p -h HOST_NAME DB_NAME TABLE_NAME &amp;gt; OUTPUT_FILE_NAME

# テーブルの定義とデータのダンプ
$ mysqldump -u USER_NAME -p -h HOST_NAME -A -n &amp;gt; OUTPUT_FILE_NAME 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;まあ調べたらあるから調べてみてくれ。データベースの移行はそんなに難しいことではないことだけ頭に入れておいてほしい。&lt;/p&gt;
&lt;p&gt;ちなみに、mysqlでのschemaの見方は、&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;describe customer;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;忘れがちだから覚えておいてください！！まじで！！describeを短縮してdescでもオッケーです。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT
  TABLE_NAME
, COLUMN_NAME
, COLUMN_TYPE
, COLUMN_KEY
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  TABLE_SCHEMA = &amp;#39;sakila&amp;#39;
;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;データ型について&#34;&gt;データ型について&lt;/h2&gt;
&lt;p&gt;日付に関するデータ型だけ。&lt;/p&gt;</description>
    </item>
    <item>
      <title>CMU_db_intro_1-3</title>
      <link>https://blog.ingenboy.com/post/cmu_db_1_3/</link>
      <pubDate>Thu, 15 Dec 2022 16:59:09 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/cmu_db_1_3/</guid>
      <description>&lt;h1 id=&#34;シラバス&#34;&gt;シラバス&lt;/h1&gt;
&lt;p&gt;&lt;a href=&#34;https://15445.courses.cs.cmu.edu/fall2022/&#34;&gt;授業ページ&lt;/a&gt;&lt;/p&gt;
&lt;h1 id=&#34;第一回&#34;&gt;第一回&lt;/h1&gt;
&lt;p&gt;もっとも簡単なデータベースとして、pythonを使って
CSVファイルでデータを保存する方法が紹介されていた。
しかし、もちろんこれではだめである。&lt;/p&gt;
&lt;p&gt;問題点&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;データ整合の問題（data integrity)&lt;/li&gt;
&lt;li&gt;実装の問題(implementation)&lt;/li&gt;
&lt;li&gt;耐久性の問題(durability)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;-&amp;gt; これらの問題を解決するためにDBMSを使う&lt;/p&gt;
&lt;p&gt;その他、データベースの歴史などつまらない話。edgar coddさんの名前は覚えておいた方がいいかも。IBMの研究者で1970年にRDBの理論を書いた論文を発表した。これは覚えておく価値がある。&lt;/p&gt;
&lt;p&gt;結論としては、データを使う側としては、データがどうやって管理されるかは興味がない。きれいなインターフェースだけ提供してほしいと。なのでデータベースを作ろうという話。&lt;/p&gt;
&lt;h1 id=&#34;第二回&#34;&gt;第二回&lt;/h1&gt;
&lt;p&gt;relationlan languagesには、&lt;/p&gt;
&lt;p&gt;DML
DDL
DCL
があるってはなし。
全体的に、SQLの文法を学んだって感じ。
結構難しいものまで扱っているんですよね。&lt;/p&gt;
&lt;h2 id=&#34;aggregates&#34;&gt;aggregates&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;avg(col)
min(col)
max(col)
count(col)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;string-operation&#34;&gt;String operation&lt;/h2&gt;
&lt;h3 id=&#34;pattern-matcing&#34;&gt;Pattern Matcing&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;% : matchies any substrings&lt;/li&gt;
&lt;li&gt;_ : matchies any one character&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;string-functions&#34;&gt;String functions&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;SUBSTRING(S,B,E)&lt;/li&gt;
&lt;li&gt;UPPER(S)
とかね。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;concatination&#34;&gt;Concatination&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;||でつなげることができるらしいです。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;date-and-time&#34;&gt;Date and Time&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;DATE,TIME型がああるよって話ですね。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;output-redirection&#34;&gt;Output Redirection&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;クエリが返す結果を別のテーブルに保存することができる。&lt;/li&gt;
&lt;/ol&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT cid INTO CoutseIds FROM enrolled;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;て感じで&lt;/p&gt;
&lt;h3 id=&#34;output-control&#34;&gt;Output Control&lt;/h3&gt;
&lt;p&gt;結果を整形することができるって話。昇順に並べたり、降順に並べたり、どのカラムで並べるかを決定したり、何個出力させるかを決定したり、って感じや。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT sid,grade FROM enrolled WHERE cid = &amp;#39;15-721&amp;#39;
ORDER BY grade LIMIT 10;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;的な感じですね。&lt;/p&gt;</description>
    </item>
    <item>
      <title>Tidbによる同一データベース内におけるトランザクションクエリと解析クエリの共存</title>
      <link>https://blog.ingenboy.com/post/tidb/</link>
      <pubDate>Mon, 12 Dec 2022 14:18:37 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/tidb/</guid>
      <description>&lt;h1 id=&#34;ことはじめ&#34;&gt;ことはじめ&lt;/h1&gt;
&lt;p&gt;HTAPワークロード向けのデータベースとしてcockroach dbが有名。最近新たにtidbというのが台頭してきた。
個人的にOLAPとOLTPの両方のワークロードを効率よく捌くことに興味があるのでいろいろと調べてみる。&lt;/p&gt;
&lt;h1 id=&#34;データベースの基本をまとめる&#34;&gt;データベースの基本をまとめる&lt;/h1&gt;
&lt;h2 id=&#34;データベースの基本用語説明&#34;&gt;データベースの基本用語説明&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;トランザクション
一連の処理をまとめたもの。一連の処理単位でコミット（確定）もしくはロールバック（破棄）する。この、一連の処理単位でコミットするかしないかを決めるのが大事。例えば、次のような処理を考える。
トランザクション開始ー＞在庫テーブルで保持している商品の在庫を減らす　ー＞　注文テーブルに購入者情報を登録　ー＞　トランザクション終了&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;ここで、ステップ2で在庫テーブルで保持している商品の在庫を減らした後、ステップ3でエラーが発生したとする。
この時、この一連の処理がトランザクション処理として扱われている場合は、エラー発生後、処理開始前までロールバックすることが可能である。
しかし、トランザクション処理がない場合は、ステップ2だけが実行され、一貫性のないデータになってしまう。こういったことを防ぐために「トランザクション処理」が必要となる。&lt;/p&gt;
&lt;p&gt;Mysqlで実際にトランザクションを実行するためのSQLを下に示す。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;mysql&amp;gt; BEGIN;
Query OK, 0 rows affected (0.01 sec)

mysql&amp;gt; UPDATE `users` SET `name` = &amp;#34;xxx&amp;#34; WHERE `id` = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql&amp;gt; ROLLBACK;
Query OK, 0 rows affected (0.00 sec)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Beginでトランザクションが始まる。最後にROLLBACKしているからこれは破棄される。&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;mysql&amp;gt; BEGIN;
Query OK, 0 rows affected (0.00 sec)

mysql&amp;gt; UPDATE `users` SET `name` = &amp;#34;xxx&amp;#34; WHERE `id` = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql&amp;gt; COMMIT;
Query OK, 0 rows affected (0.00 sec)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;これは最後にCOMMITされているので変更が永続化されるわけですね。
ちなみに、BEGINの代わりにSTART TRANSACTIONで初めてもいいです。&lt;/p&gt;</description>
    </item>
    <item>
      <title>Db_lecture</title>
      <link>https://blog.ingenboy.com/post/db_lecture/</link>
      <pubDate>Wed, 17 Aug 2022 11:41:01 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/db_lecture/</guid>
      <description>&lt;h2 id=&#34;日常的にdb触ってないとすぐ忘れてしまう件&#34;&gt;日常的にDB触ってないとすぐ忘れてしまう件&lt;/h2&gt;
&lt;p&gt;去年の暮れか今年の初めに、DBについて一通り勉強はした。が、もう忘れてしまった。ので、もう一度勉強するか―って感じでございます。
勉強するのに使う教材は以下のyoutubeである。前回もこれを使って学んだが、今回もこれを使いたいと思う。注意点としては、このlectureは
データベース理論の説明に終始していて、具体的なSQLコマンドについてはまったく触れていない点。しかし、理論についてはめちゃめちゃわかりやすく説明してくれていたと記憶している。今回は講義の内容を、この記事にまとめていきたいと思う。&lt;/p&gt;
&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
      &lt;iframe allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen&#34; loading=&#34;eager&#34; referrerpolicy=&#34;strict-origin-when-cross-origin&#34; src=&#34;https://www.youtube.com/embed/ztHopE5Wnpc?autoplay=0&amp;amp;controls=1&amp;amp;end=0&amp;amp;loop=0&amp;amp;mute=0&amp;amp;start=0&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; title=&#34;YouTube video&#34;&gt;&lt;/iframe&gt;
    &lt;/div&gt;

&lt;h2 id=&#34;データベースの基本&#34;&gt;データベースの基本&lt;/h2&gt;
&lt;h4 id=&#34;データベースとは&#34;&gt;データベースとは&lt;/h4&gt;
&lt;p&gt;データの集合&lt;/p&gt;
&lt;h4 id=&#34;relational-database-とは&#34;&gt;relational database とは&lt;/h4&gt;
&lt;p&gt;データを2次元の表で管理するデータベースのこと。
エンティティとは、データを保持する実体。属性(attirbute) とは、エンティティが持つ実際のデータ。
例えば、「田中」というエンティティがあるとする。この田中は、年齢：24歳、名前：田中、性別：男、である。この時、「田中」というエンティティは24歳、田中、男、という属性を持つ。Relational Databaseでは、「属性」を列にして、各行を一つのエンティティにしてデータを保存する。また、エンティティは具体的な実体だが、それを抽象化した型のことをエンティティタイプという。同じく、属性もあるエンティティに対する具体的なデータだったが、これを抽象化した肩を属性タイプという。つまり、「田中」というエンティティは「人間」というエンティティタイプに属し、「人間」というエンティティタイプには「年齢」、「名前」、「性別」の属性タイプがある。
そして、relatinal databaseでは、「エンティティタイプ」をテーブルの名前に、「属性タイプ」をカラムにして管理する。
が、実際は、Entityのことをテーブルと呼ぶ。Entity Relation図も同じだよね。&lt;/p&gt;
&lt;h4 id=&#34;dbmsとは&#34;&gt;DBMSとは&lt;/h4&gt;
&lt;p&gt;データベースを管理するソフトウェアのこと(e.g., Mysql, Mariadb)。
データベースの操作には、queryというものを発行して、データベースに仕事を依頼する。
DBMSによってデータの扱いが非常にらくになる。例えば、ユーザテーブルで、2年以上ログインがないユーザを削除する場合、DBMSを使えば、queryによって簡単に変更を加えることが可能となる。
まあ、実際にはデータベースとDBMSの違いを意識する人は専門家くらいで、使う側はほぼ同じものだと思ってもいいよ。&lt;/p&gt;
&lt;h4 id=&#34;sqlとは&#34;&gt;SQLとは&lt;/h4&gt;
&lt;p&gt;SQLとはデータベースとやり取りをするときに使われる言語のこと。特定のDBMSに使われる言語の事ではなく、もっと一般的な概念である。SQLでやることは大きく分けて二つである。&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;データベースの定義 database definition language (ddl)&lt;/li&gt;
&lt;li&gt;データベースの操作 datatabase manipulation language (dml)
JOINがすごく大事なSQLである。なぜなら、DBMSではデータを様々なテーブルに分けて管理し、分散されたデータを一つにまとめるときにJOINを使うからである。&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;naming-convention名前の付け方&#34;&gt;naming convention(名前の付け方)&lt;/h4&gt;
&lt;p&gt;SQLは大文字で書く。e.g,SELECT, JOIN, INSERT,
データ自体は、小文字で書く。　user_id&lt;/p&gt;</description>
    </item>
    <item>
      <title>データベース実体の保存先の変更</title>
      <link>https://blog.ingenboy.com/post/db_on_hdd/</link>
      <pubDate>Fri, 12 Aug 2022 00:11:32 +0900</pubDate>
      <guid>https://blog.ingenboy.com/post/db_on_hdd/</guid>
      <description>データベースの実体の保存先の変更方法について。また、データベースを使い始めるときのログイン方法等</description>
    </item>
  </channel>
</rss>
