DbSchema Database Designer

DbSchema | How to Create a Database in PostgreSQL?

Publish on DbSchema Blog >>>

Install PostgreSQL

This article will guide you through the process of creating a database using psql and DbSchema. By the end, you’ll have a better understanding of how to manage your databases using these tools. The article is divided into the following sections:

Table of Contents

  1. Introduction
  2. Prerequisites
  3. Installing PostgreSQL and psql
  4. Creating a Database using psql
  5. Installing DbSchema
  6. Creating a Database using DbSchema
  7. Designing the Database Schema
  8. Generating SQL Scripts
  9. Executing SQL Scripts
  10. Conclusion

Introduction

In this article, we’ll explore both tools and show you how to create a database using psql, a Postgres command-line client, and DbSchema, a visual database designer.

Prerequisites

Before we begin, ensure that you have the following:

  • A computer with a compatible operating system (Windows, macOS, or Linux)
  • Administrative rights to install software on your computer
  • A stable internet connection

Installing PostgreSQL and psql

First, you’ll need to install PostgreSQL and its command-line interface, psql. Follow the instructions for your operating system below:

  1. Download the Windows / MacOS / Linux installer.
  2. Run the installer and follow the on-screen instructions.
  3. Ensure that the “Command Line Tools” option is selected during installation.

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.

psql --version
psql (PostgreSQL) 14.1

Creating a Database using psql

To create a new database using psql, follow these steps:

  1. Open a terminal or command prompt.

  2. Connect to your PostgreSQL server using the following command, replacing username with your PostgreSQL username:

    postgres=# psql -U username
    
  3. When prompted, enter your PostgreSQL password.

  4. To create a new database, run the following command, replacing your_database_name with your desired database name:

    postgres=# CREATE DATABASE your_database_name;
    
  5. Verify that the database was created by running:

    postgres=# \l
        List of Databases
    Name      | Owner
    ==================
    postgres  | postgres
    template0 | postgres 
    test      | postgres
    

    This will display a list of all databases in your PostgreSQL instance.

  6. Exit psql by running:

    postgres=# \q
    

Congratulations! You’ve just created a new database using psql.

Create Tables and Visually Manage PostgreSQL using DbSchema

DbSchema is a PostgreSQL client and visual designer. DbSchema has a free Community Edition, which can be downloaded here.

Create Table >

Connect to Postgres

Start the application and connect to the Postgres database. Right-click the table folder to create a table.


Add Columns >

Create a Database

Choose the database host, enter the username and password. Choose to create a database.


Conclusion

In this article, we covered the process of creating a PostgreSQL database using both psql and DbSchema. You should now have a better understanding of how to manage your databases using these powerful tools. Whether you prefer the command-line interface of psql or the visual design capabilities of DbSchema, both methods will allow you to create and manage your databases effectively.

As you continue to work with PostgreSQL, you may want to explore additional features of psql and DbSchema, such as creating tables, defining relationships, or managing your schema. The official PostgreSQL documentation and the DbSchema documentation are great resources for learning more about these tools and the many features they offer.

Visually Manage Databases using DbSchema

DbSchema is a databases client and visual designer. DbSchema has a free Community Edition, which can be downloaded here.
DbSchema main features include:

DbSchema Designer alt >

Interactive Diagrams

Design tables, column and foreign keys directly in diagrams, by double-clicking them. Changes will be saved to the design model and, if DbSchema is connected to the database also into the database. More.


Connection Dialog alt >

Simple Connection Dialog

Choose the database location, the user and password, and simply get connected. Choose 'Edit Manually' into the JDBC URL combo to enter a custom URL. More.


Relational Data Explorer alt >

Relational Data Explorer

Explore data from multiple tables simultaneously, using foreign keys or virtual foreign keys. Double-click cells to edit the data. More.


Query Builder alt >

Query Builder

Create SQL Queries featuring JOINS, GROUP BY, ORDER BY just using the mouse. More.


SQL Query Editor alt >

SQL Query Editor

Edit and execute SQL Queries. The editor is autocompletion-enabled. More.


Schema Synchronization alt >

Design Schema in Team & Schema Deployment

DbSchema is using the design model, a copy of the schema structure, independent of the database.
The design model can be saved to file and shared in a team.
Connecting to another database you may compare the design model with the database, commit the differences or merge them in the design model. More.


Dark Theme alt >

Dark Theme

Configurable styles & dark theme. More.


Many features are available in the free Community edition.
The Pro edition adds capabilities to save the design to the model file, design schema in team and deploy the schema on multiple databases.


DbSchema can be downloaded for free. No registration is required.