简体   繁体   中英

Cannot createdb in postgresql

I'm trying to start a Ruby on Rails app with PostgreSQL as the database because once this site is finished I'll be promoting it to another blog that has 259K followers and I just want to anticipate if the user base for my new website gets big.

Anyway I followed this tutorial: https://gorails.com/setup/osx/10.11-el-capitan at first. But when I made my app with PostgreSQL the database would fail to create.

So I stepped back, tried uninstalling and reinstalling postgres, I updated my homebrew, and now I'm following this new tutorial: https://www.codefellows.org/blog/three-battle-tested-ways-to-install-postgresql#macosx

I'm at the step: Create a Default db Based on Your Username.

I run the command and get this:

Mayas-MacBook-Air:~ mayaah$ which psql
/usr/local/bin/psql
Mayas-MacBook-Air:~ mayaah$ createdb `whoami`
createdb: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

I don't know what to do from here. I've googled this problem extensively and couldn't find an answer. The only possible problem I can think of is my Mac has very little space left, as I saw something about "shared space" which I don't really understand.

Any insight into this, especially with specific step-by-step command line instructions would be super helpful. Thanks!

Edit: Now I found this tutorial: http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/

Tried to run

postgres -D /usr/local/var/postgres

Got this:

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.5.

I don't know what to do from here either.

At first, you installed PostgreSQL version 9.3, then you uninstalled it and installed version 9.4. But some old files stayed there and PostgreSQL 9.4 is not compatible with them. If you don't need any data of 9.3 version then you can remove them and initialize new settings for 9.4 version:

rm -rf /usr/local/var/postgres
initdb /usr/local/var/postgres -E utf8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM