Using the a9s PostgreSQL for PCF

This topic describes how to use a9s PostgreSQL for Pivotal Cloud Foundry (PCF) after it has been successfully installed. For more information, see Installing and Configuring PostgreSQL for PCF.

Use a9s PostgreSQL for PCF with an App

To use the a9s PostgreSQL for PCF with with an app, follow the procedures in this section to create a service instance and bind the service instance to your app. For more information about managing service instances, see Managing Service Instances with the cf CLI.

View the Service

After the tile is installed, a9s-postgresql and its service plans appear in your PCF marketplace. Run cf marketplace to see the service listing:

$ cf marketplace
Getting services from marketplace in org test / space test as admin...
OK

service            plans                                                                                              description
a9s-postgresql     postgresql-single-small, postgresql-cluster-small, postgresql-single-big, postgresql-cluster-big   This is the anynines PostgreSQL 9.4 service.

See the next section for instructions on creating PostgreSQL service instances based on the plans listed in the cf marketplace output.

Create a Service Instance

You can provision a database with the cf create-service.

The following example creates a postgresql-single-small service that provisions a single VM PostgreSQL server. In contrast, the cluster service plans provision PostgreSQL clusters consisting of 3 virtual machines.

$ cf create-service a9s-postgresql postgresql-single-small my-postgresql-service

Depending on your infrastructure and service broker usage, it may take several minutes to create the service instance.

Check the creation status using cf services. This displays a list of all your service instances. To check the status of a specific service instance, run cf service NAME-OF-YOUR-SERVICE.

Bind the Service Instance to an App

After you create your database, run cf bind-service to bind the service to your app:

$ cf bind-service a9s-postgresql-app my-postgresql-service

Restage or Restart Your App

To enable your app to access the service instance, run cf restage or cf restart to restage or restart your app.

Obtain Service Instance Access Credentials

After you bind your service instance to your app, you can find the credentials of your PostgreSQL database in the environment variables of the app.

Run cf env APP-NAME to display environment variables. The credentials are listed under the VCAP_SERVICES key.

$ cf env a9s-postgresql-app
Getting env variables for app a9s-postgresql-app in org test / space test as admin...
OK

System-Provided:
{
 "VCAP_SERVICES": {
  "a9s-postgresql": [
   {
    "credentials": {
     "host": "EXAMPLE-HOST",
     "name": "d92e2bd",
     "password": "EXAMPLE-PASSWORD",
     "port": 5432,
     "uri": "EXAMPLE-URI",
     "username": "EXAMPLE-USERNAME"
    },
    "label": "a9s-postgresql",
    "name": "my-postgresql-service",
    "plan": "postgresql-cluster-small",
    "tags": [
     "sql",
     "database"
    ]
   }
  ]
 }
}
...

You can use the host, username, and password values with a PostgreSQL client to connect to the database.

Delete an a9s PostgreSQL for PCF Service Instance

Note: Before deleting a service instance, you must back up data stored in your database. This operation cannot be undone and all the data will be lost when the service is deleted.

Follow the instructions below to unbind your service instance from all apps and delete it.

List Available Services

Run cf services to list your available services.

$ cf services

Getting services in org test / space test as admin...
OK

name                    service          plan                      bound apps           last operation
my-postgresql-service   a9s-postgresql   postgresql-single-small   a9s-postgresql-app   create succeeded

This example shows that my-postgresql-service is bound to the a9s-postgresql-app app.

Unbind a Service Instance

Run cf unbind to unbind the service from your app.

$ cf unbind-service a9s-postgresql-app my-postgresql-service

Delete a Service Instance

Run cf delete-service to delete the service.

  $ cf delete-service my-postgresql-service

It may take up to several minutes to delete the service. Deleting a service deprovisions the corresponding infrastructure resources. Run the cf services command to check the deletion status.

Create a pull request or raise an issue on the source for this page in GitHub