PostgreSQL running with versions 12 and 13 confusion

3.9k views Asked by At

I am fairly new to PostgreSQL but I have some knowledge of SQL. I've been using a database with tables and data on postgres that (I'm assuming) comes with MacOS because when I start the server, access a given database and run SELECT version(); on terminal I get the following:
PostgreSQL 12.3 on x86_64-apple-darwin19.4.0, compiled by Apple clang version 11.0.3 (clang-1103.0.32.59), 64-bit However, I can't see it in Library/PostgreSQL because it doesn't exist.

So now I installed PostgreSQL 13 to work with while taking a course and also installed pgAdmin. It should have been installed under Library/PostgreSQL/13/ but it also doesn't exist. Nevertheless, I can access the servers for both 12 (port 5432) and 13 (port 5433) via pgAdmin and all its tables. I can access the tables from the 12 in pgAdmin and on the terminal.

I am a little confused with how everything was set up and I couldn't find a proper tutorial to solve it so I have a few questions:

  • How can I get rid of two versions and run only one with all my databases in the same? It feels like it would be more organized.
  • How do I access the server of version 13 through the terminal?
  • How can I uninstall version 12? I tried running open uninstall_postgresql.app but the folder doesn't exist anymore.
  • If I access via: psql -U postgres -p 5433: then psql (12.3, server 13.0) WARNING: psql major version 12, server major version 13. why is that?
1

There are 1 answers

1
Jeremy On BEST ANSWER

How can I get rid of two versions and run only one with all my databases in the same? It feels like it would be more organized.

How do I access the server of version 13 through the terminal?

You said it was on port 5433, so it should just be psql -U postgres -p 5433

How can I uninstall version 12? I tried running open uninstall_postgresql.app but the folder doesn't exist anymore.

This depends entirely on how you installed it, which you didn't mention here. Did you use postgres.app or brew or compile from source or ?

If I access via: psql -U postgres -p 5433: then psql (12.3, server 13.0) WARNING: psql major version 12, server major version 13. why is that?

The psql that is first in your path is the version 12 one. Your version 13 one may also be on your path, but maybe not. Try which -a psql to see if any other versions show up. The 12 version will mostly work, but some of the \ commands may throw errors.

There are two parts to the postgres versions that are running. The data directory, which can be found by connecting to the server and running show data_directory; and the executables. You can find those with which psql (or similar) because at least one of them seems to be in your path. If that doesn't work, you could use lsof to find the files that are in use for ports 5432 and 5433.