I'm trying to create a database in PostgreSQL using this command:
createdb -E UTF8 aws-inventories
There are no errors from that command. But when I go to list the dbs the new database isn't there:
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)
And if I try to change to that new database it tells me that it isn't there:
postgres-# \c aws-inventories
FATAL: database "aws-inventories" does not exist
Previous connection kept
I also tried this with the CREATE DATABASE command. And I get the same result:
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
Doing the same commands in PGAdmin4 I do get an error:
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
I'm on PostgreSQL 13. Why is Postgres refusing to create this database?
ERROR: syntax error at or near "createdb" LINE 1: createdb aws-inventories ^ SQL state: 42601 Character: 1postgres-# createdb -E UTF8 aws-inventories postgres-#. No errors! It's just that the DB does not exist when I try to list it or change to it!;, so it never actually executed anything. It is still waiting for you to finish typing the rest of your command. You can create databases from the psql prompt, but you have to do it withCREATE DATABASE....;, notcreatedb.psqlcommand prompt if I use the fullCREATE_DATABASEcommand with a;. However it didn't like the hyphen-and I had to name it with an underscore_: This didn't work:postgres=# CREATE DATABASE aws-inventories; ERROR: syntax error at or near "-" LINE 1: CREATE DATABASE aws-inventories;But this DID work:postgres=# CREATE DATABASE aws_inventories; CREATE DATABASE. Thanks for the help! Put that as the answer and I'll accept it. :)