How to brew uninstall postgres on OX Sierra - postgresql

Reading from the here, I want to uninstall postgres completely with homebrew and have used brew uninstall postgresql but I get this response.
No such keg: /usr/local/Cellar/postgresql
I know postgres is running because when I run ps auxwww | grep postgres I see /usr/local/opt/postgresql94/bin/postgres -D /usr/local/var/postgres. What am I doing wrong? I have mac Sierra

I installed postgres using homebrew. I uninstalled it using the following steps:
Run the following command and look for the correct name something like postgresql94, postgres, postgresql#13. Name may varies, you have to check accordingly. In my case it was postgresql94.
brew list
After finding the correct name, run the following command to uninstall postgres. You have to replace postgresql94 with the name you found in the above mentioned command:
brew uninstall postgresql94
That should do the uninstall.
Shortcut command for the same is
brew list | grep postgres | xargs brew uninstall

Related

Unable to reinstall postgresql on mac

I'm trying to reset postgreSQL but looks like it is stuck on Mac M1 with a password and every time that I uninstall and reinstall postgreSQL it is remembering the previously set password.
So when I run brew uninstall postgresql and then brew install postgresql it is not fixing the problem.
I tried to delete the /tmp/.s.PGSQL but it looks like that makes it worse because now can't find this file even on the reinstall.
So what is the proper way to completely remove postgreSQL from a Mac M1 and then reinstall it from 0.
Disclaimer: Make sure you backup your db's in case you need them later because running these commands will delete all your local Postgres databases.
First you need to run:
$ brew uninstall postgres
$ rm -rf /usr/local/var/postgres
$ rm /usr/local/var/log/postgres.log
$ rm -f ~/.psqlrc ~/.psql_history
If you want to make sure there are no other Postgres-adjacent Homebrew formulae still installed you can eihter check via:
$ brew list --formula | grep -e postgres -e psql
or search your entire system for file name matches:
$ sudo find / -name "*postgres*" -o -name "*psql*"
Before reinstalling postgreSQL it might be a good time to reboot your machine. After the reboot run the following commands to get your fresh installation of postgreSQL:
Make sure your Homebrew is fully updated and give Homebrew a chance to diagnose any problems:
$ brew update
$ brew doctor
The diagnostic command $ brew doctor should exit cleanly with the simple message 'Your system is ready to brew.'
Now you can reinstall postgreSQL and see if it runs via:
$ brew install postgres
$ brew services start postgresql
Source: https://blog.testdouble.com/posts/2021-01-28-how-to-completely-uninstall-homebrew-postgres/

Could not load library /usr/local/lib/postgresql/plpgsql.so .. undefined symbol "MakeExpandedObjectReadOnly"

