2017-03-25 21 views
1

私はコマンドラインインターフェイスを使ってLinux上でpostgresqlを学びたいと思っています。Linuxでpostgresqlデータベースを削除するには

いくつかのチュートリアル(これまで私が学んだすべてを忘れてしまった後)に続いて、いくつかのデータベースを戻しながら追加しました。

これらのデータベースを削除します。

私は、postgresqlのコマンドラインインターフェイスであるpsqlを使用してこれを行うべきであると仮定しました。

私は次のコマンドライン出力で試したことが分かり、それがどれも成功していないことがわかります。

psql (9.5.6) 
Type "help" for help. 

postgres=# \list 
            List of databases 
    Name | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+----------+----------+-------------+-------------+----------------------- 
postgres | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | 
template0 | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres   + 
      |   |   |    |    | postgres=CTc/postgres 
template1 | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres   + 
      |   |   |    |    | postgres=CTc/postgres 
testdb | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | 
(4 rows) 

postgres=# dropdb template1 
postgres-# \list 
            List of databases 
    Name | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+----------+----------+-------------+-------------+----------------------- 
postgres | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | 
template0 | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres   + 
      |   |   |    |    | postgres=CTc/postgres 
template1 | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres   + 
      |   |   |    |    | postgres=CTc/postgres 
testdb | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | 
(4 rows) 

postgres-# DROP DATABASE template1 
postgres-# \list 
            List of databases 
    Name | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+----------+----------+-------------+-------------+----------------------- 
postgres | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | 
template0 | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres   + 
      |   |   |    |    | postgres=CTc/postgres 
template1 | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | =c/postgres   + 
      |   |   |    |    | postgres=CTc/postgres 
testdb | postgres | UTF8  | en_CA.UTF-8 | en_CA.UTF-8 | 
(4 rows) 
+0

empty_database psqlを[について読んで、テンプレートのデータベースを削除しないでくださいそれらのファイルを削除します。](https://www.postgresql.org/docs/current/static/manage-ag-templatedbs.html) – klin

答えて

2

はい、

DROP DATABASE template1;

とバックアップにデータベースを忘れてはいけない:

バックアップへ:pg_dumpのname_of_database> name_of_backup_file.bak

復元するには:< backup_file.bak

1

を確認して、セミコロンを使用してSQLコマンドを終了(;) が最後にセミコロンで

DROP DATABASE template1; 

コマンドを発行してください。

+0

と大文字のDROP DATABASEも(私の間違い) – perlyking

関連する問題