【问题标题】:Cannot createdb in postgresql无法在 postgresql 中创建数据库
【发布时间】:2016-04-05 03:28:09
【问题描述】:

我正在尝试使用 PostgreSQL 作为数据库启动一个 Ruby on Rails 应用程序,因为一旦这个站点完成,我将把它推广到另一个拥有 259K 关注者的博客,我只想预测我的用户群是否新网站变大了。

不管怎样,我首先遵循了这个教程:https://gorails.com/setup/osx/10.11-el-capitan。但是当我使用 PostgreSQL 制作我的应用程序时,数据库将无法创建。

所以我退后一步,尝试卸载并重新安装 postgres,我更新了我的自制软件,现在我正在关注这个新教程: https://www.codefellows.org/blog/three-battle-tested-ways-to-install-postgresql#macosx

我正在执行以下步骤:根据您的用户名创建默认数据库。

我运行命令并得到这个:

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"?

我不知道从这里做什么。我已经广泛搜索了这个问题,但找不到答案。我能想到的唯一可能的问题是我的 Mac 剩下的空间很少,因为我看到了一些我不太了解的“共享空间”。

对此的任何见解,尤其是具体的分步命令行说明都会非常有帮助。谢谢!

编辑: 现在我找到了这个教程:http://exponential.io/blog/2015/02/21/install-postgresql-on-mac-os-x-via-brew/

试图运行

postgres -D /usr/local/var/postgres

知道了:

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.

我也不知道从这里做什么。

【问题讨论】:

  • 似乎 Postgres 没有运行。您是否完成了之前的所有步骤?尝试运行ps aux | grep postgres 看看是否有问题。
  • 我运行它并得到:mayaah 1302 0.0 0.0 2423376 296 s000 R+ 9:55PM 0:00.00 grep postgres我不知道如何解释这个

标签: ruby-on-rails ruby macos postgresql


【解决方案1】:

首先,您安装了 PostgreSQL 9.3 版,然后将其卸载并安装了 9.4 版。但是一些旧文件保留在那里,PostgreSQL 9.4 与它们不兼容。如果您不需要 9.3 版本的任何数据,则可以将其删除并初始化 9.4 版本的新设置:

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

【讨论】:

  • 我做到了。但现在我得到了:Mayas-MacBook-Air:~ mayaah$ postgres -D /usr/local/var/postgres LOG: could not translate host name "localhost", service "5432" to address: nodename nor servname provided, or not known WARNING: could not create listen socket for "localhost" FATAL: could not create any TCP/IP sockets
  • 当我检查时:Mayas-MacBook-Air:~ mayaah$ cat /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 192.168.1.2 server.domain 127.0.0.1 localhost.domain 255.255.255.255 broadcasthost ::1 localhost.domain 对我来说看起来不错。我只是不断遇到越来越多的问题。不过还是谢谢!!
  • 但是您的/etc/hosts 文件中没有localhost。编辑127.0.0.1 localhost.domain 喜欢这样:127.0.0.1 localhost localhost.domain
  • 哇!我认为做到了。我在另一个 stackoverflow 线程上看到了这个修复,但我认为我的已经正确了。下次不要这么自信了哈哈。太感谢了!我认为我的 Rails 应用程序已启动并正常运行(目前)!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-21
  • 1970-01-01
  • 1970-01-01
  • 2020-06-25
  • 2020-03-01
  • 2014-04-10
  • 1970-01-01
相关资源
最近更新 更多