How to Create a Postgres Database Using Command Line and pgAdmin?

PostgreSQL is a trusted open-source database system used worldwide. This guide shows you how to create a Postgres database step by step with both command line and pgAdmin methods. Learn key prerequisites and avoid common mistakes.

download-icon
Free Download
for VM, OS, DB, File, NAS, etc.
nathaniel-harper

Updated by Nathaniel Harper on 2025/10/10

Table of contents
  • What Is a Postgres Database?

  • Prerequisites for Creating a Postgres Database

  • Method 1: Creating a Postgres Database via Command Line

  • Method 2: Creating a Postgres Database Using pgAdmin

  • Protecting Your PostgreSQL Databases with Vinchin Backup & Recovery

  • Creating a Postgres Database FAQs

  • Conclusion

PostgreSQL—often called Postgres—is a trusted open-source database system used by organizations worldwide. It is known for its ACID compliance, which means it keeps your data safe even during crashes or power failures. This reliability makes it popular in enterprise environments where data integrity matters most. Whether you are launching a new application or managing an existing one, creating a Postgres database is an essential skill for any IT administrator. In this guide, we will explain what a Postgres database is, what you need before starting, and two proven ways to create one—using both the command line and pgAdmin graphical interface. We will also cover troubleshooting tips so you can avoid common pitfalls.

What Is a Postgres Database?

A Postgres database is an organized collection of data managed by the PostgreSQL server. Each database acts as its own container for tables, indexes, views, functions, roles, and other objects. You can host many databases on one server; each stays isolated from others so projects or users do not interfere with each other’s data. PostgreSQL supports advanced features such as transactions that guarantee all-or-nothing changes to your data; custom data types tailored to your needs; robust security controls; and support for multiple languages. These features make it suitable for everything from small web apps to large-scale analytics.

Prerequisites for Creating a Postgres Database

Before you create a Postgres database, check that several things are ready:

First, ensure PostgreSQL is installed on your system and running properly. On Linux systems you can verify this by running systemctl status postgresql. If you see “active (running),” your server is up.

Second, confirm that your user account has permission to create databases. You need either superuser rights or the CREATEDB privilege assigned to your role. To check this inside psql, type \du at the prompt; look under “Attributes” for Superuser or Create DB next to your username.

Third, make sure you have access to either the psql shell (for command-line work) or have installed pgAdmin if you prefer using a graphical tool.

Finally—choose a unique name for your new database that follows naming rules: start with a letter or underscore; use only letters, numbers or underscores unless enclosed in double quotes; avoid names already in use.

Method 1: Creating a Postgres Database via Command Line

The command line offers speed and flexibility when creating databases—a favorite choice among experienced admins working across Linux, macOS or Windows platforms.

Start by opening your terminal or command prompt window. Connect to PostgreSQL using the psql shell:

psql -U postgres

Replace postgres with your actual username if needed. After entering your password (if prompted), you should see something like postgres=#.

To create a basic new database with default settings:

CREATE DATABASE mydb;

Swap out mydb with whatever name you picked earlier.

If your chosen name includes special characters (like hyphens), wrap it in double quotes:

CREATE DATABASE "my-db";

Want more control? Specify details like owner account (who manages it), character encoding (such as UTF8), connection limit (how many users can connect at once), collation order (for sorting text), template source (to clone another DB’s structure/data):

CREATE DATABASE mydb
  WITH OWNER = myuser
       ENCODING = 'UTF8'
       LC_COLLATE = 'en_US.UTF-8'
       LC_CTYPE = 'en_US.UTF-8'
       CONNECTION LIMIT = 20
       TEMPLATE template0;

Here:

  • OWNER sets who owns/administers this DB,

  • ENCODING, LC_COLLATE, and LC_CTYPE define how text is stored/sorted,

  • CONNECTION LIMIT restricts simultaneous connections,

  • TEMPLATE template0 creates an empty DB without copying any existing objects—useful if you want full control over initial contents.

After running these commands successfully you'll see CREATE DATABASE.

