Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.



Repository files navigation

Cloud Foundry CLI PSQL Plugin

Build Status License

cf-psql-plugin makes it easy to connect the psql command line client to any PSQL-compatible database used by Cloud Foundry apps. Use it to

  • inspect databases for debugging purposes
  • manually adjust schema or contents in development environments



$ cf psql -h
   psql - Connect to a PSQL database service

   Open a psql client to a database:
   cf psql <service-name> [psql args...]

Connecting to a database

Passing the name of a database service will open a PSQL client:

$ cf psql my-db
psql (10.3, server 9.6.3)
SSL connection (protocol: TLSv1.2, cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.


Removing service keys

The plugin creates a service key called 'cf-psql' for each service instance a user connects to. The keys are reused when available and never deleted. Keys need to be removed manually before their service instances can be removed:

$ cf delete-service -f somedb
Deleting service somedb in org DevProjects / space constantin as
Cannot delete service instance. Service keys, bindings, and shares must first be deleted.

Deleting the service failed. The CLI hints at service keys and app bindings that might still exist.

$ cf service-keys somedb
Getting keys for service instance somedb as


A key called 'cf-psql' is found for the service instance 'somedb', because we have used the plugin with 'somedb' earlier. After removing the key, the service instance can be deleted:

$ cf delete-service-key -f somedb cf-psql
Deleting key cf-psql for service instance somedb as

$ cf delete-service -f somedb
Deleting service somedb in org DevProjects / space constantin as

This behavior might change in the future as it's not optimal to leave a key around.

Installing and uninstalling

Pre steps

You need to have the postgres client in your path. On Mac simply run brew install postgresql.

Installing the plugin

The easiest way is to install from the repository:

$ cf install-plugin -r "CF-Community" psql-plugin

You can download a binary release or build yourself by running go build. Then, install the plugin with

$ cf install-plugin /path/to/cf-psql-plugin

The plugin can be uninstalled with:

$ cf uninstall-plugin psql


# download dependencies
go get -v ./...
go get
go get
go install

# run tests and build
ginkgo -r
go build


Obtaining credentials

cf-psql-plugin creates a service key called 'cf-psql' to obtain credentials. It no longer retrieves credentials from application environment variables, because with the introduction of CredHub, service brokers can decide to return a CredHub reference instead.

The service key is currently not deleted after closing the connection. It can be deleted by running:

cf delete-service-key service-instance-name cf-psql

A started application instance is still required in the current space for setting up an SSH tunnel. If you don't have an app running, try the following to start an nginx app:

TEMP_DIR=`mktemp -d`
pushd $TEMP_DIR
touch Staticfile
cf push static-app -m 128M --no-route
rm -r $TEMP_DIR


Cloud Foundry CLI PSQL Plugin







No packages published


  • Go 96.9%
  • Shell 3.1%