How do I install older version of postgresql and postgis? - postgresql

I am new to Linux and I found it really difficult to install older version of postgresql (along with postgis). I have uninstalled everything I could find connected to postgresql in aptidude. As only the newest version is available through apt-get install, I have went through several tutorials how to get 9.1 installed.
Example: https://wiki.postgresql.org/wiki/Apt (with 9.1 at the end, not 9.3)
After I was done with this tutorial, pgAdmin III is still showing 9.3 as version.
What's the correct way to dump 9.3 and install 9.1 as well as postgis 1.5?
I am using Mint 17

Okay. First off it is perfectly fine to run multiple versions of postgresql alongside one another. You can have more than one cluster on a box, and each cluster can run different versions. The debian pacakges are very well designed to make this easy to do.
However since you've indicated you're a newby to linux/postgresql it's probably best to get 9.3 completely cleaned from your system to avoid frustrating hiccups which will take you a long time to figure out.
To do this you need to:
Purge all postgresql 9.3 packages from dpkg
Manually delete any 9.3 data and configuration for 9.3 cluster
Make sure you've created a 9.1 cluster
Step 1 – purge DPKG
DPKG manages the packages on your system. APT acts as a mechanism for getting packages to install. A lot of DPKG functionality is available through apt, but some things are just easier on dpkg. In your comments you've shown that DPKG is still showing remnants of 9.3. When you uninstall a package some parts of it may hang around (such as configuration files). You can remove multiple packages in one command. To get rid of these completely you can tell dpkg to purge them dpkg --purge <package name>. You can remove multiple packages in one command and it's best to do so.
dpkg --list will list everything on your system. dpkg --list | grep postgresql searches this list for postgresql.
Step 2 – Manually delete data and configuration from the old 9.3 cluster.
When you first install postgresql it creates a cluster for you; no questions asked. This trips up a lot of new users because they neither knew that it happened nor how to replace it. Now that 9.3 is uninstalled you can go ahead and simply delete the configuration and data:
If there was anything you wanted to keep in the installed 9.3 database DO NOT run the following commands
sudo rm -rf /etc/postgresql/9.3 Removes the configuration.
sudo rm -rf /var/lib/postgresql/9.3 Removes the data.
Step 3 – Create a new cluster
You've indicated in comments that postgresql 9.1 is installed. Before you run this command it's worth reading the manual. man pg_createcluster.
sudo pg_createcluster 9.1 <think up a name>
Now you should be able to start up postgresql sudo service postgresql start
Edit
If pg_config is still listing the incorrect version then... this can be a result of remnants of 9.3 still left on your system. This may not be a problem. To allow multiple versions to run along side one another pg_config is a wrapper script which searches for the latest (highest version) of /usr/lib/postgresql/*/bin/pg_config. So what you're seeing is the result of running /usr/lib/postgresql/9.3/bin/pg_config. If 9.3 is completely cleaned from your system then /usr/lib/postgresql/9.3 should have gone.
If you want to see the configuration of 9.1 then try running:
/usr/lib/postgresql/9.1/bin/pg_config.
The wrapper scripts which starts the server will use the file structure of /etc/postgresql and use the apropriate version. So /etc/postgresql/9.1/main will startup version as 9.1.

Related

Is there a problem with having 2 versions of postgres for Apache-Age

I installed the Apache-Age extension for postgres and this extension specifies that it works with postgres-11 or postgres-12. However I have already installed postgres-14 on my system. Am i gonna have a problem with that? And if I am how do i only uninstall the postgres-14 version?
I tried searching the deb packages installed to see if i find postgres-14 but i can't seem to find it
So mainly the apache-age extension works with PostgreSQL versions 11 and 12. It creates problems with different other versions of PostgreSQL.
In order to have a smooth installation follow the below steps:
uninstall PostgreSQL version 14
reinstall PostgreSQL version 11 or 12
Uninstalling PostgreSQL version 14:
For uninstalling the PostgreSQL from ubuntu:
sudo apt remove postgresql postgresql-contrib
The output would look something like this:
After uninstalling PostgreSQL, uninstall the dependencies
sudo apt autoremove
The output of the above command would look like this:
enter Y here and the PostgreSQL will be uninstalled.
Now reinstall the PostgreSQL version 11 or 12 using the below commands:
Download the files in any folder:
wget https://ftp.postgresql.org/pub/source/v11.18/postgresql-11.18.tar.gz && tar -xvf postgresql-11.18.tar.gz && rm -f postgresql-11.18.tar.gz
The command will download and extract the tar files for Linux users from Source in the working directory.
Installing PG:
Now we will move toward installing PG
cd postgresql-11.18
# configure by setting flags
./configure --enable-debug --enable-cassert --prefix=$(path) CFLAGS="-ggdb -Og
# now install
make install
References:
For more references you can also see:
https://dev.to/talhahahae/installation-of-apache-age-and-postgresql-from-source-in-linux-part-1-gka
https://www.commandprompt.com/education/how-to-uninstall-postgresql-from-ubuntu/#:~:text=Conclusion-,To%20uninstall%20Postgres%20from%20your%20Ubuntu%20operating%20system%2C%20open%20the,“sudo%20apt%20autoremove”%20command.
https://github.com/git-guides/install-git
https://age.apache.org/age-manual/master/intro/setup.html
https://www.postgresql.org/docs/current/install-procedure.html
Apache AGE only supports Postgres-11 and Postgres-12. You can follow the following to install Apache AGE with Postgres:
How to install AGE extension of postgresql from source code in ubuntu?
While Apache Age is designed to work with PostgreSQL 11 and 12, you can have multiple versions of PostgreSQL installed in your computer. However, the installations need to be in "different directories". Each version of PostgreSQL will have its own set of binaries and configuration files.
When you install multiple versions of PostgreSQL, it is important to ensure that each version is installed in a separate directory and that the ports used by each instance do not conflict with each other. Additionally, you may need to specify the correct version of PostgreSQL when running commands, by using the appropriate version-specific binary or setting the PATH environment variable to include the correct directory.

psql is still pointing to older version after upgrade to newer ( 10.7 )

I have 2 different major versions of postgres 9 and 10 installed on rhel.
Latest situation after attempts of updating psql package:
I have psql 9.2.24 installed on rhel 7.6 while the server version is 10.7.
I had earlier issues with my yum repo which got corrupted and later on, i recovered/fixed it with the help of following command mentioned at here (You can get idea of what my problem was initially with corrupt yum repo)
echo 7 > /etc/yum/vars/releasever
I checked my update-alternatives at here
and it is correctly referring to the psql at 10.7 directory but still I am seeing the psql old version number while connecting to existing database.
Following was the steps i followed to update the psql package:
All databases were kept running.
yum install postgresql10.x86_64
Command mentioned in point 2, installed/upgraded whole lot of packages on machine as the yum repo was corrupted . one of the key statements in this upgrade concerning to postgres was
postgresql10 x86_64 10.7-2PGDG.rhel7 pgdg10 1.6M
Please note, I have not yet restarted any of the instance running during/before/after above update and somehow believe it has something related to the fact that until I restart(stop existing instances and start them again) all running instances of psql/db's , psql changes will not start reflecting but that is just my assumption. Could someone please help what i understood/did wrong in this upgrade process.
Nothing except above has been changed/upgraded in terms of psql/postgres. Still I have both installations of postgres: 9 and 10.
I did this fix few months back and I forgot that. Something similar with better answers are at here So all credits goes to answer posters there. But here is what I did to solve it:-
Restarting already running postgres instances did not help.
I checked which psql showed me one of the psql at /usr/bin . It was some 9 months old so definitely it was not something got installed with my yum postgres... install step mentioned in my question which made me realize that new package installation will not override it straightaway.
I tried using
update-alternatives --config pgsql-psql but got the same error as mentioned on the above SO answer:
/usr/bin/psql exists and it is not a symlink
key clue on this page is in the comment from #Alexander Gorg that ln command will not override the existing link , it needs to be removed manually. I thought of removing the symlink but then end up renaming the psql at /usr/bin to psql_org.
Indeed i issued ln command during this process.
Now i issued the update-alternatives command and restarted one of the instances. Correct psql was now there.
Above indeed helped fixing psql version but still other utilities pg_basebackup and others were referring to older version. I believe better approach would have been to remove the old postgresql installation. I tried to list existing postgresql version with
yum list installed | grep postgres
only shows that
postgresql10*
packages are there and I remember I have already removed older postgres version with
yum erase postgres... so not sure what to remove.
Temporarily I have further solved issued by renaming other utilities in /usr/bin and then updating their alternatives.

Postgres pg_dump version mismatch... even though versions are the same

I'm trying to dump a Postgres db from Amazon RDS, which I recently updated to 10.1. To do so, I download pg_dump 10.1 from enterprisedb.com (http://get.enterprisedb.com/postgresql/postgresql-10.1-1-linux-x64-binaries.tar.gz) but when I try to use it, I get the following error:
pg_dump: server version: 10.1; pg_dump version: 10.1
pg_dump: aborting because of server version mismatch
This worked fine before, when RDS had version 9.6 and I used pg_dump 9.6 (downloaded from the same location).
I tried newer versions of pg_dump (10.2 and 10.3) but get the same error (which makes sense, because those newer versions actually don't match the RDS version).
I also checked that no other pg_dump is installed on my server (Ubuntu 15.04 - I know I should update... waiting for 18.04), found one and deleted it, but get the same error.
What could be the problem here?
First of all, pg_dump works perfectly with older version of the server. In such cases you will see lines like these:
-- Dumped from database version 9.6.6
-- Dumped by pg_dump version 10.1
Also, pg_dump version, say, 10.0 should work with server version 10.1 and higher in 10.* branch – so minor version should not be the issue. See this comment in pg_dump's source code: https://github.com/postgres/postgres/blob/REL_10_STABLE/src/bin/pg_dump/pg_dump.c#L668
/*
* We allow the server to be back to 8.0, and up to any minor release of
* our own major version. (See also version check in pg_dumpall.c.)
*/
In your case, the issue can be caused by one of these aspects:
you downloaded not official pg_dump, you took it from one of Postgres companies, it can be modified somehow (notice addition "-1" in URL, so you use their version of pg_dump labeled as "10.1-1");
you're working with modified (by AWS engineers) Postgres server;
recently, versioning schema has been changed in the Postgres project, from 3-number versions to 2 numbers. This means, that some bugs in version detecting functions might be present since the changes are relatively new.
Anyway, the error message you provided saying that 10.1 and 10.1 do not match – this is is not normal at all. There is a definitely a bug, but it's not obvious where.
I would try the following steps.
1) Use official (community supported) pg_dump. On Ubuntu, you need just install "postgresql-client-10" using official packages:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client-10
2) If the previous step doesn't help, try contacting AWS support, asking them to double-check this issue.
3) Finally, try to reproduce the problem with vanilla Postgres installed on your Ubuntu machine and if it persists, it definitely needs to be reported as a bug https://www.postgresql.org/docs/10/static/bug-reporting.html
try check for permissions - whats the path

