oma
oma

Reputation: 40920

brew install postgresql (upgrade) error, could not link - dead links to old non-existent version

Warning: Do not start deleting files manually in Terminal unless you've tried everything else first. Manual deletion may caused uninstall and install programs to crash.

This is QA style post, sharing my path to resolve the issue. I'm sure there are better ways

I picked up an older mac air and wanted to set it up for Ruby and Rails training. During the upgrade I had issues with installing postgresql:

➜  ~  brew install postgresql
....
==> Installing postgresql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/postgresql-9.3.5.mountain_lion.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Pouring postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Caveats
...
To reload postgresql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
No such file or directory - /usr/local/Cellar/postgresql/9.2.3/include/server
Error: No such file or directory - /usr/local/Cellar/postgresql/9.2.3/include/server

I'm installing postgresql 9.3.5, I couldn't care less about 9.2.3 not being found!

➜  ~  brew install postgresql
Warning: postgresql-9.3.5 already installed, it's just not linked

but postgres was still broken.

What's the problem?

Upvotes: 10

Views: 29541

Answers (6)

Deus Bacchus
Deus Bacchus

Reputation: 1

You can try this

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &

Upvotes: 0

Dheiva Gandhi
Dheiva Gandhi

Reputation: 1

'/usr/local/Cellar/[email protected]/9.6.21/bin/pg_ctl -D /usr/local/var/[email protected] start && brew services start postgresql' returned me postgre not installed

brew install postgresql returned me not linked

brew services start postgresql returned me root can not be found

psql postgres

Upvotes: -3

codeAligned
codeAligned

Reputation: 189

I ran brew doctor and followed the relevant suggestions. In this case

Warning: The following directories do not exist:/usr/local/include
You should create these directories and change their ownership to your account.
  sudo mkdir -p /usr/local/include
  sudo chown -R $(whoami) /usr/local/include

After that, I was able to run brew link postgresql

Upvotes: 0

oma
oma

Reputation: 40920

brew update 
brew doctor

is always first steps.

to help finding files, update the files db

sudo /usr/libexec/locate.updatedb

this is similar to updatedb on ubuntu and you might want to alias it.

then you may perform

locate postgresql

and learn more about where things are.

Chances are you made the mistake of deleting the files and folders just like me (sorry, that's a stupid thing to do). What I learn is that then I have a bunch of dead symlinks.

homebrew mostly use /usr/, more specifically /usr/local/bin and puts all source on /usr/local/Cellar, symlink local/bin to Cellar bin

what I did was to hunt down those dead symlinks and kill them over again. unlink.

move into the /usr/local/bin and others in the /usr and do

sudo find . -type l -exec test ! -e {} \; -delete

this test that the target of symlinks exists and delete if not.

To find symlinks in a folder and subfolders do

sudo ls -lR /usr | grep \^l
# and only those pointing to something postgresql:
sudo ls -lR /usr | grep \^l | grep postgresql

that'll get you a step further.

I couldn't even install wget, brew install wget´ because of somewgetrcissue. I found that being a dead symlink/usr/local/etc/wgetrc`

Having cleaned up the symlinks, my system works much better and finally postgresql installed as a charm

➜ brew uninstall postgresql
➜ brew install postgresql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/postgresql-9.3.5.mountain_lion.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Pouring postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/issue/2510

To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
  http://www.postgresql.org/docs/9.3/static/upgrading.html

When installing the postgres gem, including ARCHFLAGS is recommended:
  ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To reload postgresql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
==> /usr/local/Cellar/postgresql/9.3.5/bin/initdb /usr/local/var/postgres
==> Summary
🍺  /usr/local/Cellar/postgresql/9.3.5: 2927 files, 39M

# and in my project
➜ bundle
➜ rake db:create
➜ rake db:migrate
# YEAH!

Upvotes: 7

fronterace
fronterace

Reputation: 31

I had the same problem on Yosemite 10.10.3.

My steps were:

  1. Install latest OS updates
  2. List item
  3. Install updates from xCode
  4. in terminal run command: brew install postgresql
  5. in terminal run command: sudo brew link postgresql
  6. in terminal run command: gem install pg -v '0.18.1'

then bundle install and it's done.

Upvotes: 0

Maxim Vladimirsky
Maxim Vladimirsky

Reputation: 1269

I had the similar problem but with another package. Turned out there had been a bunch of dead links pointing to the old version all other my file system. Here is what helped in my case:

  1. Run brew link <appname> (e.g. brew link postgress);
  2. If completed successfully then you are golden, otherwise proceed with the next step;
  3. Take a look at the path in the error message (e.g. /usr/local/Cellar/postgresql/9.2.3/include/server) transform the path by removing the Cellar/<app name>/<version> from it (e.g. /usr/local/include/server)
  4. Find under that path all links referring to Cellar/<app name>/<version> and remove them;
  5. Goto step 1.

Hope that helps

Upvotes: 13

Related Questions