Installing older version of postgres using homebrew - postgresql

I am trying to use an older version of postgres and I cannot get it to work. When I run brew search postgres I see:
$ brew search postgresql
==> Searching local taps...
postgresql ✔ postgresql#9.4 ✔ postgresql#9.5 postgresql#9.6
but then when I run brew switch postgres 9.4 I see:
$ brew switch postgresql 9.4
Error: postgresql does not have a version "9.4" in the Cellar.
Versions available: 9.6.2, 9.6.4
What am I missing? I need to run version 9.4

brew switch works only on installed versions of a specific formula. You have postgresql versions 9.6.2 and 9.6.4 on your machine, so you can only switch to one of those.
However Homebrew provides fixed-version formulae using the <name>#<version> thing. In order to get Postgres 9.4, you can run the following command:
brew install postgresql#9.4

Related

Upgrading postgres database files fail with "could not access file $libdir/postgis-2.5: No such file or directory"

I'm working on OSX and have postgres installed via Homebrew. I've just upgraded Postgres from v11 to v13. Now I've tried updating the database files with:
brew postgresql-upgrade-database
This fails and looking at the logs, the error is:
pg_dump: error: query failed: ERROR: could not access file "$libdir/postgis-2.5": No such file or directory
If I do brew info postgis then I see:
% brew info postgis
postgis: stable 3.0.2 (bottled), HEAD
Adds support for geographic objects to PostgreSQL
https://postgis.net/
/usr/local/Cellar/postgis/3.0.2_1 (435 files, 29.7MB) *
Poured from bottle on 2020-11-12 at 23:15:12
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgis.rb
License: GPL-2.0-or-later
==> Dependencies
Build: gpp ✘, pkg-config ✔
Required: gdal ✔, geos ✔, json-c ✔, pcre ✔, postgresql ✔, proj ✔, protobuf-c ✔, sfcgal ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 11,064 (30 days), 26,959 (90 days), 80,033 (365 days)
install-on-request: 10,946 (30 days), 26,628 (90 days), 78,351 (365 days)
build-error: 0 (30 days)
So I guess Postgis 3.0.2 was installed as part of the upgrade process and pg_dump (which is needed for the database file upgrade) can't find Postgis 2.5.
What should I do? I guess I could reinstall Postgis 2.5 to $libdir temporarily - but how?
pg_config --pkglibdir reveals that $libdir is /usr/local/lib/postgresql. If I list the files in that directory, I can see it contains postgis-3.so, but not postgis-2.5.so.
NB: I also can't currently access postgres with psql - I see the dreaded psql: error: could not connect to server: could not connect to server: No such file or directory. However, brew services list tells me that postgresql is running.
Uninstall the wrong version of Postgis if you haven't already:
brew remove postgis
Firstly go to the last 2.5 version of the Postgis formula here:
https://raw.githubusercontent.com/Homebrew/homebrew-core/bca96164362bfa3c42b4d403be4eb3847797424f/Formula/postgis.rb
Copy that code.
Paste this over the homebrew Postgis formula on your machine:
pbpaste > $(find $(brew --repository) -name postgis.rb)
Then install Postgis again with this formula:
brew install postgis
Pin Postgis to prevent it being upgraded accidentally:
brew pin postgis
That should get the correct version of Postgis in there for you.
Upgrading PostGIS is not so straightforward (see the documentation), and by using the automatic upgrade of this distribution you probably messed up your installation.
Take a full backup of your PostgreSQL data directory, then uninstall PostgreSQL v13, install v11 and PostGIS 2.5 again and see that you can get the database to work again.
Then follow the upgrade procedure from the PostGIS manual.
There's a compatibility/support matrix on the user wiki linked off of the PostGIS site which seems to indicate that as of Postgres v13, the minimum version of PostGIS is v3.0
If you're stuck on PostGIS v2.5 for whatever reason, Postgres V12 looks to be your best bet.

How do i install postgis on ubuntu server?

