Creating and Deleting a PostgreSQL Database

PostgreSQL (pronounced “post-gress-Q-L”) is a household name for open source relational database management systems. Its object-relational meaning that you’ll be able to use objects, classes in database schemas and the query language.  In this tutorial, we will be demonstrating some essentials like creating, listing and deleting a database.

If you have already installed PostgreSQL to your Ubuntu 16.04 server using our last tutorial, your next step is to create a database.  You’ll be accomplishing this task by using the default superuser, postgres, to log in.

Step 1: Login as the Postgres User

su - postgres

Step 2: Enter the PostgreSQL Environment

psql

With the psql command, you’ll be greeted by its current version and command prompt.

psql (9.5.14)
Type "help" for help.
postgres=#

Step 3: Creating the PostgreSQL Database

Let’s create our first database by typing in the command below.  Replace dbname with the database name of your choice.

CREATE DATABASE dbname;

 

Verify Creation of PostgreSQL Database

Using the following command allows us to view the databases in our PostgreSQL instance (you can ignore, delete or utilize the default databases: postgres, template0, template1)

postgres=# \list

 

Deleting a PostgreSQL Database

Once you’ve backed up your removing your PostgreSQL database is a cinch!  Its similar to creating a database but we will be using the drop command. In my command line example, the database name is “dbname”. By using the list command in the previous section, you’ll be able to view your databases’ names. Replace dbname with your database’s name in the command below.

DROP DATABASE dbname;

 

Series Navigation<< Install and Connect to PostgreSQL 10 on Ubuntu 16.04Listing and Switching Databases in PostgreSQL >>
Be Sociable, Share!

Author Bio

About the Author: Echo Diaz

Throughout Echo's four year stint as a technical support specialist, her passion for breaking down complex concepts has to lead to a career in professional writing. As a top tier support specialist, she adds a distinctive element to her written work that speaks to customer feedback and concerns.

Echo occasionally pops her head out from behind her computer to watch her dog energetically run around the yard and unabashedly shovels money into buying tickets to see her favorite musical artists.

Here's 75 % off, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support