How to Perform the PostgreSQL create database in an ObjectRocket Instance

Have a Database Problem? Speak with an Expert for Free
Get Started >>

Introduction

PostgreSQL is very popular due to its many features, fast performance and easy scalability. The PostgreSQL database server is used to access a database over a network or on a local device and a Postgres instance starts the server process that facilitates the connection. Typically, one Postgres instance manages the data of one database cluster, or a collection of databases stored at a common location. This tutorial will explain how to use PostgreSQL to create a database in an ObjectRocket instance.

Prerequisites

  • Create an account and sign in to the ObjectRocket web page to create a PostgreSQL instance that supports the current version of 12.2.

  • A PostgreSQL database cluster must be properly installed and configured on the local device. Execute the command psql -V to verify the current version number of the Postgres interactive shell.

Create a User in PostgreSQL Instance of ObjectRocket

After an instance of PostgreSQL has been created in ObjectRocket, create a unique user ID to use for the credentials required to set and access the psql on the local device.

First, click on the PostgreSQL instance and then click on the VIEW MORE DETAILS button.

Next, look for the “USERS” tab and click the Add User button on the right side of the PostgreSQL instance as shown in the following image:

Screenshot of the add user button in PostgreSQL instance

Be certain to also check the admin button before proceeding.

Enter Into the PostgreSQL Instance in ObjectRocket

In order to access the PostgreSQL instance in ObjectRocket, copy the connection URL of the instance.

Go to the CONNECT tab and copy the included credentials.

NOTE: The username and password of the credentials must be applied in the psql shell in the terminal to access the PostgreSQL instance.

Accessing the PostgreSQL Interactive Shell

Now, before creating a database in the PostgreSQL instance, navigate into the psql using the command line interface and entering the following command syntax:

1
sudo su - PostgreSQL

Next, as shown here, use the psql along with the credentials of the PostgreSQL instance to connect and navigate to the instance:

1
psql -U username -h localhost_name -p 4123

NOTE: The localhost name should be ingress.hkybrhnz.launchpad.objectrocket.cloud, included in the credentials of the PostgreSQL instance.

Now the system will prompt for the user password. Enter the password that was created earlier for the user in PostgreSQL instance and then press ENTER.

Using the PostgreSQL to Create a Database in ObjectRocket Instance

Database are critical for storing and organizing a collection of data, allowing data to easily be accessed, controlled and updatedas needed.

Execute the following command to create a database in PostgreSQL:

1
CREATE DATABASE database_name;

Note that the database can be named whatever the user likes.

For example, for illustrative purposes, the database here is named “sample_db;”:

1
2
CREATE DATABASE sample_db;
CREATE DATABASE

Using the Createdb Command in PostgreSQL Instance

A database can also be created that can run directly in the command line interface while accessing the PostgreSQL instance. The following createdb command syntax is just another example of how to easily create a database:

1
createdb -h localhost_name -p 4123 -U username database_name

The system will then prompt for a password.

Now execute the following command \l to list the newly created database, as well as all of the databases, in the PostgreSQL instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges  
-----------+----------+----------+-------------+-------------+-----------------------
 demo      | PostgreSQL | UTF8     | en_PH.UTF-8 | en_PH.UTF-8 |
 docker    | docker   | UTF8     | en_PH.UTF-8 | en_PH.UTF-8 |
 node      | PostgreSQL | UTF8     | en_PH.UTF-8 | en_PH.UTF-8 |
 PostgreSQL  | PostgreSQL | UTF8     | en_PH.UTF-8 | en_PH.UTF-8 |
 sample_db | PostgreSQL | UTF8     | en_PH.UTF-8 | en_PH.UTF-8 |
 template0 | PostgreSQL | UTF8     | en_PH.UTF-8 | en_PH.UTF-8 | =c/PostgreSQL          +
           |          |          |             |             | PostgreSQL=CTc/PostgreSQL
 template1 | PostgreSQL | UTF8     | en_PH.UTF-8 | en_PH.UTF-8 | =c/PostgreSQL          +
           |          |          |             |             | PostgreSQL=CTc/PostgreSQL
(7 rows)

Conclusion

This tutorial explained how to use PostgreSQL to create a database in an ObjectRocket instance. The tutorial covered how to set up an instance of PostgreSQL in ObjectRocket and create a unique user ID. The article then explained how to enter into the PostgreSQL instance in ObjectRocket, access the PostgreSQL interactive shell, use PostgreSQL to create a database in the ObjectRocket instance and how to execute the createdb command in the PostgreSQL instance. Remember that an account must be create on the ObjectRocket web page that supports the current Postgres version of 12.2 to use PostgreSQL to create a database in an ObjectRocket instance.

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.