0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【備忘録】KaliLinuxにPostgreSQLをインストール

Last updated at Posted at 2023-10-15

こんにちは、なつきです。
やられサイト自作への道 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インストール

  1. パッケージを更新する

    sudo apt update
    
  2. PostgreSQLがインストールされているか確認(デフォルトでKali Linuxにインストールされている)

    sudo apt show postgresql 
    
    # apt show postgresql
    Package: postgresql
    Version: 16+255
    Priority: optional
    ~
    
  3. PostgreSQLを起動する

    # sudo systemctl status postgresql
    
  4. 起動確認

    ● 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.
    
  5. 接続確認

    (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=#
    
  6. 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)
    
  7. ユーザの作成、データベースへの権限を付与

    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の本もハンズオン中心に読み直したいですね。

6. 参考資料

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?