What I'm trying to do is to convert this installing script for webodm (https://gist.github.com/lkpanganiban/5226cc8dd59cb39cdc1946259c3fea6e) written in bash to be used in tcsh shell under a freenas jail.
I have now enter at part where I can't find a solution to and my hope is that someone can en light me what to do next.
The line that is triggering the problem is :
su - postgres -c "psql -d webodm_dev -c "\""CREATE EXTENSION postgis;"\"" "
The whole error line :
ERROR: could not load library "/usr/local/lib/postgresql/plpgsql.so": dlopen (/usr/local/lib/postgresql/plpgsql.so) failed: /usr/local/lib/postgresql/plpgsql.so: Undefined symbol "MakeExpandedObjectReadOnly"
pkg info give :
postgis24-2.4.5_1 Geographic objects support for PostgreSQL databases
postgresql95-client-9.5.15_2 PostgreSQL database (client)
postgresql95-contrib-9.5.15_2 The contrib utilities from the PostgreSQL distribution
postgresql95-server-9.5.15_2 PostgreSQL is the most advanced open-source database available anywhere
And yes the file exists:
root#webodm2:~ # ls -l /usr/local/lib/postgresql/plpgsql.so
-rwxr-xr-x 1 root wheel 195119 Feb 7 18:16 /usr/local/lib/postgresql/plpgsql.so
root#webodm2:~ #
So anyone have some idea ?
I faced this issue after the upgrade from postgres 11 to 12, here how to fix it for Linux and Mac (without brew)
$ sudo su postgres
$ /usr/lib/postgresql/12/bin/pg_upgrade \
--old-datadir=/var/lib/postgresql/11/main \
--new-datadir=/var/lib/postgresql/12/main \
--old-bindir=/usr/lib/postgresql/11/bin \
--new-bindir=/usr/lib/postgresql/12/bin \
--old-options '-c config_file=/etc/postgresql/11/main/postgresql.conf' \
--new-options '-c config_file=/etc/postgresql/12/main/postgresql.conf' \
you can add --check to do a dry test upgrade without changing anything in your postgres installation.
for Mac users with brew installation:
after the upgrade run the following command"
$ brew postgresql-upgrade-database
That error message means that you have a plpgsql.so from PostgreSQL 9.5 or earlier and try to use it with PostgreSQL 9.6 or later.
Either you are picking up the wrong library, or you copied files around.
Anyway, the problem has nothing to do with PostGIS.
It might be your database has an outdated version, try to run the checks before running brew postgresql-upgrade-database. OR try to restart your service brew services restart postgres.
psql --version # 11.4 <--- psql cli version
psql -c 'select version();' postgres # 10.2 <--- db version in storage
brew info postgres # check pg info <--- found solution
brew postgresql-upgrade-database # upgrade db version in storage and fixed the issue

Install Marklogic in ubuntu 16.04?

I want to install MarkLogic 9 on my ubuntu machine. I tried following steps from this doc
sudo apt-get install alien
sudo alien --to-deb --verbose MarkLogic-9.0-3.1.x86_64.rpm
sudo dpkg -i marklogic_4.1-6_amd64.deb
sudo /etc/init.d/MarkLogic start
But when I tried the second one I got an error like this:
iama#learner:~$ sudo alien --to-deb --verbose MarkLogic-9.0-3.1.x86_64.rpmFile "MarkLogic-9.0-3.1.x86_64.rpm" not found.
I don't know how to proceed further. I just wanted to confirm, is there any official documentation to install MarkLogic 9 in ubuntu?
The error is "File Not Found"
Make sure the rpm file exists in the current directory with read privileges with the name given.
Make sure sudo is not changing to another directory.
To be certain, use an absolute file path.
Then, test with sudo ls -l file..

How do I correct the mismatch of psql version and postgresql version?

Somewhere along the line I have ended up with a version mismatch between postgresql-9.4 and psql which is version 9.3 despite the fact that version 9.4 is installed.
I think I need to correct the $PATH variable but I don't know where to find this. I've looked in my /etc/.bashrc file and can't see anything that points me in the right direction.
When I do sudo find / -name psql the result is:
/usr/bin/psql
/usr/share/bash-completion/completions/psql
/usr/pgsql-9.4/bin/psql
yum list installed | grep postgres yields the following:
postgresql.x86_64 9.3.9-1.fc21 #updates
postgresql-contrib.x86_64 9.3.9-1.fc21 #updates
postgresql-devel.x86_64 9.3.9-1.fc21 #updates
postgresql-libs.x86_64 9.3.9-1.fc21 #updates
postgresql-server.x86_64 9.3.9-1.fc21 #updates
postgresql94.x86_64 9.4.5-1PGDG.f21 #pgdg94
postgresql94-libs.x86_64 9.4.5-1PGDG.f21 #pgdg94
postgresql94-server.x86_64 9.4.5-1PGDG.f21 #pgdg94
As Craig Ringer answered - generally you should use:
sudo update-alternatives --config pgsql-psql
Nevertheless, sometimes you can get such message back:
failed to link /usr/bin/psql -> /etc/alternatives/pgsql-psql: /usr/bin/psql exists and it is not a symlink
If so - try:
ln -s /usr/pgsql-[PUT YOUR VERSION HERE(ex. 9.6)]/bin/psql /usr/local/bin/psql
Use the alternatives mechanism. On Fedora:
sudo update-alternatives --config pgsql-psql
You're apparently using CentOS or RHEL.
In this case, you might: 1) invoke psql with the full path or 2) replace the current psql in the alternatives by executing the following command as root:
update-alternatives --install /usr/bin/psql pgsql-psql /usr/pgsql-9.4/bin/psql 1
A tip: use updatedb and locate instead of find whenever looking for a file or directory. :D

