How do I install just the client tools for PostgreSQL on Windows?
Asked Answered
C

11

118

I have a PostgreSQL database on a Linux system that I want to access from my Windows PC. But the only Windows binaries I have been able to find are the full installer, which includes the database server and client.

Is it possible to get a client-only Windows binary install for PostgreSQL from anywhere?

(To clarify, I want the standard PostgreSQL client, psql - not a GUI client or independent tool).

Cerargyrite answered 22/11, 2015 at 12:32 Comment(4)
Why don't use ssh into your linux machine and use psql there?Maury
Basically because any scripts I develop will be on my local PC, and so running from there is easier. All my development work is at the Windows console prompt, so running my SQL from there as well is just more convenient.Cerargyrite
@Maury he's asking for a client, if he's asking for that is obvious that he doesn't need/want/can't run psql in the Linux machine.Ancell
Answer by @Fact below should be the accepted answer as of 2020.Publicness
F
68

Unfortunately there is no real client "only" installer.

What you can do, is to download the ZIP archive of the complete Postgres binaries:

http://www.enterprisedb.com/products-services-training/pgbindownload

and then remove the "server" part from it.

When you unzip it, you get the following directories:

bin
doc
include
lib
pgAdmin III
share
StackBuilder
symbols

You can remove the doc, include, pgAdmin III, StackBuilder and symbols directories. As far as I can tell (but I am not sure) the client also doesn't need the share or lib directories, but you would need to test that. So that leaves only the bin directory.

I think the share directory could be needed for localized error messages in psql but I'm not sure about that.

Inside the bin directory you can essentially remove all .exe files (except psql.exe of course). You can also remove all wx*.dll files, they are only needed for pgAdmin. The libxml2.dll and libxslt.dll are also only needed for the server.

If you do want some of the other client tools, you might want to keep

  • pg_dump.exe
  • pg_dumpall.exe
  • pg_restore.exe

One drawback of this approach is that this requires the Visual C++ Redistributable to be installed. But you can overcome that as well by simply putting the MSVCR120.DLL from some computer where it is installed into the bin directory.

So that leaves you with these files (from the bin directory) that are required for the psql client:

  • iconv.dll (libiconv-2.dll in newer Postgres versions)
  • libeay32.dll
  • libintl-8.dll
  • libpq.dll
  • msvcr120.dll
  • ssleay32.dll
  • zlib1.dll
  • psql.exe

Of course you can also take all that from an existing Postgres installation without the need to download the ZIP archive.


It is obviously not a real installer, but if you put the cleaned up directory into a ZIP file, you can distribute that and whoever needs it just unzips the archive. Personally I find unzip to be the best "installer" anyway (I also use that to install the Postgres server, the Windows installer just has too many quirks)

Flouncing answered 22/11, 2015 at 12:45 Comment(5)
Thanks. I'm not actually too worried about stripping out the unneeded server bits - the main thing I want to avoid is the installer creating accounts, the service and a database - so just having the zip distribution is fine. I looked for this first, but could only find the installer on the EnterpriseDB site (the postgresql site points only to enterprisedb.com/products-services-training/pgdownload and there's no link from there to the bin download page :-().Cerargyrite
Whoops. Just noticed the "advanced users" link on the postgresql.org download page. I must have missed that last time.Cerargyrite
For anyone on PostgreSQL >= 9.6.3 wondering where iconv.dll went, bring in libiconv-2.dll instead.Provenance
Can confirm that this still works in 2020. Very helpful for having psql.exe for the client tool only.Tight
@a_horse_with_no_name i am getting this error during binary zip installation " initdb.exe initialize a database cluster has stopped working" any ideas are highly appreciated?Doran
A
81

As of 2020, when you click download the full installer from here , click next and next and you get the option to install only the command line - tools enter image description here. Remember to add the path to the bin folder in the PATH variable.

