3

How do I specify which version of postgres rails use? When I run puma and go to localhost:3000 I get a an error

PG::ConnectionBad
fe_sendauth: no password supplied

I think the copy being used may be the manual install 9.3, as when I run:

/usr/local/Cellar/postgresql/9.4.1/bin/pg_ctl -D /usr/local/var/postgres start

I get the error:

stgres start
server starting
LOG:  skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.1.

I found three copies of pg_hba.conf on my system:

/Library/PostgreSQL/9.3/data/pg_hba.conf
/Users/lasernite/Library/Application Support/Postgres/var-9.4/pg_hba.conf
/usr/local/var/postgres/pg_hba.conf

The first one I believe was from a manual install at some point. The second one is probably just some supporting copy/ignorable, and the third one is a homebrew install.

How can I make rails use the homebrew postgres install, even if it means wiping the local database? Which is fine so long as the production on heroku is instact.

I've been stuck for several days on reconfiguring my development environment from sqlite to postgres, which is very problematic as I have a production db and site live now, which is forcing me to do some code pushes without being able to verify functionality locally, but for the most part has totally crippled my ability to do any development.

Please help me!

1 Answer 1

13

It looks like the problem is that you're starting 9.4.1 when the database was created by 9.3.x.

The version of posgres that Rails uses should be whichever one is running. So if you want to start postgres in version 9.3.x, then you should start that version. But you have to specify the correct path for that version.

What output do you get for these?

> initdb --version
> pg_ctl --version
> postgres --version
> psql --version

It should all be the same. If it says 9.4.x and you want to use that version, then you can re-init the database like so: initdb -D /usr/local/var/postgres-4.1 and then you can start postgres postgres -D /usr/local/var/postgres-4.1. Doing it this way, you'll probably lose your local database since it sounds like that data was created by 9.3.x.

Alternatively, if those output 9.3.x, then you should just be able to use the commands without the full path to the binary: postgres -D /usr/local/var/postgres.

If you're using 9.4.x and you want to keep using 9.3.x, then try which postgres. It's probably pointing to /usr/local/bin. Then make sure that that is just a link to the homebrew version. ls -la /usr/local/bin | grep "postgres ->".

If you're using the homebrew version, you can do brew switch postgres 9.3.x to tell homebrew to use that version. Then you should be able to start postgres with postgres -D /var/local/var/postgres.

Sign up to request clarification or add additional context in comments.

10 Comments

So it says I'm using 9.4.1, so I was able to re-init it, but then when trying to start it with postgres -D /usr/local/var/postgres-4.1 I get LOG: could not bind IPv4 socket: Address already in use HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. LOG: could not bind IPv6 socket: Address already in use HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv6 socket: Address already in use HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. WARNING: could not create listen socket for "localhost" FATAL: could not create any TCP/IP sockets So how would I shut down this other postmaster/is it another postgres running? Thanks!
Ah cool. That's easy. Just ps aux | grep postgres, find the pid and kill -9 it.
The proper way to do it is probably pg_ctl -D /usr/local/var/postgres stop. But killing it means you don't have to know the path to the config.
Yeh I tried pg_ctl -D /usr/local/var/postgres stop -s -m fast but got pg_ctl: PID file "/usr/local/var/postgres/postmaster.pid" does not exist Is server running? which confused me since I thought the issue that it's running? And does 'kill -9' mean remove the file or?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.