Database connection

TBSP on Google Cloud uses the PostgreSQL database to store transactions.

This section describes two ways you can access the PostgreSQL database running inside TBSP on Google Cloud:

  • using your Kubernetes cluster
  • using your local development machine.

Access your database with kubectl

Connect to the preconfigured database, specifying the <namespace>. As well, specify the node you want to connect to; in this case, it is node 0, indicated in postgres-client-0 and --host fullstack-tbsp-0-postgresql-tbsp-svc.

kubectl run \
postgres-client-0 --namespace default \
--image launcher.gcr.io/google/postgresql9 \
--rm --attach --restart=Never -it \
-- sh -c 'exec psql --host fullstack-tbsp-0-postgresql-tbsp-svc --dbname postgres --username postgres --password'

Enter the password when you see this prompt:

If you don't see a command prompt, try pressing enter.

Access your database from your local machine

Connect to your database from outside the cluster, specifying the <namespace>. As well, specify the node you want to connect to; in this case, it is node 0, indicated in "app=fullstack-tbsp-0-postgresql-tbsp,release=fullstack-tbsp-0.

kubectl port-forward $(kubectl get pod --selector="app=fullstack-tbsp-0-postgresql-tbsp,release=fullstack-tbsp-0,role=master" --output jsonpath='{.items[0].metadata.name}') 8080:5432

Once you have connected to the database, you are able to track and trace your transactions.

For more information, consult the PostgreSQL-Docker website.

Access your database with PostgreSQL Explorer

Install the PostgreSQL Explorer add-on for Visual Studio Code to track and trace your transactions and assets locally on your machine.

With an active TBSP on Google Cloud instance, open the PostgreSQL side tab in Visual Studio Code.

If you're working from a Docker container, you must download and install the Remote Development add-in from Visual Studio Code (ms-vscode-remote.vscode-remote-extensionpack). After installing the add-in, click the Remote Host icon on the bottom left hand corner and select Remote Connection: Attach to Running Container. Then select the container to which you'd like to attach VS Code.

Click on the "+" symbol to open a connection to your database.

Enter the hostname of the database (for example 127.0.0.1).

When prompted, enter the username and password for the PostgreSQL database (displayed when you ran the getPasswords script).

Enter the port number (for example 8080).

Follow the prompt. Where prompted, select Show All Databases.

Track and trace your transactions

Navigate to ng_rt_bc_private.

Then, navigate to Schemas>tmtx.

Right click and select Select Top 1000.

The table will display transaction-related information, including the transaction data and transaction metadata.

Track and trace your assets by transaction ID

In ng_rt_bc_private, navigate to Schemas>tmasset.

Right click and select Select Top 1000.

The table will display asset-related information, including the asset type, asset format, and asset data.