Artina answered 24/2, 2020 at 3:37 Comment(4)
This is the easiest, yet better way, imho.Freelance
This should be the accepted answer as of 2022Marylyn
And the accepted answer as of 2023. Still valid.Feer
What helped me was adding the bin directory path to the PATH variable in Environment Variables. After installing the PostgreSQL installer of course.Michaud
F
68

Unfortunately there is no real client "only" installer.

What you can do, is to download the ZIP archive of the complete Postgres binaries:

http://www.enterprisedb.com/products-services-training/pgbindownload

and then remove the "server" part from it.

When you unzip it, you get the following directories:

bin
doc
include
lib
pgAdmin III
share
StackBuilder
symbols

You can remove the doc, include, pgAdmin III, StackBuilder and symbols directories. As far as I can tell (but I am not sure) the client also doesn't need the share or lib directories, but you would need to test that. So that leaves only the bin directory.

I think the share directory could be needed for localized error messages in psql but I'm not sure about that.

Inside the bin directory you can essentially remove all .exe files (except psql.exe of course). You can also remove all wx*.dll files, they are only needed for pgAdmin. The libxml2.dll and libxslt.dll are also only needed for the server.

If you do want some of the other client tools, you might want to keep

  • pg_dump.exe
  • pg_dumpall.exe
  • pg_restore.exe

One drawback of this approach is that this requires the Visual C++ Redistributable to be installed. But you can overcome that as well by simply putting the MSVCR120.DLL from some computer where it is installed into the bin directory.

So that leaves you with these files (from the bin directory) that are required for the psql client:

  • iconv.dll (libiconv-2.dll in newer Postgres versions)
  • libeay32.dll
  • libintl-8.dll
  • libpq.dll
  • msvcr120.dll
  • ssleay32.dll
  • zlib1.dll
  • psql.exe

Of course you can also take all that from an existing Postgres installation without the need to download the ZIP archive.


It is obviously not a real installer, but if you put the cleaned up directory into a ZIP file, you can distribute that and whoever needs it just unzips the archive. Personally I find unzip to be the best "installer" anyway (I also use that to install the Postgres server, the Windows installer just has too many quirks)

Flouncing answered 22/11, 2015 at 12:45 Comment(5)
Thanks. I'm not actually too worried about stripping out the unneeded server bits - the main thing I want to avoid is the installer creating accounts, the service and a database - so just having the zip distribution is fine. I looked for this first, but could only find the installer on the EnterpriseDB site (the postgresql site points only to enterprisedb.com/products-services-training/pgdownload and there's no link from there to the bin download page :-().Cerargyrite
Whoops. Just noticed the "advanced users" link on the postgresql.org download page. I must have missed that last time.Cerargyrite
For anyone on PostgreSQL >= 9.6.3 wondering where iconv.dll went, bring in libiconv-2.dll instead.Provenance
Can confirm that this still works in 2020. Very helpful for having psql.exe for the client tool only.Tight
@a_horse_with_no_name i am getting this error during binary zip installation " initdb.exe initialize a database cluster has stopped working" any ideas are highly appreciated?Doran
C
37

Actually there are client CLI tools in pgAdmin. All you need is just to install it on your Windows machine from https://www.postgresql.org/download/windows/.

Then you'll be able to find those tools in folder like C:\Program Files (x86)\pgAdmin III\1.22 or C:\Program Files (x86)\pgAdmin 4\v2\runtime, depends on the pgAdmin version you have installed.

Chowchow answered 23/3, 2017 at 7:15 Comment(1)
note you can download pgadmin from postgresql.org/ftp/pgadmin/pgadmin4/v7.6/windowsAffinitive
G
15