Postgresql 9.2 pg_dump version mismatch

I am trying to dump a Postgresql database using the pg_dump tool.
$ pg_dump books > books.out
How ever i am getting this error.
pg_dump: server version: 9.2.1; pg_dump version: 9.1.6
pg_dump: aborting because of server version mismatch
The --ignore-version option is now deprecated and really would not be a a solution to my issue even if it had worked.
How can I upgrade pg_dump to resolve this issue?
Check the installed version(s) of pg_dump:
find / -name pg_dump -type f 2>/dev/null
My output was:
/usr/pgsql-9.3/bin/pg_dump
/usr/bin/pg_dump
There are two versions installed. To update pg_dump with the newer version:
sudo ln -s /usr/pgsql-9.3/bin/pg_dump /usr/bin/pg_dump --force
This will create the symlink to the newer version.
I encountered this while using Heroku on Ubuntu, and here's how I fixed it:
Add the PostgreSQL apt repository as described at "Linux downloads (Ubuntu)
". (There are similar pages for other operating systems.)
Upgrade to the latest version (9.3 for me) with:
sudo apt-get install postgresql
Recreate the symbolic link in /usr/bin with:
sudo ln -s /usr/lib/postgresql/9.3/bin/pg_dump /usr/bin/pg_dump --force
The version number in the /usr/lib/postgresql/... path above should match the server version number in the error you received. So if your error says, pg_dump: server version: 9.9, then link to /usr/lib/postgresql/9.9/....
Macs have a builtin /usr/bin/pg_dump command that is used as default.
With the postgresql install you get another binary at /Library/PostgreSQL/<version>/bin/pg_dump
You can just locate pg_dump and use the full path in command
locate pg_dump
/usr/bin/pg_dump
/usr/bin/pg_dumpall
/usr/lib/postgresql/9.3/bin/pg_dump
/usr/lib/postgresql/9.3/bin/pg_dumpall
/usr/lib/postgresql/9.6/bin/pg_dump
/usr/lib/postgresql/9.6/bin/pg_dumpall
Now just use the path of the desired version in the command
/usr/lib/postgresql/9.6/bin/pg_dump books > books.out
You can either install PostgreSQL 9.2.1 in the pg_dump client machine or just copy the $PGHOME from the PostgreSQL server machine to the client machine. Note that there is no need to initdb a new cluster in the client machine.
After you have finished installing the 9.2.1 software, remember to edit some environment variables in your .bash_profile file.
If you're on Ubuntu, you might have an old version of postgresql-client installed. Based on the versions in your error message, the solution would be the following:
sudo apt-get remove postgresql-client-9.1
sudo apt-get install postgresql-client-9.2
If you have docker installed you can do something like:
$ docker run postgres:9.2 pg_dump books > books.out
That will download the Docker container with Postgres 9.2 in it, run pg_dump inside of the container, and write the output.
On Ubuntu you can simply add the most recent Apt repository and then run:
sudo apt-get install postgresql-client-11
Every time you upgrade or re install a new version of PostgreSQL, a latest version of pg_dump is installed.
There must be a PostgreSQL/bin directory somewhere on your system, under the latest version of PostgreSQL that you've installed ( 9.2.1 is latest) and try running the
pg_dump from in there.
For those running Postgres.app:
Add the following code to your .bash_profile:
export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
Restart terminal.
For Macs with Homebrew. I had this problem when fetching the db from Heroku. I've fixed it just running:
brew upgrade postgresql
For mac users
put to the top of .profile file.
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
then run
. ~/.profile
An alternative answer that I don't think anyone else has covered.
If you have multiple PG clusters installed (as I do), then you can view those using pg_lsclusters.
You should be able to see the version and cluster from the list displayed.
From there, you can then do this:
pg_dump --cluster=9.6/main books > books.out
Obviously, replace the version and cluster name with the appropriate one for your circumstances from what is returned by pg_lsclusters separating the version and cluster with a /. This targets the specific cluster you wish to run against.
For me the issue was updating psql apt-get wasn't resolving newer versions, even after update. The following worked.
Ubuntu
Start with the import of the GPG key for PostgreSQL packages.
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Now add the repository to your system.
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
Install PostgreSQL on Ubuntu
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
https://www.postgresql.org/download/linux/ubuntu/
As explained, this is because your postgresql is in old version -> update it
For Mac via homebrew:
brew tap petere/postgresql,
brew install <formula> (eg: brew install petere/postgresql/postgresql-9.6)
Remove old postgre:
brew unlink postgresql
brew link -f postgresql-9.6
If any error happen, don't forget to read and follow brew instruction in each step.
Check this out for more: https://github.com/petere/homebrew-postgresql
The answer sounds silly but if you get the above error and wanna run the pg_dump for earlier version go to bin directory of postgres and type
./pg_dump servername > out.sql ./ ignores the root and looks for pg_dump in current directory
I had same error and this is how I solved it in my case.
This means your postgresql version is 9.2.1 but you have started postgresql service of 9.1.6.
If you run psql postgres you will see:
psql (9.2.1, server 9.1.6)
What I did to solve this problem is:
brew services stop postgresql#9.1.6
brew services restart postgresql#9.2.1
Now run psql postgres and you should have: psql (9.2.1)
You can also run brew services list to see the status of your postgres.
This worked for me, a collection of solutions from above and other sites. If you specified a version like postgressql-client-11 before then you need to remove that version first.
sudo apt-get remove -y postgresql-client
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-12
I was facing the same issue. I used docker instead of upgrading pg_dump.
run following command to create a Docker container of postgres 14.2, or any other version as you like.
sudo docker run --name mac_postgres -p 5444:5432 -e POSTGRES_PASSWORD=password -d postgres:14.2
Then take dump using following command. Note: you should change the host, port, username and password according to your actual database credentials.
sudo docker exec -it mac_postgres pg_dump --host=xxxxx0.b.db.ondigitalocean.com --port=250xx --username=doadmin --dbname=test --password > out.sql
After entering password. Your dump will be ready in out.sql file. Then you can delete the docker-container.
sudo docker stop mac_postgres
sudo docker rm mac_postgres
If you're using Heroku's Postgres.app the pg_dump (along with all the other binaries) is in /Applications/Postgres.app/Contents/MacOS/bin/
so in that case it's
ln -s /Applications/Postgres.app/Contents/MacOS/bin/pg_dump /usr/local/bin/pg_dump
or
ln -s /Applications/Postgres.app/Contents/MacOS/bin/* /usr/local/bin/.
to just grab them all
** after install postgres version is match(9.2)
Create a symbolic link or new shortcut
**- on '/usr/bin'
syntag is = sudo ln -s [path for use] [new shortcut name]
example
sudo ln -s /usr/lib/postgresql/9.2/bin/pg_dump new_pg_dump
-- how to call : new_pg_dump -h 192.168.9.88 -U postgres database
Try that:
export PATH=/usr/local/bin:$PATH
If the database is installed on a different machine it has probably correct version of pg_dump installed. This means that you can execute pg_dump command remotely with SSH:
ssh username#dbserver pg_dump books > books.out
You can also use public key authentication for passwordless execution. Steps to achieve that:
Generate (if not yet done) a pair of keys with ssh-keygen command.
Copy the public key to the database server, usually ~/.ssh/authorized_keys.
Test if the connection works with ssh command.
Well, I had the same issue as I have two postgress versions installed.
Just use the proper pg_dump and you don't need to change anything, in your case:
$> /usr/lib/postgresql/9.2/bin/pg_dump books > books.out
For macs, use find / -name pg_dump -type f 2>/dev/null find the location of pg_dump
For me, I have following results:
Applications/Postgres.app/Contents/Versions/9.5/bin/pg_dump
/usr/local/Cellar/postgresql/9.4.5_2/bin/pg_dump
If you don't want to use sudo ln -s new_pg_dump old_pg_dump --force, just use:
Applications/Postgres.app/Contents/Versions/9.5/bin/pg_dump to replace with pg_dump in your terminal
For example:
Applications/Postgres.app/Contents/Versions/9.5/bin/pg_dump books > books.out
It works for me!
On my scenario the production version was 12, and my development version was 11, upgrading the package postgresql-client-xx was enough to solve my incident.
Reference web page : https://www.postgresql.org/download/linux/ubuntu/
sudo apt-get update && sudo apt-get -y upgrade postgresql-client
One interest thing to point out is that after the upgrade the previous version kept installed :
mlazo#mlazo-pc:~$ dpkg -l |grep -i postgresql-client
ii postgresql-client-11 11.8-1.pgdg18.04+1 amd64 front-end programs for PostgreSQL 11
ii postgresql-client-12 12.4-1.pgdg18.04+1 amd64 front-end programs for PostgreSQL 12
Hope my experience would be helpful to someone.
Greetings,
I had the same message, for me it was that I had to adjust the following:
export LD_LIBRARY_PATH=/usr/pgsql-12/lib:....
export LD_RUN_PATH=/usr/pgsql-12/lib:.....
First step: see if postgres has a repository with prebuilt binaries for the version you want for your OS: https://www.postgresql.org/download/
If that doesn't work (for instance if your distro is there but is no longer supported, so correct binaries aren't provided for it), or if you just want to go straight or the source and not have to worry about adding remote repo's, etc.
What I did is download the raw source of postgres for the desired version.
Untar it, cd into it, build it ./configure && make, then:
postgresql-12.3 $ find . -name pg_dump
./src/bin/pg_dump/pg_dump
$ ./src/bin/pg_dump/pg_dump
unable to load libpg.so.5 # if it says this...
$ find . -name libpg.so.5
$ export LD_LIBRARY_PATH=/your/path/to/the/shared/dir/of/above/file
$ ./src/bin/pg_dump/pg_dump # works now
Now you have access to any version that builds on your box. Which should be any.
Full steps tutorial
Your local version needs to match the one used by AWS on the remote server.
Unfortunately, apt-get install will lag behind the official release.
So you need to proceed the following way:
sudo apt-get remove postgresql
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 -
Then check your error message should be something like
pg_dump: server version: 12.3; pg_dump version: 10.16 (Ubuntu 10.16-0ubuntu0.18.04.1)
So it means you want version 12 (and not 13), for the install of the matching version by specifying the version number (without minor) during your fresh install:
sudo apt-get -y install postgresql-12
Now it works:
pg_dump -h {{endpoint}} -U {{username}} -f dump.sql {{tablename}}
NB: You get the endpoint in Connectivity & security go to https://us-east-2.console.aws.amazon.com/rds/home?region=us-east-2 and click on your DB instance
For Ubuntu 20.04 with the "official" postgresql repo, moving from pg12 to pg13, I had to do this:
sudo apt purge postgresql-12
This was very hard for me to pinpoint. I had played with a variety of these packages:
postgresql-client
postgresql-client-common
postgresql-##
postgresql-client-##
postgresql-server-dev-##
pgadmin