Skip to main content

Google AlloyDB

This guide explains how to connect AlloyDB to a PolyScale cache. AlloyDB is a fully managed Postgres-compatible database service running within Google Cloud that can be connected to PolyScale. Because AlloyDB is not directly accessible to the public internet, you must use PolyScale Self Hosted in conjunction with AlloyDB. Read on for details of working with AlloyDB and PolyScale.

tip

General instructions for installing PolyScale can be found here. Be sure to install PolyScale on the same VPC within Google Cloud that as your AlloyDB instance. You can read more about VPC networks on Google Cloud here.

Step 1: Create your PolyScale Cache

1.1 Retrieve your AlloyDB Host

  • In your Google Cloud console go to the Clusters page.
  • Click on a cluster in the Resource Name column.
  • In the Overview page that opens, go to the Instances in your cluster and view the details about your instance.
  • Get the Private IP address of the AlloyDB instance you want to connect to

1.2 Configure your PolyScale Cache

  • In your PolyScale account, click on the New Cache button
  • Give the cache a Name
  • Select Google AlloyDB for the Type
  • Enter the Host from Step 1.1 above
  • Enter 5432 for the Port
  • Click Create
Create Cache

Your cache is now created.

tip

Cache creation for use with the PCE is identical to the process for connecting a cache using the PolyScale Serverless. However, because AlloyDB is not publicly accessible, at present the network test that runs when a cache is created will fail. This does not mean you have a configuration problem; it just means that your database is not publicly accessible. To use the PCE, ensure that your database host specified in your cache configuration is accessible from the Docker machine running the PCE.

Step 2: Connect to your PolyScale Cache

Using your PolyScale cache is simple -- instead of connecting to your AlloyDB database directly, you'll replace your original connection string with the PolyScale connection string in your application.

The PolyScale user interface indicates that psedge.global is the hostname to use to connect to PolyScale. However, to connect using the PCE, use the host of your Docker container running the PCE. (If the PCE is running on an instance that has a public IP address, then your cache can be reached from anywhere. If your PCE only has a private IP address, then your cache can only be reached from the same VPC in which your AlloyDB and cache sit.) In addition, by default, the PCE runs the Postgres protocol (on which AlloyDB runs) on port 9010. If you wish to access your cache on 5432, you can pass the -p 5432:9010 flag when starting the PCE.

For example, if your original connection string was: postgres://postgres:zqGHFAbPLvVCKw@10.0.112.2:5432/employees

Your PolyScale connection string would be: postgres://postgres:zqGHFAbPLvVCKw@<PCE_IP_ADDRESS>:9010/employees?application_name=a645cb93-fa53-46b2-9d6c-227e357e5bfb

That's it.