0

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?

6
  • 1
    Did createdb not report any errors? Commented Apr 25, 2021 at 2:06
  • Nope! No errors on the CLI. But if I try this in PGAdmin4 I get the following:ERROR: syntax error at or near "createdb" LINE 1: createdb aws-inventories ^ SQL state: 42601 Character: 1 Commented Apr 25, 2021 at 2:12
  • Yet on the CLI nothing happens when I give the command: postgres-# 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! Commented Apr 25, 2021 at 2:13
  • 1
    createdb needs to run from the OS shell prompt, not from the psql prompt. It didn't report any errors because you didn't end the command with a ;, 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 with CREATE DATABASE....;, not createdb. Commented Apr 25, 2021 at 2:16
  • Ok thanks. I works from the psql command prompt if I use the full CREATE_DATABASE command 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. :) Commented Apr 25, 2021 at 2:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.