To view all databases—including size/details—type:

\l+

To switch into your new database right away:

\c mydb

You can also create databases directly from outside psql using the system shell utility:

createdb mydb

This uses current OS user credentials unless otherwise specified (createdb -U username dbname). For more options about templates/encoding/ownership run createdb --help or consult official documentation.

Method 2: Creating a Postgres Database Using pgAdmin

Not everyone enjoys typing commands—pgAdmin provides an intuitive graphical interface available on Windows/macOS/Linux systems.

Begin by launching pgAdmin, then connect it to your PostgreSQL server if not already set up:

1. Click “Add New Server”

2. Enter connection details such as hostname/IP address (localhost if local), port (5432 by default), maintenance database (postgres) and authentication info.

3. Click “Save”.

Once connected:

1. In left sidebar (“Browser”), expand tree until you see the server’s name.

2. Expand again until reaching the bolded word “Databases”.

3. Right-click on “Databases”, select “Create > Database…”..

A dialog box appears:

1. Under “General”, enter desired name in field labeled “Database”.

2. Pick owner from dropdown list (“Owner”) if different than yourself.

3. Switch tabs—for example under “Definition”, adjust encoding/template/tablespace/collation/connection limit as needed—but defaults usually suffice unless supporting specific languages/locales.

4. When satisfied click bold blue button labeled “Save”.

Your new DB should appear instantly under Databases node—but sometimes pgAdmin does not refresh automatically! If missing:

1. Right-click on “Databases”

2. Select bolded option “Refresh”.

Clicking into your newly created DB lets you review properties/settings before adding tables/importing data/assigning permissions—all through easy point-and-click menus rather than SQL code.

Protecting Your PostgreSQL Databases with Vinchin Backup & Recovery

After establishing reliable operations for your PostgreSQL environment, implementing robust backup measures becomes essential for ongoing protection against threats like accidental deletion or ransomware attacks. Vinchin Backup & Recovery stands out as an enterprise-level solution supporting today’s mainstream databases—including Oracle, MySQL, SQL Server, MariaDB, PostgreSQL/PostgresPro, and MongoDB—with comprehensive coverage tailored specifically for mission-critical workloads like yours.

For PostgreSQL users especially concerned about business continuity and compliance requirements, Vinchin Backup & Recovery delivers key features such as incremental backup support for efficient storage usage over time; batch backup management across multiple instances; flexible GFS retention policies ensuring long-term archiving without manual intervention; scheduled backups that automate routine protection tasks; plus built-in ransomware defense mechanisms safeguarding every backup copy against unauthorized tampering—all designed to minimize risk while maximizing operational resilience.

Managing backups through Vinchin Backup & Recovery’s intuitive web console streamlines workflows into just four steps:

Step 1: Select the PostgreSQL database to back up

Select the PostgreSQL database to back up

Step 2: Choose backup storage

Choose backup storage

Step 3: Define backup strategy

Define backup strategy

Step 4: Submit job

Submit job

With global recognition among enterprise customers and top ratings across industry platforms, Vinchin Backup & Recovery offers peace of mind—and every feature is available free for 60 days so you can experience full functionality firsthand before committing further investment! Click below to get started today.

Creating a Postgres Database FAQs

Q1: How do I grant permission so another user can create their own databases?

A1: Connect as superuser in psql then run ALTER ROLE username CREATEDB; replacing "username" accordingly—the recipient gains ability immediately without needing full admin rights!

Q2: Can I copy structure/data from another existing DB during creation?

A2: Yes—add TEMPLATE option like so: CREATE DATABASE newdb WITH TEMPLATE sourcedb OWNER me ENCODING 'UTF8' CONNECTION LIMIT 10;

Conclusion

Creating a Postgres database takes just minutes whether using command line tools or pgAdmin's friendly interface—as long as prerequisites are met! Remember best practice steps like assigning proper permissions after creation—and consider Vinchin's backup solutions for ongoing protection of mission-critical workloads.

Share on:

Categories: Database Tips