Change the user to postgres :

su - postgres

Create User for Postgres (in the shell and NOT with psql)

$ createuser testuser

Create Database (same)

$ createdb testdb

Acces the postgres Shell

psql ( enter the password for postgressql)

Provide the privileges to the postgres user

$ alter user testuser with encrypted password 'qwerty';
$ grant all privileges on database testdb to testuser;
Answer from django-renjith on Stack Overflow
🌐
PostgreSQL
postgresql.org › docs › current › app-createdb.html
PostgreSQL: Documentation: 18: createdb
May 14, 2026 - createdb accepts the following command-line arguments: ... Specifies the name of the database to be created. The name must be unique among all PostgreSQL databases in this cluster.
Discussions

Running createdb from CLI - how does that work?
createdb/createuser and similar are virtually the same as: psql -d postgres -c "create database ..." They start connection to database, run sql command that does what is necessary, and exit. Does it help, or is something not clear? More on reddit.com
🌐 r/PostgreSQL
11
0
December 22, 2023
Can't create database in PostgreSQL using Git Bash in Windows 10
From what I understand you did: psql -U postgres within psql, you typed: createdb -U postgres test this will not work. Reason is simple: createdb is program and not sql query. Within psql, you'd have to type: create database test; and press enter. createdb, on the other hand should be called from your "shell" (git bash? however it's called). As for your "freeze", I suspect that it didn't freeze,I suspect that your terminal looked like this: postgres=# createdb -U postgres test postgres-# if that's the case (there is always a chance that it was something else), then the problem is simple - you didn't end your SQL query (createdb ...) with ';', so psql is waiting for you to finish your query. You can notice that in first line prompt ends with =#, but in second, it's -# - this - instead of = means that you are in query continuation - psql is patiently waiting for you to finish writing your query, before it will pass it to pg. Of course, once you will add ';' and press enter, you will get error, because, as i wrote earlier, createdb is not sql command. More on reddit.com
🌐 r/PostgreSQL
11
1
May 11, 2022
How do I simply navigate to a folder and create a database file there with BASH?
postgresql is service, usually only one in one server and it stores files into data folder. If you want really simple database then use SQLite. More on reddit.com
🌐 r/PostgreSQL
20
0
May 23, 2024
Just installed PostgreSQL, not able to follow step 1: $ createdb mydb
My question: where do I type this command? In a command line window. Also known as "shell" More on reddit.com
🌐 r/PostgreSQL
11
0
January 18, 2024
🌐
Micro Focus
microfocus.com › documentation › idol › IDOL_12_0 › MediaServer › Guides › html › English › Content › Getting_Started › Configure › _TRN_Set_up_PostgreSQL.htm
Set Up a PostgreSQL Database on Windows
This step enables you to use the ... file path in the Command Prompt to start psql. ... Enter your password when prompted. Run a CREATE DATABASE command to create a new database....
🌐
TutorialsPoint
tutorialspoint.com › postgresql › postgresql_create_database.htm
PostgreSQL - CREATE Database
Go to the bin directory and execute the following command to create a database. createdb -h localhost -p 5432 -U postgres testdb password ******
🌐
PostgreSQL
postgresql.org › docs › current › manage-ag-createdb.html
PostgreSQL: Documentation: 18: 22.2. Creating a Database
May 14, 2026 - In order to create a database, the PostgreSQL server must be up and running (see Section 18.3). Databases are created with the SQL command CREATE DATABASE:
🌐
DB Vis
dbvis.com › thetable › create-database-in-postgresql-a-complete-guide
CREATE DATABASE in PostgreSQL: A Complete Guide
April 30, 2025 - Let's learn everything you need to know about CREATE DATABASE in PostgreSQL, the statement you can employ to create new databases in your Postgres instance. ... Adding databases to a new database server is one of the most common tasks performed by DBAs or database users. While standard SQL does not provide a specific command for this, there are several options available, with the CREATE DATABASE command being the most common.
Find elsewhere
🌐
PostgreSQL
postgresql.org › docs › current › sql-createdatabase.html
PostgreSQL: Documentation: 18: CREATE DATABASE
May 14, 2026 - CREATE DATABASE CREATE DATABASE — create a new database Synopsis CREATE DATABASE name [ WITH ] [ OWNER [=] user_name …
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › create-database-postgresql
Create Database in PostgreSQL - GeeksforGeeks
June 17, 2026 - This command connects to the specified database. To create a database using the PostgreSQL psql shell, connect to the PostgreSQL server and execute the CREATE DATABASE command.
🌐
CommandPrompt Inc.
commandprompt.com › education › how-to-create-a-postgres-database-from-command-line
How to Create a Postgres Database From Command Line — CommandPrompt Inc.
August 17, 2023 - PostgreSQL supports various commands to create a database from the command line, including “createdb” and “CREATE DATABASE”. For instance, executing the “CREATE DATABASE” command from SQL Shell creates a new Postgres database, while ...
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › postgresql-create-database
PostgreSQL - Create Database - GeeksforGeeks
July 12, 2025 - Let's explore step-by-step how to create a PostgreSQL database in detail. The PSQL provides a command-line interface to create a database using the CREATE DATABASE SQL command.
🌐
PostgreSQL
postgresql.org › docs › current › tutorial-createdb.html
PostgreSQL: Documentation: 18: 1.3. Creating a Database
May 14, 2026 - A running PostgreSQL server can manage many databases. Typically, a separate database is used for each project or for each user. Possibly, your site administrator has already created a database for your use. In that case you can omit this step and skip ahead to the next section. To create a new database from the command line, in this example named mydb, you use the following command:
🌐
W3Schools
w3schools.com › postgresql › postgresql_getstarted.php
PostgreSQL - Get Started
If you have followed the steps from the Install PostgreSQL page, you now have a PostgreSQL database on you computer. There are several ways to connect to the database, we will look at two ways in this tutorial: ... SQL Shell (psql) is a terminal based program where you can write and execute SQL syntax in the command-line terminal.
Top answer
1 of 2
1

There are two different ways of creating a database in PostgreSQL. One is from the command line. The other is from the PostgreSQL console.

Command Line

In order to be able to create a database from the command line, you must first change to a user with rights to create a database. As you have shown with the \du command above, the user with those rights is postgres.

root@eric-desktop:/home/eric# su postgres
postgres@eric-desktop:/home/eric$ createdb prismatest2
postgres@eric-desktop:/home/eric$

As you can see, the creatdb command does not give any feedback. You need to confirm the creation by listing the current databases:

psql -U postgres -l
                                                 List of databases
    Name     |  Owner   | Encoding |   Collate   |    Ctype    | ICU Locale | Locale Provider |   Access privileges   

-------------+----------+----------+-------------+-------------+------------+-----------------+-----------------------

 postgres    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 

 prismatest  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 

 prismatest2 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 

PostgreSQL Console

Another possibility is to use the PostgreSQL console. To enter the console:

root@eric-desktop:/home/eric# sudo -u postgres psql psql (15.7 (Debian 15.7-0+deb12u1)) Type "help" for help.

postgres=# 
postgres=# CREATE DATABASE "prismatest3";
CREATE DATABASE
postgres=# 

To confirm the creation of the database, list the databases:

postgres=# \l

                                                 List of databases
    Name     |  Owner   | Encoding |   Collate   |    Ctype    | ICU Locale | Locale Provider |   Access privileges   

-------------+----------+----------+-------------+-------------+------------+-----------------+-----------------------

 postgres    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 

 prismatest  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 

 prismatest2 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 

 prismatest3 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 
2 of 2
3

Notice how the prompt has changed from the first line to the second:

        v
postgres=# createdb prismatest
postgres-# \l
        ^

psql is hinting that you are entering more lines of the same command.

Enter the semicolon (";") that terminates the create database statement.

postgres=# createdb prismatest ; 
🌐
Reddit
reddit.com › r/postgresql › running createdb from cli - how does that work?
r/PostgreSQL on Reddit: Running createdb from CLI - how does that work?
December 22, 2023 -

Hi all,

Pretty new to postgres and been playing with creating and dropping db's with my CLI.

My question is: Why/how is it that I can run a command like createdb or drop database from outside of the psql repl / just in my root directory (aka: ~)?

I get that there's a connection running, but is it also listening for those commands despite the CLI being in an unrelated area?

From a GUI-perspective, isn't that like calling a command for one application while just on your desktop / the application is minimized and not active? It feels like it's hitting Ctrl+B on my desktop and expecting my Word document to bold something.

TIA!

🌐
StrongDM
strongdm.com › blog › security
Create a Database in PostgreSQL (Step-By-Step Guide)
January 7, 2025 - If you frequently need to create databases, such as during continuous integration testing, you may need to integrate automation to expedite processes and save time. In such a case, you can leverage scripting via the CREATEDB command. Note: CREATEDB is a shell utility and may not be available in all environments unless the PostgreSQL client tools are installed.
🌐
Prisma
prisma.io › dataguide › postgresql › create-and-delete-databases-and-tables
Create and Delete Databases and Tables in PostgreSQL | PSQL CreateDB
To create a database from a dump (pg_dump), PostgreSQL provides the utility program pg_restore. This program recreates the database in the same state as it was at the time of the dump. Example syntax would look like the following: pg_restore [connection-option...][option...][filename] Which command line creates a database in PostgreSQL?
🌐
Red Gate Software
red-gate.com › home › creating a database and tables in postgresql: learning postgresql with grant
Creating a Database and Tables in PostgreSQL: Learning PostgreSQL with Grant | Simple Talk
April 16, 2024 - Well, that’s a default built into PostgreSQL so that tools always connect to a default database. The CREATE DATABASE command has a number of options, as you can see in the documentation. One of the more interesting to me relates right back to those template databases.
🌐
Liquid Web
liquidweb.com › home › creating and deleting a postgresql database on ubuntu 16.04
Creating & Deleting a PostgreSQL Database on Ubuntu 16.04 | Liquid Web
August 23, 2024 - With the psql command, you’ll be greeted by its current version and command prompt. ... Step 3: Create the Postgres Database. Let’s create our first database by typing in the command below.
🌐
Vinchin
vinchin.com › home › database tips › how to create a postgres database using command line and pgadmin?
How to Create a Postgres Database Using Command Line and pgAdmin? | Vinchin Backup
October 10, 2025 - This post describes what a Postgres database is and explains two methods to create one using the command line or pgAdmin, plus troubleshooting tips for common issues.
🌐
Cherry Servers
cherryservers.com › home › blog › postgresql › how to create a database in postgresql [create database, createdb]
How to create a database in PostgreSQL | Cherry Servers
November 7, 2025 - Let's start with the Postgres: CREATE DATABASE SQL statement. The conventional way of interacting with PostgreSQL is via the command line CREATE DATABASE query using the SQL query language, which is the standard in most Relational Database Management Systems (RDBMS).