My pc showing i have two versions of Postgres installed.
postgres=# \c viserver
psql (12.2 (Ubuntu 12.2-4), server 11.7 (Ubuntu 11.7-0ubuntu0.19.10.1))
I installed PostGIS using sudo apt-get install postgis but it installed PostGIS in Postgres 12.
But I want to install it in Postgres 11. cause my server version using postgres 11.
because CREATE EXTENSION postgis; on a database giving error
ERROR: could not open extension control file "/usr/share/postgresql/11/extension/postgis.control": No such file or directory
the error you see means that some packages are not installed.
To have postgis.control please check and install
postgresql-11-postgis-X.Y (e.g. X.Y = 2.5)
and
postgresql-11-postgis-X.Y-scripts
Regards,
Mohamad
It helped what S. Mohamad explained. But I want to share the exact answer.
Steps to resolve the error:
Try to run sudo apt install postgresql-11-postgis. This will install but provide suggestion what to install like below.
You can see the 2 versions of postgis I installed the latest version by sudo apt install postgresql-11-postgis-3
After installing required package you can run CREATE EXTENSION postgis; in postgres and it will show you following:
Yay!! No errors.

postgres app gets only 10.0 on Mac (sierra). how do I lower that version?

I tried installing brew install postgresql#9.6 but then
pg_ctl -D /usr/local/var/postgres start
returned this command not found: pg_ctl
Has anyone installed 9.6 version of postgres without the app and successful started the service or is there a way to install 9.6 via the app. it seems to get me the latest 10.0
You need to update your $PATH after brew install
export PATH="/usr/local/opt/postgresql#9.6/bin:$PATH"
Moreover,
For compilers to find postgresql#9.6 you may need to set:
export LDFLAGS="-L/usr/local/opt/postgresql#9.6/lib"
export CPPFLAGS="-I/usr/local/opt/postgresql#9.6/include"
For pkg-config to find postgresql#9.6 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/postgresql#9.6/lib/pkgconfig"

Install Postgis in Ubuntu 16.04 in with already postgresql 9.3 installed

In ubuntu 16.04 when I tried to install postgis with using apt-get install postgis postgresql-9.3-postgis-2.1 this command, it installed postgresql 9.6 and postgis-9.6 version. And when tried to create extension it gives error ERROR: could not open extension control file "/usr/share/postgresql/9.3/extension/postgis.control": No such file or directory.
postgres#db:~$ psql
psql (9.6.3, server 9.3.17)
Type "help" for help.
It seems that you didn't use sudo before apt-get which is causing issue with write permissions of your directory.
To prevent this error remove the installed version and reinstall it with sudo like,
sudo apt-get install postgis postgresql-9.3-postgis-2.1
Read more related with your issue and follow the steps to install specific version.

Incompatible postgis 2.1 for postgresql 9.3.3 homebrew os x 10.10

I have upgraded from OS X 10.9 to 10.10 Yosemite. I was running postgresql 9.3.3 with postgis 2.1. I did not do a pgdump before upgrading to OS X 10.10 (I know, I know, kill me...) but I have the original data directory. I did a brew install postgresql and got 9.4.4. So I installed Postgresql 9.3.9 (the only 9.3 version I could find) with Homebrew. Also brew install postgis. I then got a version 2.1 Postgis for Postgresql 9.4.4. I tried to install postgis20 but that does not work with my database.
When I start Postgresql 9.3.3 I can see all my databases but when I browse I get the error:
ERROR: could not access file "$libdir/postgis-2.1": No such file or directory
I tried to link to posts-2.1 in the $libdir directory but then I get this message:
ERROR: incompatible library "/usr/local/Cellar/postgresql93/9.3.9/lib/postgis-2.1.so": version mismatch
DETAIL: Server is version 9.3, library is version 9.4.
So obviously I need a postgis-2.1 for Postgresql 9.3 but I don't know how to fix that.
If I try to run a pg_dumpall I get this error (obvious I guess):
➜ ./pg_dumpall >> old_backup.sql
pg_dump: Dumping the contents of table "darwin_test" failed: PQgetResult() failed.
pg_dump: Error message from server: ERROR: could not load library "/usr/local/Cellar/postgresql/9.3.3/lib/postgis-2.1.so": dlopen(/usr/local/Cellar/postgresql/9.3.3/lib/postgis-2.1.so, 10): Symbol not found: _json_tokener_errors
Referenced from: /usr/local/Cellar/postgresql/9.3.3/lib/postgis-2.1.so
Expected in: /usr/local/lib/libjson-c.2.dylib
in /usr/local/Cellar/postgresql/9.3.3/lib/postgis-2.1.so
So how do I get postgis-2.1 to work again with postgresql 9.3.3?
In homebrew I only find a postgis-2.1 for postgresql94.
Use brew edit postgis to change the postgresql references to postgresql93 in the install script and then run brew install postgis. You might also have to link/unlink postgresql using brew link postgresql93 or brew unlink postgresql.