In a terminal window, start psql and specify localhost as the database server host.
Optionally specify a port number if PGAdapter is configured to listen on
a 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, you
can specify a single command or a batch of commands separated by
semicolons (;). For more information, see psql command-line tool.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Connect psql to a PostgreSQL-dialect database\n\nThis page explains how to connect `psql` to a PostgreSQL-dialect database in Spanner.\n`psql` is the command-line front end to PostgreSQL.\n\n1. Ensure that PGAdapter is running on the same machine as the `psql` command.\n\n For more information, see [Start PGAdapter](/spanner/docs/pgadapter-start).\n2. In a terminal window, start `psql` and specify `localhost` as the database server host.\n\n - Optionally specify a port number if PGAdapter is configured to listen on a port other than the default PostgreSQL port (5432).\n - 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, you can specify a single command or a batch of commands separated by semicolons (;). For more information, see [psql command-line tool](/spanner/docs/psql-commands).\n\n `psql -h localhost [-p `\u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e`] [-c \"`\u003cvar translate=\"no\"\u003eCOMMAND\u003c/var\u003e`; ...\"] ...`\n3. Optional: Verify that `psql` successfully connected to a PostgreSQL-dialect database\n by submitting the following query:\n\n `SELECT 1::bigint;`\n\n This query is incompatible with GoogleSQL-dialect databases.\n\nWhat's next\n-----------\n\n- Learn about [PGAdapter](/spanner/docs/pgadapter).\n- See the supported `psql` commands in [psql command-line tool](/spanner/docs/psql-commands)."]]