Guide
How to install psql on a Mac (without running a PostgreSQL server)
To get psql on macOS without a PostgreSQL server, install Homebrew's client-only libpq package with brew install libpq, then add it to your PATH, because Homebrew does not link it: echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc on Apple silicon, or /usr/local/opt/libpq/bin on Intel. Open a new terminal and check with psql --version.
Option 1: Homebrew libpq (client only, no server)
libpq is PostgreSQL's client library, and Homebrew's formula of the same name ships the client programs with it: psql, pg_dump, pg_restore, pg_isready and friends, but not the postgres server. As of November 2026 it installs version 19.0.
brew install libpqHomebrew marks libpq as keg-only because it conflicts with the full PostgreSQL formulae, so it does not put psql on your PATH. Add its bin folder yourself. On Apple silicon Homebrew lives in /opt/homebrew:
echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcOn an Intel Mac the prefix is /usr/local:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcNot sure which you have? brew --prefix prints it. If your shell is bash rather than zsh (the macOS default since Catalina), write the line to ~/.bash_profile instead.
The alternative is to let Homebrew symlink the tools into its main bin folder, which is already on your PATH:
brew link --force libpqThat works, but the links will clash if you later install a full postgresql@NN formula and link it, so the PATH line is the tidier choice.
Intel note: since September 2026 Homebrew treats Intel Macs as Tier 3 and no longer builds new bottles for them, so brew install libpq may compile from source there. Postgres.app (below) is a quicker route on an Intel Mac.
Option 2: the full postgresql@19 formula
If you also want a local server for development, install the full formula. Homebrew offers postgresql@14 through postgresql@19; brew install postgresql is an alias for the newest, postgresql@19. (postgresql@14 is deprecated and due to be disabled on 30 November 2026.)
brew install postgresql@19
echo 'export PATH="/opt/homebrew/opt/postgresql@19/bin:$PATH"' >> ~/.zshrcVersioned formulae are keg-only too, hence the PATH line (use /usr/local/opt/… on Intel). The install creates a database cluster in $(brew --prefix)/var/postgresql@19 but does not start a server; that only happens if you run brew services start postgresql@19. If all you need is psql, Option 1 is lighter.
Option 3: Postgres.app's command line tools
Postgres.app is a menu bar app that runs a local PostgreSQL server, and it bundles psql, pg_dump and the other tools. Version 3.0 ships PostgreSQL 19.0 (a larger download includes 14 to 19), runs on macOS 11 or later and is a universal build for Apple silicon and Intel. Move it to Applications, open it once, then put the tools on your PATH with the command from its documentation:
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresappClose the terminal window and open a new one. Versions/latest follows whichever version is newest in the app.
Option 4: the EDB installer
The PostgreSQL download page for macOS links to EnterpriseDB's graphical installer. It is the heaviest option: it installs the server, pgAdmin, StackBuilder and the command line tools under /Library/PostgreSQL/<version>. For PostgreSQL 18 it supports macOS 13 or later on both Apple silicon and Intel. Add its bin folder to your PATH:
echo 'export PATH="/Library/PostgreSQL/18/bin:$PATH"' >> ~/.zshrc| Method | Local server | psql location |
|---|---|---|
| Homebrew libpq | No | $(brew --prefix)/opt/libpq/bin |
| Homebrew postgresql@19 | Installed, not started | $(brew --prefix)/opt/postgresql@19/bin |
| Postgres.app | Yes, while the app runs | /Applications/Postgres.app/Contents/Versions/latest/bin |
| EDB installer | Yes | /Library/PostgreSQL/<version>/bin |
Check that it worked
psql --version
# psql (PostgreSQL) 19.0
which -a psqlwhich -a lists every psql on your PATH in the order the shell finds them. If you installed more than one way, the first line is the one that runs.
Connect to a database
Pass a connection URI, quoted so zsh does not try to expand the ? and &:
psql "postgresql://[email protected]:5432/appdb?sslmode=require"Or use flags. psql asks for the password when the server wants one:
psql -h db.example.com -p 5432 -U app_user -d appdbWith flags, set SSL through the environment: PGSSLMODE=require psql -h …. Hosted databases usually expect SSL. sslmode=require encrypts the connection but only checks the certificate if you have a root certificate file in ~/.postgresql/root.crt; for full checking use sslmode=verify-full with sslrootcert=/path/to/provider-ca.pem, or sslrootcert=system (libpq 16 and later) for servers with publicly trusted certificates.
To stop typing passwords, put them in ~/.pgpass, one line per server in the form hostname:port:database:username:password (* matches anything). libpq ignores the file unless only you can read it:
echo 'db.example.com:5432:appdb:app_user:s3cret' >> ~/.pgpass
chmod 0600 ~/.pgpassThe PGPASSWORD environment variable also works, but the PostgreSQL docs advise against it: some systems let other users see a process's environment with ps, and an inline PGPASSWORD=… psql ends up in your shell history. A password inside the URI has the same history problem, and special characters in it must be percent-encoded.
Need a server to try this against? The Tablux demo database is a public, read-only PostgreSQL database:
psql "postgresql://tablux_demo.nwazeancgffixzvpqgvc@aws-1-eu-west-2.pooler.supabase.com:5432/postgres?sslmode=require"
# password: tablux-demo-readonlyOnce connected, \dt lists tables, \d table_name describes one, and \q quits.
Fix common errors
zsh: command not found: psql. The install worked but the folder is not on your PATH. Check the binary exists (ls "$(brew --prefix)/opt/libpq/bin/psql"), add the PATH line above, then open a new terminal or run source ~/.zshrc.
connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory. You did not give a host, so psql looked for a server on this Mac. Pass -h or a full URI.
Connection refused or a timeout. Nothing is accepting connections at that host and port from where you are: check the host name and port, that the server listens on a public interface (listen_addresses), and that a firewall or cloud security group allows your IP.
no pg_hba.conf entry for host "…", user "…", database "…", no encryption. The server only accepts SSL connections (or not from your address). Add sslmode=require.
server does not support SSL, but SSL was required. The server has SSL turned off. Ask for it to be enabled; drop to sslmode=prefer only on a network you trust.
certificate verify failed. You asked for verify-ca or verify-full and libpq cannot find the CA that signed the server's certificate. Download your provider's CA bundle and pass it with sslrootcert=.
WARNING: psql major version 16, server major version 19. Your psql is older than the server. Queries still run, but backslash commands such as \d may fail. Run brew upgrade libpq. The reverse is fine: a newer psql works with older servers, and its \d commands support servers back to 9.2. pg_dump is stricter and refuses to dump a server newer than itself (aborting because of server version mismatch).
password authentication failed for user. Wrong password, or the wrong user name format: through Supabase's shared pooler, for example, the user is role.project-ref, not just postgres.
Uninstall psql
# Homebrew
brew uninstall libpq # or: brew uninstall postgresql@19
brew cleanup --prune-prefix # clears dead symlinks after a postgresql@NN uninstallThen delete the PATH line from ~/.zshrc. If you ran the full formula's server, stop it first (brew services stop postgresql@19); its data stays in $(brew --prefix)/var/postgresql@19 until you delete that folder.
For Postgres.app, quit it, move it to the Trash and remove the PATH entry with sudo rm /etc/paths.d/postgresapp. For the EDB install, open /Library/PostgreSQL/<version>/uninstall-postgresql.app; it leaves the data directory behind on purpose.
Prefer a GUI?
psql is the right tool for scripts and quick checks. If you would rather browse tables and write queries in an app, Tablux connects to PostgreSQL from a Mac, iPhone or iPad, and you can point it at the same demo database.
Questions
Can I install psql without installing PostgreSQL?
Yes. Homebrew's libpq formula installs psql, pg_dump and the other client tools without the postgres server. It is keg-only, so add /opt/homebrew/opt/libpq/bin (or /usr/local/opt/libpq/bin on Intel) to your PATH.
Does macOS come with psql?
No. macOS does not include psql or any PostgreSQL tools; install them with Homebrew, Postgres.app or the EDB installer.
Why does Homebrew say libpq is keg-only?
Its programs have the same names as those in the full postgresql@NN formulae, so Homebrew does not symlink them by default. Add the libpq bin folder to your PATH or run brew link --force libpq.
Which psql version should I install?
The newest. psql works best with servers of the same or an older major version, and its \d commands support servers back to 9.2. An older psql against a newer server prints a version warning.
How do I connect psql to a database that requires SSL?
Add sslmode=require to the connection URI, for example psql "postgresql://user@host:5432/db?sslmode=require", or set PGSSLMODE=require when you use flags.
How do I exit psql?
Type \q and press Return, or press Control-D.
Updated 2026-11-25