在Windows上运行的Ubuntu bash上设置PostgreSQL

时间:2018-07-17 07:01:42

标签: ruby-on-rails postgresql ubuntu windows-subsystem-for-linux

我最近在Windows上作为Linux子系统运行的Ubuntu bash上安装和设置了滑轨。我能够顺利启动和运行Rails,并在Windows C:/驱动器上创建了一个新的Rails应用程序。我尝试直接从postgresql.org/downloads/windows网站下载PSQL,但是遇到了一些问题,因此我取消了,然后按照this tutorial的Install PostgresQL部分进行操作。唯一的问题是,先前被取消的下载已设置为侦听默认端口5432,并且似乎保留了该端口的位置,因为第二次安装说它必须使用端口5433。

编辑:似乎原始的PSQL已成功安装,如它在程序列表中所示,我能够将其卸载,但确实收到错误警告,指出未删除数据文件夹。卸载并仅安装一个PSQL副本后,运行以下sudo service postgresql start时仍然出现相同的错误。

编辑编辑:我完全卸载了两个版本的PSQL,然后在链接的教程中重新安装了该版本,它摆脱了我遇到的第二个错误。但是,我的“ pg” gem仍未捆绑安装。

完成后,我尝试将现有的Rails应用程序切换到postgresql。我更新了database.yml文件,并将“ pg” gem添加到我的Gemfile中。但是,我无法捆绑安装。当我尝试时,出现此错误:

Fetching pg 1.0.0
Installing pg 1.0.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/pg-1.0.0/ext
/home/<user_profile>/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20180717-4727-vex5p2.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a
client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a
client-side application.
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/<user_profile>/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/pg-1.0.0 for
inspection.
Results logged to
/home/<user_profile>/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/pg-1.0.0/gem_make.out

An error occurred while installing pg (1.0.0), and Bundler cannot continue.
Make sure that `gem install pg -v '1.0.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  pg

编辑:以下已解决,请参阅上面的第二个编辑。

类似地,当我尝试使用sudo service postgresql start从命令行启动postgresql时,我得到以下信息:

$ sudo service postgresql start
 * Starting PostgreSQL 9.5 database server                                                                            * The PostgreSQL server failed to start. Please check the log output:
2018-07-17 14:59:26 DST [4858-1] LOG:  could not bind IPv4 socket: Permission denied
2018-07-17 14:59:26 DST [4858-2] HINT:  Is another postmaster already running on port 5433? If not, wait a few seconds and retry.
2018-07-17 14:59:26 DST [4858-3] WARNING:  could not create listen socket for "localhost"
2018-07-17 14:59:26 DST [4858-4] FATAL:  could not create any TCP/IP sockets

有人知道我的环境中安装PostgresQL出了什么问题以及如何使它在Ubuntu外壳程序上成功运行吗?

1 个答案:

答案 0 :(得分:1)

找到了解决这些问题的方法。

问题#1-'pg'gem未安装 在bash中执行以下操作:

  1. sudo apt-get install libpq-dev
  2. gem安装pg
  3. 捆绑安装

问题#2-PostgreSQL无法启动而不会崩溃

在计算机上的PSQL上卸载所有版本,然后重新安装一个。安装失败和第二个版本共享它们的数据文件夹,并导致我正在使用的安装出现错误。