Connect psql to a PostgreSQL-dialect database

This page explains how to connectpsql to a PostgreSQL-dialect database in Spanner.psql is the command-line front end to PostgreSQL.

  1. Ensure that PGAdapter is running on the same machine as thepsql command.

    For more information, seeStart PGAdapter.

  2. In a terminal window, startpsql and specifylocalhost as 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-c option, 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; ..."] ...

  3. Optional: Verify thatpsql successfully connected to a PostgreSQL-dialect databaseby submitting the following query:

    SELECT 1::bigint;

    This query is incompatible with GoogleSQL-dialect databases.

What's next

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.