我正在尝试使用以下命令在 PostgreSQL 中创建一个数据库:
createdb -E UTF8 aws-inventories
该命令没有错误。但是当我列出数据库时,新数据库不存在:
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------------+----------+----------+----------------------------+----------------------------+-----------------------
analysis | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
animals | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
postgis_31_sample | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
postgres | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
template0 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
(6 rows)
如果我尝试更改为该新数据库,它会告诉我它不存在:
postgres-# \c aws-inventories
FATAL: database "aws-inventories" does not exist
Previous connection kept
CREATE DATABASE
我也用命令试过这个。我得到了同样的结果:
postgres=# CREATE DATABASE aws-inventories
postgres-# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------------+----------+----------+----------------------------+----------------------------+-----------------------
analysis | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
animals | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
postgis_31_sample | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
postgres | postgres | UTF8 | English_United States.1252 | English_United States.1252 |
template0 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +
| | | | | postgres=CTc/postgres
(6 rows)
postgres-# \c aws-inventories
FATAL: database "aws-inventories" does not exist
Previous connection kept
在 PGAdmin4 中执行相同的命令,我确实得到了一个错误:
createdb aws-inventories
ERROR: syntax error at or near "createdb"
LINE 1: createdb aws-inventories
^
SQL state: 42601
Character: 1**strong text**
CREATE DATABASE aws-inventories
ERROR: syntax error at or near "-"
LINE 1: CREATE DATABASE aws-inventories
^
SQL state: 42601
Character: 20
我在 PostgreSQL 13。为什么 Postgres 拒绝创建这个数据库?