Where did my database appear in postgres?

postgres refuses to work. I am using 9.2 and newbie.

I am creating a database. I list, but he is not? No mistake! Where did he go? Was it ever created?

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 
+4
source share
2 answers

You have two errors:

  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 = #
+19
source

createdb is a shell command, not a postgres command, so it doesn’t show an error or success message.

To create a database from your terminal, you must do this.

 sudo -u postgres createdb databaseName 

To create a database from the postgres command, you need to run the following command one by one

 sudo -u postgres psql CREATE DATABASE testDB; 

If the database is successfully created, you will receive a message about the successful completion with the command "CREATE DATABASE"

enter image description here

To see a list of your database, write this command

 \l 
+1
source

Source: https://habr.com/ru/post/1500639/


All Articles