Upgrading postgresql on redhat failing "version" - postgresql

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.

Related

Troubleshooting PostgreSQL performance issue

I have a data ware house running on PostgreSQL and I would like to check what all are the missing indices are in my database.
I tried to install the extension pg_qualstats but it is giving the below error.
root#Ubuntu-1604-xenial-64-minimal ~ # sudo pip install pg_qualstats
Collecting pg_qualstats
Could not find a version that satisfies the requirement pg_qualstats (from versions: )
No matching distribution found for pg_qualstats
You are using pip version 18.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root#Ubuntu-1604-xenial-64-minimal ~ #
So how can i install this extension? I tried the CREATE EXTENSION pg_qualstats but it was giving error.
Also is there any other database maintenance need to be done for the database regularly?
What all parameter I have to check?
Can we automate the maintenance activity?
I was a SQL server DB admin and it was much easier to find out the missing index, understand the execution plan, DB maintenance but I find it hard, when it comes to PostgreSQL.
So any guidance will be of great help.
I am only answering the immediate question regarding the installation of pg_qualstats - the rest of the questions are way too broad for a platform like stackoverflow (or dba.stackexchange).
Many interesting extensions are provided as source code in Postgres (that's one of the reasons why it's highly recommended to run Postgres on Linux, because compiling the extensions is way easier in Linux than it is on Windows, and may extensions are only developed for Linux).
pg_qualstats is no different.
It is provided together with PoWA and the installation of the extension is documented as part of their installation guide
In a nutshell:
Download the source:
wget https://github.com/powa-team/pg_qualstats/archive/1.0.7.tar.gz -O pg_qualstats-1.0.7.tar.gz
tar zxvf pg_qualstats-1.0.7.tar.gz
cd pg_qualstats-1.0.7
the compile it:
make
make install
Register the shared libraries by editing postgresql.conf and after restarting Postgres the extension can be created using CREATE EXTENSION pg_qualstats;

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

how to install postgresql on Linux

I'm new to Linux and have been using KDE for a little while. I'm working on learning more ruby on rails. The book I'm reading uses postgresql but I cannot find a walkthrough of installing postgresql on KDE. On this page - https://yum.postgresql.org/repopackages.php#pg10 - it doesn't list an rpm for KDE so I'm not sure if there's another one I can use or not. I don't know enough about Linux/KDE yet to know. Does anyone know if I can use any of the packages on that page or if there's another way to install postgresql on KDE?
Simple solution
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
sudo -i -u postgres
psql
So KDE is your desktop. It could be used on almost any operating system, and probably doesn't determine your install. It's more about distros/OS that you're on. So, what OS are you on? Wild guess Fedora or Ubuntu. Here are the install guides for each:
Fedora: https://fedoraproject.org/wiki/PostgreSQL
Ubuntu: https://www.postgresql.org/download/linux/ubuntu/
Neither is as bad as it seems. Just take them step by step.
BTW, in the Linux world the command line is king. At first, this will seem daunting, but after a while, you'll find it faster for many things. Maybe Learn Enough Command Line to Be Dangerous would help.

How do I install older version of postgresql and postgis?

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.