To connect to your AlloyDB for PostgreSQL instance from the command line, you can
install the psql client tool on macOS, Linux, or Windows. The psql
command-line tool is a terminal-based frontend to
PostgreSQL that is required by the
gcloud beta alloydb connect
command and is also used for direct database connections.
macOS
To install psql on macOS, we recommend using Homebrew:
Install the
postgresqlpackage:brew install postgresqlAdd
psqlto yourPATHby following the instructions provided in the terminal output after the installation completes. For example:echo 'export PATH="/opt/homebrew/opt/postgresql@18/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
Linux (Debian or Ubuntu)
Use your distribution's package manager to install the PostgreSQL client:
sudo apt-get update
sudo apt-get install postgresql-client
For other distributions, see the official PostgreSQL download page.
Windows
To install psql on Windows, you can use the interactive installer.
Installer
- Download the PostgreSQL Interactive Installer for Windows from the PostgreSQL downloads page.
- Run the installer. When prompted to select components, you can install only Command Line Tools.
- Add the
bindirectory of your PostgreSQL installation (for example,C:\Program Files\PostgreSQL\18\bin) to your systemPATHenvironment variable.
Verify the installation
After installation, verify that psql is in your PATH and is working
correctly:
psql --version
If installed correctly, the output shows the version of the psql client
tool.