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 › 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 …
🌐
PostgreSQL
postgresql.org › docs › current › manage-ag-createdb.html
PostgreSQL: Documentation: 18: 22.2. Creating a Database
May 14, 2026 - Since you need to be connected to the database server in order to execute the CREATE DATABASE command, the question remains how the first database at any given site can be created. The first database is always created by the initdb command when the data storage area is initialized.
🌐
Neon
neon.com › postgresql › administration › create-database
PostgreSQL CREATE DATABASE Statement
In PostgreSQL, a database is a collection of related data, which serves as a container for tables, indexes, views, and other database objects. To create a new database, you use the CREATE DATABASE statement.
🌐
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....
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 ; 
Find elsewhere
🌐
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.
🌐
DbSchema
dbschema.com › blog › postgresql › postgresql create database guide with psql and dbschema | dbschema
PostgreSQL CREATE DATABASE Guide with psql and DbSchema | DbSchema
May 11, 2023 - After installation, open a terminal or command prompt and verify that psql is accessible by running psql --version. You should see the version number of your installed PostgreSQL instance. ... Open a terminal or command prompt. Connect to your PostgreSQL server using the following command, replacing username with your PostgreSQL username: ... When prompted, enter your PostgreSQL password. To create a new database, run the following command, replacing your_database_name with your desired database name:
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › create-database-postgresql
Create Database in PostgreSQL - GeeksforGeeks
June 17, 2026 - To create a database using the PostgreSQL psql shell, connect to the PostgreSQL server and execute the CREATE DATABASE command.
🌐
EnterpriseDB
enterprisedb.com › postgres-tutorials › how-create-postgresql-database-and-users-using-psql-and-pgadmin
How to create a PostgreSQL database and users using psql and pgAdmin | EDB
If you are creating databases with similar structures, then one of the most useful additions to the CREATE DATABASE argument is the template. You can modify the default database template, template1, in the default installation, and then while trying to replicate it within the same instance you can use the following at the psql prompt::
🌐
GeeksforGeeks
geeksforgeeks.org › postgresql › postgresql-create-database
PostgreSQL - Create Database - GeeksforGeeks
July 12, 2025 - Creating a database in PostgreSQL can be done using the CREATE DATABASE SQL statement in the psql shell or via the createdb command-line utility. Additionally, for users who prefer a graphical interface, pgAdmin offers a convenient way to manage ...
🌐
DataCamp
datacamp.com › doc › postgresql › create-database
PostgreSQL CREATE DATABASE
In PostgreSQL, a database is a collection of structured data stored and managed by a database management system (DBMS) in a computer, allowing for efficient data retrieval and modification. The `CREATE DATABASE` command is used to create a new database within the PostgreSQL system.
🌐
Medium
medium.com › analytics-vidhya › how-to-create-a-postgres-database-394b362abfbe
How to create a Postgres database | by AlexV | Analytics Vidhya | Medium
January 3, 2021 - CREATE DATABASE clothes_shop; \c clothes_shop CREATE TYPE colours AS ENUM ('blue', 'green', 'red', 'yellow'); CREATE TYPE sexes AS ENUM ('male', 'female'); CREATE TYPE sizes AS ENUM ('small', 'medium', 'large'); CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE clothes_stock ( id UUID NOT NULL DEFAULT uuid_generate_v4(), clothes_name TEXT NOT NULL, price NUMERIC NOT NULL, cost NUMERIC NOT NULL, colour colours NOT NULL, sex sexes NOT NULL, clothes_size sizes NOT NULL, stock_level int NOT NULL ); INSERT INTO clothes_stock (clothes_name, price, cost, colour, sex, clothes_size, stock_level) VALUES ('Red T-shirt', 1.99, 0.99, 'red', 'male', 'small', 100);
🌐
Reddit
reddit.com › r/postgresql › create / add new database to (already) running postgres. best practices
r/PostgreSQL on Reddit: Create / Add new database to (already) running Postgres. Best practices
June 21, 2025 - PS * init scripts "are only run if you start the container with a data directory that is empty" (c) https://hub.docker.com/_/postgres * POSTGRES_DB env is already defined (to create another unrelated database) ... Create Database. Probably should have already done this...the initial database you setup when creating a cluster should be limited to administrative work.
🌐
W3Schools
w3schools.com › postgresql › postgresql_create_table.php
PostgreSQL - Create Table
PostgreSQL CREATE TABLE PostgreSQL INSERT INTO PostgreSQL Fetch Data PostgreSQL ADD COLUMN PostgreSQL UPDATE PostgreSQL ALTER COLUMN PostgreSQL DROP COLUMN PostgreSQL DELETE PostgreSQL DROP TABLE Create Demo Database
🌐
DevGenius
blog.devgenius.io › postgresql-004-creating-a-database-in-postgresql-the-fun-begins-cfcc83b80e93
PostgreSQL 05: Creating a Database in PostgreSQL — The Fun Begins!! 🎉 | by M Business Solutions | Dev Genius
December 4, 2024 - Think of a database as a giant treasure chest, waiting to hold all your valuable data — neatly organized and secure. In this post, I’ll show you how to create a database in both pgAdmin and the SQL command line (because we’re all about options).
🌐
SnapShooter
snapshooter.com › learn › postgresql › create-manage-postgresql-database
How to Create and Manage PostgreSQL Databases - SnapShooter Tutorials
April 30, 2021 - sudo -u postgres psql · Once login, ... "/var/run/postgresql" at port "5432". Next, create a new database named userdb with the following command: postgres=# CREATE DATABASE userdb; To list all databases, run the following command: postgres=# \list ·...
🌐
Fly.io
fly.io › docs › about › pricing
Fly.io Resource Pricing · Fly Docs
Fly Postgres is a PostgreSQL database that you create and then manage yourself.
🌐
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”.
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham