我创建了一个数据库。我列出了它不在那里?没有错误!它去了哪里?有没有创造过?
postgres-# creatdb test
postgres-# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 |
template0 | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_PH.UTF-8 | en_PH.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres-#
postgres@ubuntu:/home/ubuntu$ psql -h 127.0.0.1 -U postgres -d test
Password for user postgres:
psql: FATAL: database "test" does not exist
答案 0 :(得分:24)
您有两个错误:
createdb
是操作系统命令,它不是SQL命令。在psql中,您需要使用SQL语句,即:CREATE DATABASE
。有关详细信息,请参阅手册:http://www.postgresql.org/docs/current/static/sql-createdatabase.html
每个SQL语句都需要以;
终止。由于您没有这样做,您的声明未执行,因此您没有收到错误。有关详细信息,请参阅手册:http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html
postgres=# createdb test; ERROR: syntax error at or near "createdb" LINE 1: createdb test; ^ postgres=# create database test; CREATE DATABASE postgres=# \list List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+---------------------+---------------------+----------------------- postgres | postgres | UTF8 | German_Germany.1252 | German_Germany.1252 | template0 | postgres | UTF8 | German_Germany.1252 | German_Germany.1252 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | German_Germany.1252 | German_Germany.1252 | postgres=CTc/postgres+ | | | | | =c/postgres test | postgres | UTF8 | German_Germany.1252 | German_Germany.1252 | 10 rows) postgres=#
答案 1 :(得分:1)