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?

postgresqlその② データベースやテーブル作成など

Last updated at Posted at 2023-12-10

データベース作成から

以下の方法で実施するとデータベースが作成できた。

[postgres@docker163 ~]$  createdb testdb -U postgres
[postgres@docker163 ~]$
[postgres@docker163 ~]$
[postgres@docker163 ~]$ psql
psql (10.23)
"help" でヘルプを表示します。

postgres=# \d
リレーションが見つかりませんでした。
postgres=# \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    | postgres | UTF8             | ja_JP.UTF-8 | ja_JP.UTF-8       |
(4 行)

postgres=#

testデータベースにログインする

[postgres@docker163 ~]$ psql -d testdb
psql (10.23)
"help" でヘルプを表示します。

testdb=#

テーブルを作成してみました

testdb=# CREATE TABLE test(id char(4) not null,name text not null,food text not null,PRIMARY KEY(id));
CREATE TABLE
testdb=#
testdb=#
testdb=# \d
           リレーション一覧
 スキーマ | 名前 |    型    |  所有者
----------+------+----------+----------
 public   | test | テーブル | postgres
(1 行)

testdb=#

軽くSQLを実行 どうも最後に「;」が必要!!

testdb=# select * from test;
 id | name | food
----+------+------
(0 行)

testdb=#

showコマンドも実行できる


testdb=# show max_connections;
 max_connections
-----------------
 100
(1 行)

testdb=#

次回課題

ANALYZE
vacuum
backup
restore
などなど

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?