Below are the steps I followed to connect to Amazon Redshift with postgres12 psql on windows:

  1. download postgres 12.4 from below location: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

  2. run the installer which will take few minutes and prompt you for installations options

  3. select command line tools as shown in below screenshot and install that

  4. Above will install postgres12 command line in below folder C:\Program Files\PostgreSQL\12\bin. Make sure to add this to your PATH environment variable

  5. open cmd and run command set PGCLIENTENCODING=UTF8

  6. run psql to connect to redshift. Make sure to change below parameters highlighted in red for your cluster endpoint, userid, copy script file name and log script file name respectively psql -h redshift-cluster-1.abcdefgh.us-east-1.redshift.amazonaws.com -U demo_user -d dev -p 5439 -f d:\demo\redshift_script.sql -L d:\demo\log_redshift_script.log

  7. all commands in redshift_script.sql file would get executed in PSQL and logs will be stored in log_redshift_script.log file

enter image description here

Grefe answered 29/10, 2020 at 13:39 Comment(2)
The accepted answer is... wrong. This should be the answerHampson
I installed the server in specific directory/drive than the default one (C:/Program Files) on windows and the path to psql.exe was not set. In that case you will need to add the path to <server-install-direcrtory>/bin in your PATH environment variable.Contrary
B
14

Thanks to everyone who has posted on this thread.

For what it's worth, I got psql.exe from PostgreSQL 10.10 working under Windows 10 with just the following files from the zip archive:

libcrypto-1_1-x64.dll
libiconv-2.dll
libintl-8.dll
libpq.dll
libssl-1_1-x64.dll
psql.exe

When connecting to AWS Redshift, I got the following error:

psql: FATAL: invalid value for parameter "client_encoding": "WIN1252"

I resolved this by running

set PGCLIENTENCODING=UTF8

I found this solution at https://forums.aws.amazon.com/thread.jspa?messageID=600088

HTH.

Brote answered 31/10, 2019 at 10:32 Comment(1)
Thanks. This list was exactly what I was looking for. Much appreciated.Radome
S
13

I realize this is an older question, but when I used the Windows installer for the latest version of Postgres (10.4), it gave me the option to install just the command line tools. I just unchecked server and pgadmin in the installer's window when prompted to choose what I wanted to install.

Singleminded answered 8/6, 2018 at 14:31 Comment(1)
Note, as of today I see two Windows installers in the PostgreSQL web site and only one of them has the option to install only the command line tools. The EnterpriseDB installer has the option, the BigSQL installer does not have a command line tools only option.Grallatorial
S
6

There is a third-party command-line tool available known as PGCLI - A command-line interface for Postgres with auto-completion and syntax highlighting.

Install:

pip install pgcli

Connect to POSTGRES Server from Command-line:

pgcli -h localhost -U xyz -d app_db

For official documentation, visit PGCLI

Shammer answered 18/10, 2021 at 18:24 Comment(0)
A
1

If there's pgadmin v4 installed then just copy these libraries (from C:\Program Files\pgAdmin 4\v4\runtime\):

libcrypto-1_1-x64.dll
libpq.dll
libssl-1_1-x64.dll

These were enough for me to connect from a client Windows 10 x64 PC to a remote Postgres 13 server. Note, that libraries coming with the ZIP archive mentioned above are slightly different and have more dependencies.

Alpheus answered 13/1, 2021 at 15:0 Comment(0)
P
1

I built standalone versions for windows and linux. It has less dll dependecies and smaller size and work with many linux.

https://github.com/hemnstill/StandaloneTools/releases?q=pg_dump

Portiaportico answered 24/12, 2022 at 8:14 Comment(0)
C
0

I kind of cheat. I install sqlbackupandftp.com on a Windows server - which has a free version that can schedule a single database backup. In the binaries, pg_dump.exe is there - typically on the C: drive like C:\Program Files (x86)\SQLBackupAndFTP\dbms\PostgreSql

Chromogenic answered 24/8, 2021 at 18:14 Comment(0)
C
0

You can also download "https://www.nuget.org/packages/Postgres.psql" nuget package to get "psql.exe"

Capital answered 7/2, 2023 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.