[A-00070]PostgreSQLで新規データベースを作成する
postgresqlで新規データベースを作成する方法を記載しておく。
基本形式は下記のとおり。
CREATE DATABASE <dabase_name> OWNER=<user_name>
文字コードや照合順序を指定する場合は下記のとおり。
CREATE DATABASE <database_name> OWNER=<user_name> ENCODING='<encoding>' LC_COLLATE='<collation>' LC_CTYPE='<collation>' TABLESPACE=<tbspace_name> CONNECTION LIMIT=<connection_limit>
;
今回は最も一般的な文字コードであるUTF8で作成します。またテーブルスペースやオーナーはデフォルトで存在するものを使用します。
dwh=# CREATE DATABASE dwh1 OWNER=postgres ENCODING='UTF8' LC_COLLATE='ja_JP.UTF-8' LC_CTYPE='ja_JP.UTF-8' TABLESPACE=DEFAULT CONNECTION LIMIT=-1
;
CREATE DATABASE
データベース一覧を確認します。
dwh=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
dwh | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | | libc |
dwh1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | | libc |
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | | libc |
template0 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
(5 rows)
コメントを残す