Forum Discussion

oschuhm's avatar
oschuhm
Occasional Visitor
4 months ago

ReadyAPI and Postgres in Google Cloud SQL

Hi,

unfortunately I was not able to find a related article to this topic.

Can anyone help me which .jars are required and how the jdbc connection string will look like if I want to connect to a Postgres DB in Google Cloud SQL environment?

BR, Oliver

2 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    oschuhm 

    There is should be any difference if the data base is in either local machine or on the google cloud as long as the respective driver files are available under READYAPI_HOME/lib.

    Here is the documentation on installing drivers

    Depending on the Java version, you may get them from Postgresql.

    Please see here

  • Stephen378Baker's avatar
    Stephen378Baker
    Occasional Visitor

    Certainly, 

    Connecting to a PostgreSQL database in Google Cloud SQL involves a few steps. Let’s break it down:

    Required JARs:
    To connect to a PostgreSQL database, you’ll need the appropriate JDBC driver JAR for PostgreSQL. You can download it from the official PostgreSQL website or use Maven/Gradle to manage dependencies.
    The most common JDBC driver for PostgreSQL is postgresql-<version>.jar.
    JDBC Connection String:
    The JDBC connection string for connecting to a PostgreSQL database in Google Cloud SQL depends on whether you want to use a public IP or a private IP.
    Here are the formats for both scenarios:
    Public IP:

    jdbc:postgresql://<PUBLIC_IP>:<PORT>/<DATABASE_NAME>?user=<USERNAME>&password=<PASSWORD>&sslmode=require


    Replace <PUBLIC_IP>, <PORT>, <DATABASE_NAME>, <USERNAME>, and <PASSWORD> with your actual values.
    Private IP (using Cloud SQL Auth Proxy):

    jdbc:postgresql:///<DATABASE_NAME>?host=/cloudsql/<PROJECT_ID>:<REGION>:<INSTANCE_ID>&user=<USERNAME>&password=<PASSWORD>&sslmode=require


    Replace <DATABASE_NAME>, <PROJECT_ID>, <REGION>, <INSTANCE_ID>, <USERNAME>, and <PASSWORD>.
    Example:
    If you’re using a public IP, your connection string might look like:

    jdbc:postgresql://35.123.45.67:5432/mydb?user=myuser&password=mypassword&sslmode=require

    For a private IP with Cloud SQL Auth Proxy:

    jdbc:postgresql:///mydb?host=/cloudsql/my-project:us-central1:my-instance&user=myuser&password=mypassword&sslmode=require

    Remember to replace placeholders with your actual values. Good luck with your PostgreSQL connection in Google Cloud SQL!