PostgreSQL/データベース名の変更方法
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* PostgreSQLで作成したデータベース名を別名に変更する方法 ...
PostgreSQLでデータベース名を変更したい場合の手順を以下に...
#contents
#htmlinsertpcsp(db-top.html,db-sp.html)
* ALTER DATABASE [#t9fad138]
ALTER DATABASE コマンドを使用することによりデータベース名...
データベース名の変更コマンドは以下の構文になります。
ALTER DATABASE 変更前DB名 RENAME TO 変更後DB名;
+ PostgreSQLのデータベース一覧を表示しています。~
以下に表示されている、sakuradb tsubakidbに変更してみます。
$ psql -l -U postgres -h localhost
Password for user postgres:
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
sakuradb | sakura | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
(4 rows)
#br
+ 以下のコマンドを実行します。~
尚、ユーザは postgres を使用します。
++ ターミナルから直接実行する場合は -c オプションでコマン...
以下、実際に実行したときの出力です。~
tsubakidbになっているのが確認できます。
$ psql -U postgres -h localhost -c "ALTER DATABASE sakur...
Password for user postgres:
ALTER DATABASE
$ psql -l -U postgres -h localhost
Password for user postgres:
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
tsubakidb | sakura | UTF8 | Japanese_Japan.932 | ...
(4 rows)
#br
++ psqlで接続し、実行する場合~
psqlコマンドでPostgreSQLに接続する場合は、postgresに接続...
下記は、PostgreSQLに接続、変更前データベース一覧の表示(\l...
$ psql -U postgres -h localhost postgres
Password for user postgres:
psql (9.6.0, server 9.2.17)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
sakuradb | sakura | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
(4 rows)
postgres=# alter database sakuradb rename to tsubakidb;
ALTER DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
tsubakidb | sakura | UTF8 | Japanese_Japan.932 | ...
(4 rows)
postgres=# \q
$
以上、PostgreSQLでデータベース名を変更する手順でした。
#htmlinsertpcsp(db-btm.html,db-sp.html)
終了行:
#navi(../)
* PostgreSQLで作成したデータベース名を別名に変更する方法 ...
PostgreSQLでデータベース名を変更したい場合の手順を以下に...
#contents
#htmlinsertpcsp(db-top.html,db-sp.html)
* ALTER DATABASE [#t9fad138]
ALTER DATABASE コマンドを使用することによりデータベース名...
データベース名の変更コマンドは以下の構文になります。
ALTER DATABASE 変更前DB名 RENAME TO 変更後DB名;
+ PostgreSQLのデータベース一覧を表示しています。~
以下に表示されている、sakuradb tsubakidbに変更してみます。
$ psql -l -U postgres -h localhost
Password for user postgres:
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
sakuradb | sakura | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
(4 rows)
#br
+ 以下のコマンドを実行します。~
尚、ユーザは postgres を使用します。
++ ターミナルから直接実行する場合は -c オプションでコマン...
以下、実際に実行したときの出力です。~
tsubakidbになっているのが確認できます。
$ psql -U postgres -h localhost -c "ALTER DATABASE sakur...
Password for user postgres:
ALTER DATABASE
$ psql -l -U postgres -h localhost
Password for user postgres:
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
tsubakidb | sakura | UTF8 | Japanese_Japan.932 | ...
(4 rows)
#br
++ psqlで接続し、実行する場合~
psqlコマンドでPostgreSQLに接続する場合は、postgresに接続...
下記は、PostgreSQLに接続、変更前データベース一覧の表示(\l...
$ psql -U postgres -h localhost postgres
Password for user postgres:
psql (9.6.0, server 9.2.17)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
sakuradb | sakura | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
(4 rows)
postgres=# alter database sakuradb rename to tsubakidb;
ALTER DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | ...
-----------+----------+----------+--------------------+-...
postgres | postgres | UTF8 | Japanese_Japan.932 | ...
template0 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
template1 | postgres | UTF8 | Japanese_Japan.932 | ...
| | | | ...
tsubakidb | sakura | UTF8 | Japanese_Japan.932 | ...
(4 rows)
postgres=# \q
$
以上、PostgreSQLでデータベース名を変更する手順でした。
#htmlinsertpcsp(db-btm.html,db-sp.html)
ページ名: