2

For development reasons I have both Postgres 12 and 14 installed on my local machine. However, often I also need to use the pg_dump utility to create backups.

pg_dump 12 won't connect to a Postgres 14 database and viceversa.

If I simply run pg_dump, Ubuntu will use the one in /bin by default which is pg_dump@12.

If I want to run version 14 I have to manually type:

/usr/lib/postgresql/14/bin/pg_dump

Is there any way I can quickly switch between them?

Something like:

pg_dump@14
  • Can you just create different clusters for each (if I'm using the correct term)? – Paul Jul 14 '22 at 14:59
  • I'm not sure what you mean by that, this is my local machine I use for development. – Leonardo Petrucci Jul 14 '22 at 15:06
  • When initiall configuring postgres, you didn't use `initdb` to create a new database cluster? – Paul Jul 14 '22 at 15:11
  • No I didn't, I just installed it and created a database – Leonardo Petrucci Jul 14 '22 at 15:18
  • I don't have extensive experience with postgres or anything, but you should find there is a directory, something like `/var/postgresql/data/` that stores the database cluster. You shouldn't be using different versions for the same cluster, and their should be a way to use the command only with certain versions and clusters. This is not at all uncommon, but I don't know how to do it in Ubuntu. – Paul Jul 14 '22 at 15:27
  • Also see this question which has solutions based on running each on different ports, t https://serverfault.com/questions/250192/running-multiple-versions-of-postgresql-on-the-same-ubuntu-server and not to mention there is always `alias pg_dump14='/usr/lib/postgresql/14/bin/pg_dump'` but it seems like this problem should have a better solution somewhere if not SF then one of the SE sites. – Paul Jul 14 '22 at 18:15

0 Answers0