「Rocky Linux 8.4」PostgreSQL 13のを利用する方法

2021年10月20日

OSバージョンの確認
[rockyuser@localhost ~]$ cat /etc/redhat-release
Rocky Linux release 8.4 (Green Obsidian)

1.テストDBに接続
[rockyuser@localhost ~]$ psql testdb
psql (13.3)
“help"でヘルプを表示します。

2.ユーザーロール一覧を表示

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
testdb=> \du
ロール一覧
ロール名 | 属性 | 所属グループ
-----------+--------------------------------------------------------------------------+--------------
postgres | スーパユーザ, ロール作成可, DB作成可, レプリケーション可, RLS のバイパス | {}
rockyuser |
testdb=> \du ロール一覧 ロール名 | 属性 | 所属グループ -----------+--------------------------------------------------------------------------+-------------- postgres | スーパユーザ, ロール作成可, DB作成可, レプリケーション可, RLS のバイパス | {} rockyuser |
testdb=> \du
                                             ロール一覧
 ロール名  |                                   属性                                   | 所属グループ
-----------+--------------------------------------------------------------------------+--------------
 postgres  | スーパユーザ, ロール作成可, DB作成可, レプリケーション可, RLS のバイパス | {}
 rockyuser |

3.データベース一覧を表示

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
testdb=> \l
データベース一覧
名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権限
-----------+-----------+------------------+-------------+-------------------+-----------------------
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | rockyuser | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
(4)
testdb=> \l データベース一覧 名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権限 -----------+-----------+------------------+-------------+-------------------+----------------------- postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres testdb | rockyuser | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | (4 行)
 testdb=> \l
                                          データベース一覧
   名前    |  所有者   | エンコーディング |  照合順序   | Ctype(変換演算子) |     アクセス権限
-----------+-----------+------------------+-------------+-------------------+-----------------------
 postgres  | postgres  | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
 template0 | postgres  | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
           |           |                  |             |                   | postgres=CTc/postgres
 template1 | postgres  | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
           |           |                  |             |                   | postgres=CTc/postgres
 testdb    | rockyuser | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
(4 行)

4.テーブルを作成
testdb=> create table user_tbl(userno int, username text);
CREATE TABLE

5.テーブル一覧を表示

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
testdb=> \dt
リレーション一覧
スキーマ | 名前 | タイプ | 所有者
----------+----------+----------+-----------
public | user_tbl | テーブル | rockyuser
(1)
testdb=> \dt リレーション一覧 スキーマ | 名前 | タイプ | 所有者 ----------+----------+----------+----------- public | user_tbl | テーブル | rockyuser (1 行)
testdb=> \dt
              リレーション一覧
 スキーマ |   名前   |  タイプ  |  所有者
----------+----------+----------+-----------
 public   | user_tbl | テーブル | rockyuser
(1 行)

データの検索確認

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
testdb=> select * from user_tbl;
userno | username
--------+----------
1001 | yamada
(1)
testdb=> select * from user_tbl; userno | username --------+---------- 1001 | yamada (1 行)
testdb=> select * from user_tbl;
 userno | username
--------+----------
   1001 | yamada
(1 行)

7.テーブルを削除
testdb=> drop table user_tbl;
DROP TABLE
testdb=> \dt
リレーションが見つかりませんでした。
testdb=> \q

8.テストデータベースを削除

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[rockyuser@localhost ~]$ dropdb testdb
[rockyuser@localhost ~]$ psql -l
データベース一覧
名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権限
-----------+----------+------------------+-------------+-------------------+-----------------------
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3)
[rockyuser@localhost ~]$ dropdb testdb [rockyuser@localhost ~]$ psql -l データベース一覧 名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権限 -----------+----------+------------------+-------------+-------------------+----------------------- postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 行)
[rockyuser@localhost ~]$ dropdb testdb
[rockyuser@localhost ~]$ psql -l
                                         データベース一覧
   名前    |  所有者  | エンコーディング |  照合順序   | Ctype(変換演算子) |     アクセス権限
-----------+----------+------------------+-------------+-------------------+-----------------------
 postgres  | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
 template0 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
           |          |                  |             |                   | postgres=CTc/postgres
 template1 | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       | =c/postgres          +
           |          |                  |             |                   | postgres=CTc/postgres
(3 行)

 

Rocky Linux 8

Posted by arkgame