Upgrading postgresql on redhat failing "version"

I'm new to postgres, and the environment started with the redhat 64bit default install of 9.2. Postgres quickly shot from a proof of concept to everyone wanting a db, and I'm trying to get up to speed with 9.6.
When I run the upgrade, it errors with the following:
-bash-4.2$ /usr/pgsql-9.6/bin/pg_upgrade -b /bin -B /usr/pgsql-9.6/bin -d /var/lib/pgsql/9.2.old/data -D /var/lib/pgsql/9.6/data
Performing Consistency Checks
-----------------------------
Checking cluster versions
This utility can only upgrade to PostgreSQL version 9.6.
Failure, exiting
I'm ensuring that I'm calling the pg_upgrade in the new binary location. --read that in one article.
I have spent the better part of the morning searching google, and searching here...trying this and that. It's been an interesting, yet ridiculous worm hole.
I'm not using home brew or anything like that. I am just doing a yum install.
Can someone tell me, or point me to a good document that works around the glitches? The postgres manual document states that the pg_upgrade is valid from versions 8.4 up.
Any suggestions would be greatly appreciated.

How to install Postgis to a Keg installation of Postgres#9.6 using Homebrew?

I have installed Postgresql#9.6 and Postgis via Homebrew. However, installing Postgis via Homebrew installs the latest version of Postgresql at 10 as dependency and pinning Postgresql at 9.6.5 blocks the install of Postgis via Homebrew.
Performing 'CREATE EXTENSION postgis;' returns:
ERROR: could not open extension control file "/usr/local/Cellar/postgresql#9.6/9.6.5/share/postgresql#9.6/extension/postgis.control": No such file or directory
I've also tried uninstalling the Postgresql (at 10) and editing the Postgis formula to depend on Postgres#9.6 instead of Postgresql.
This is similar to How to install Postgis to a Keg installation of Postgres#9.5 using Homebrew? but with a later keg formula
I managed to do it after many combinations.
In a nutshell, solution is to install the old version of the original package postgres, switch to it, and install the old version of postgis.
Install postgres
1/ Install the current version of postgres (10.1 as speaking)
brew install postgres
2/ Install the old version of postgres using its old formula. Proper link can be found using github or git log on the Tap repo (/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/).
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d014fa223f77bee4b4097c5e80faa0954e28182f/Formula/postgresql.rb
This will install the version 9.6.5 (last one before 10.x series).
3/ Switch to it so links are defaulted to postgres 9.6
brew switch postgres 9.6.5
Install postgis
4/ Install old version of postgis (2.3). This is using the same sha version of the Formula so everything is linked correctly (using the current postgis will expect postgresql 10, so it will end up to a version mismatch when initializing extension).
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/d014fa223f77bee4b4097c5e80faa0954e28182f/Formula/postgis.rb
Use them
5/ If required initialise the DB
initdb /usr/local/var/postgres
6/ Create and use your DB
createdb mydb
psql mydb
mydb=# CREATE EXTENSION postgis;
Installing PEX, a package manager for Postgresql allowed me to install Postgis for the keg version of Postgresql#9.6 and use CREATE EXTENSION postgis;
This isn't a Homebrew solution but after a lot of searching, it finally allowed me to use Postgis.
HelloI ran into this same problem of multiple implementation of pgsql versions including legacy ones. So after a bit of research I would like to share my solution.
Problem:
I am working on a macbook pro 2013 with 10.11 el capitan. I am GIS developer and extensive user of homebrew. I didn't pin the postgresql package for compatibility reasons. Thus, the package got updated to postgresql version 10.5 along other packages. This caused me to be unable to use postgresql version 9.4. The cleverest solution would have been to use a brew switch postgresql 9.4.19. Except that when compiling postgis 2.5.0 from osgeo/osgeo4mac it defautls (looks for) the postgresql binary folder to install the symlinked (or not) extensions. Here again another compatibility problem. One could tinker a bit with homebrew files and transfer files manually. That's ill advice...the package manager (homebrew) needs to stay a coherent ecosystem to provide for a stable workspace.
Proposed Solution:
Go here BigSQL and download the dmg of your chosen version
install the software where you want in your filesystem
within the installation folder you'll find a directory named pg9x ; x being the version number (e.g pg95 for postgresql 9.5 and so on...
in this folder you'll find a file named pg9x.env
source this file to your .profile with source /your/path/pg9x/pg9x.env line
in the main installation folder, for instance /your/path/pg9x/, you'll finde a python script called pgc, alias it to your .profile with alias pgc="your/path/pgc"
save your .profile and refresh your environment variable with source .profile on the command prompt
still within the command prompt, type pgc list, you'll get a list of installed packages. You'll see the version of postgesql you've downloaded
to install another version of postgresql, say 9.6, type pgc install pg96
to install postgis for pg95 type pgc install postgis22-pg95
to install postgis for pg96 type pgc install postgis23-pg96
now, after installation you'll need to initialize the downloaded component with pgc init pg96 or pgc init postgis23-pg96 etc...
to check if your daemon is running correctly type pgc status
to start a version daemon of your choice type for example pgc start pg95
to stop a version daemon of your choice type pgc stop pg95
the installation also comes with an LTS release of pgadmin3 that works fine with all versions (not the case of brew version of pgadmin3), this is very convenient
type pgc help for more options
Let the elephant dance^^
Hope this helps.
Spicy.
I faced a similar issue and what worked for me was to follow the instructions at https://github.com/CloverHealth/homebrew-tap, which seem similar in spirit to #Antwan's solution but with a few more clean up steps, also it gets slightly later versions: postgresql 9.6.10 and postgis 2.5.
My steps differed slightly from those at CloverHealth: My brew version no longer supports brew switch postgresql 9.6.10 and I tried first brew link postgresql#9.6.10 and then brew link postgresql#9.6 but both gave
Error: no such keg
Trying brew search postgresql showed a little green checkmark next to the cloverhealth Formulae, so I tried brew link cloverhealth/tap/postgresql and got
Warning: Already linked: /usr/local/Cellar/postgresql/9.6.10
So, ok it was already linked. Other than that my steps were the same as described at the CloverHealth page, and now I'm up and running again.