This page explains how to connect the PostgreSQL psycopg3 driver to a PostgreSQL-dialect database
in Cloud Spanner.
psycopg3 is a Python driver for PostgreSQL.
Ensure that PGAdapter is running on the same machine as the application that is connecting using the PostgreSQL psycopg3 driver.
For more information, see Start PGAdapter.
5432as the database server host and port in the
- Optional: Specify a different port number if PGAdapter is configured to listen on a port other than the default PostgreSQL port (5432).
- Optional: Specify a different host name if PGAdapter is running on a different host than the local machine.
connection = psycopg.connect(database="DATABASE_ID", host="localhost", port=5432) cursor = connection.cursor() cursor.execute('select \'Hello World\'') for row in cursor: print(row) cursor.close() connection.close()
- Learn more about PGAdapter.
- For more information about PostgreSQL psycopg3 driver connection options, see psycopg3 Connection Options in the PGAdapter GitHub repository.