こんにちは、なつきです。
やられサイト自作への道 KaliLinuxにPostgreSQLを導入編です!
といっても参考にしたこちらのサイトの通りにやっただけで、正直書く意味ある?という心境ですが、残しておきます...。
パパっと知りたい方は、以下の記事を読むと早いと思います。
how-to-install-postgresql-server-on-kali-linux
目次
1. はじめに
2. 実施内容
3. 前提条件
4. PostgreSQLインストール
5. 最後に
6. 参考資料
1. はじめに
やられサイト自作にあたり、DBを導入していこうと思います。
2. 実施内容
PostgreSQLインストール~DB/テーブル作成まで
3. 前提条件
TODO
4. PostgreSQLインストール
-
パッケージを更新する
sudo apt update
-
PostgreSQLがインストールされているか確認(デフォルトでKali Linuxにインストールされている)
sudo apt show postgresql # apt show postgresql Package: postgresql Version: 16+255 Priority: optional ~
-
PostgreSQLを起動する
# sudo systemctl status postgresql
-
起動確認
● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; disabled; preset: disabled) Active: active (exited) since Tue 2023-10-10 21:35:38 JST; 1s ago Process: 154163 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 154163 (code=exited, status=0/SUCCESS) CPU: 4ms Oct 10 21:35:38 kali-raspberry-pi systemd[1]: Starting postgresql.service - PostgreSQL RDBMS... Oct 10 21:35:38 kali-raspberry-pi systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.
-
接続確認
(root?kali-raspberry-pi)-[/] # su postgres postgres@kali-raspberry-pi:/$ postgres@kali-raspberry-pi:/$ psql psql (16.0 (Debian 16.0-2), server 15.4 (Debian 15.4-3)) Type "help" for help. postgres=# postgres=# \l List of databases Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges -----------+----------+----------+-----------------+---------+---------+------------+-----------+----------------------- postgres | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | template0 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres + | | | | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres + | | | | | | | | postgres=CTc/postgres (3 rows) postgres=#
-
DBの作成
postgres=# CREATE DATABASE zeizyakudb; CREATE DATABASE postgres=# postgres=# \l List of databases Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges ------------+----------+----------+-----------------+---------+---------+------------+-----------+----------------------- postgres | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | template0 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres + | | | | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres + | | | | | | | | postgres=CTc/postgres zeizyakudb | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | (4 rows)
-
ユーザの作成、データベースへの権限を付与
postgres=# CREATE USER zeizyaku WITH ENCRYPTED PASSWORD 'zeizyaku'; CREATE ROLE postgres=# GRANT ALL PRIVILEGES ON DATABASE zeizyakudb to zeizyaku; GRANT postgres=# \c zeizyakudb psql (16.0 (Debian 16.0-2), server 15.4 (Debian 15.4-3)) You are now connected to database "zeizyakudb" as user "postgres". zeizyakudb=#
5. 最後に
内容と関係ありませんが、テストDBやデータを作成する時にChatGPTを活用しました。
「user情報を管理するテーブルを作成して」
「userテーブルに挿入するテストデータを10件、insert文で教えて」
と聞くだけでパパっと回答がくる...。
便利になったなぁと感じるとともに、一抹の不安を感じるのは雑魚エンジニアの職業病でしょうか...。がんばろ
やられサイト用に作成しましたが、せっかくなので昔に買ったSQLアンチパターンやDBの本もハンズオン中心に読み直したいですね。