Di jendela terminal, mulai psql dan tentukan localhost sebagai host server database.
Secara opsional, tentukan nomor port jika PGAdapter dikonfigurasi untuk memproses
pada port selain port PostgreSQL default (5432).
Secara opsional, tentukan satu atau beberapa perintah yang akan dikirim ke database atau driver
(misalnya, driver JDBC). Untuk setiap kemunculan opsi -c, Anda
dapat menentukan satu perintah atau sekumpulan perintah yang dipisahkan oleh
titik koma (;). Untuk informasi selengkapnya, lihat alat command line psql.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-17 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)."]]