Connect psql to a PostgreSQL-dialect database Stay organized with collections Save and categorize content based on your preferences.
This page explains how to connectpsql to a PostgreSQL-dialect database in Spanner.psql is the command-line front end to PostgreSQL.
Ensure that PGAdapter is running on the same machine as the
psqlcommand.For more information, seeStart PGAdapter.
In a terminal window, start
psqland specifylocalhostas the database server host.- Optionally specify a port number if PGAdapter is configured to listen ona port other than the default PostgreSQL port (5432).
- Optionally specify one or more commands to send to the database or driver(for example, the JDBC driver). For each occurrence of the
-coption, youcan specify a single command or a batch of commands separated bysemicolons (;). For more information, seepsql command-line tool.
psql -h localhost [-pPORT] [-c "COMMAND; ..."] ...Optional: Verify that
psqlsuccessfully connected to a PostgreSQL-dialect databaseby submitting the following query:SELECT 1::bigint;This query is incompatible with GoogleSQL-dialect databases.
What's next
- Learn aboutPGAdapter.
- See the supported
psqlcommands inpsql command-line tool.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.