Installing postgresql-client

Hi all,

I’m wondering how to install the psql command on NixOS. To be clear: I’m only interested in the client, not the server.

I’ve looked at the derivation but couldn’t find any pointers.

Is there a way to create a derivation without building from source?



It seems that there is no split in the derivation.
You can just add the postgresql derivation to environment.systemPackages (or wherever you need it) and the psql command should be available.

$ nix-shell -p postgresql --command 'psql --version'
psql (PostgreSQL) 9.6.10

bump - did anybody solve this?

Does what @Mic92 mentions not work for you?

No as that postgresql package appears to install the server (alongside the client), which I am trying to avoid :slight_smile:

It pulls the binary into path, it doesn’t run it though or configure it.

If you are just annoyed by the binary being visible in your PATH a simple wrapper might solve that:

runCommandNoCC "psql" {} ''
  mkdir -p $out/bin
  ln -s ${postgresql}/bin/psql $out/bin/psql

I’m sorry, but I completely fail to see the issue here. Is your concern the fact that the server binaries are present in the path?

When I install postgresql into environment.systemPackages it also starts a postgres server daemon that I don’t want installer nor running since I use containers.

I’d rather just install the postgres-client so that I can connect to my containers etc.

I was hoping that since a couple of years had passed that potentially there was a solution already :smiley:

Nobbz’s looks like the best but was hoping for something as simple as just adding a package like postgresql-client

actually forget that i don’t think it installs it as a daemon!

Correct. Whenever you install anything via environment.systemPackages there is no possible way for a daemon to start. This will never happen and is useful for you to know. Often times people new to NixOS wonder why a service isn’t running after they installed it via environment.systemPackages, not realizing they need to “install” it via services.FOO.enable = true;.

1 Like

The only downside to not having the client and server split is the space used but as postgresql_14 currently takes up around 25mb, that’s really not an issue at all which is why nobody has put in the effort to split the 2.

1 Like

Apologies for the necropoast … but how about the use case where I’m using Nix to build a Docker image and I want to include psql (client) but not the postgres server?

1 Like

but how about the use case where I’m using Nix to build a Docker image and I want to include psql (client) but not the postgres server?

I’d like to do the same thing. Currently the runtime closure postgresql package is over 300MB, while I can find an pure psql image on docker hub under 10MB

1 Like