PostgreSQL is a popular open source database system with a rich feature set. It is used by a variety of organizations for a variety of purposes.
One way to access PostgreSQL is through a cloud-based service, such as DigitalOcean.
This article will show you how to connect to PostgreSQL using DigitalOcean.
This guide assumes that you have a valid DigitalOcean account and have installed the DigitalOcean client software. If you do not have these prerequisite, please see the instructions on how to install the DigitalOcean client software.
Next, you will need to set up a PostgreSQL server. If you are new to PostgreSQL, we recommend reading our guide on installing and setting up PostgreSQL.
Connecting to PostgreSQL
To connect to PostgreSQL using DigitalOcean, follow these steps:
Sign in to your DigitalOcean account. Click on the droplets icon in the top-right corner of the screen.
Click on the Create Droplet button. In the Create Droplet form, enter the following information:
- Droplet Name: postgres
- Server Type: PostgreSQL
- Size: 1 GB
Select the region in which you want to create your droplet. Click on the Create Droplet button.
Your newly created PostgreSQL droplet will be created and will be ready for use. To launch it, enter the following command in a terminal window:
- sudo launchpad start postgres
You should now be able to connect to your PostgreSQL droplet using the psql command. To do this, enter the following command in a terminal window:
You should see the following output:
Welcome to the PostgreSQL server (version 9.5.12). Type “help” for help.
To connect to a specific database, you can use the -D option. For example, to connect to the postgres database, you can enter the following command:
- psql -D postgres
You can also use the psql command to list the databases that are available on the droplet. To do this, enter the following command:
- psql -l
- postgres | 1GB | Linux 3.10.0-229.el7.x86_64 | #1 SMP Wed Aug 29 01:30:41 EDT 2017.
In this article, you have learned how to connect to PostgreSQL using DigitalOcean.