haskell - 使用 postgresql-simple 创建数据库连接时的 GHCI Segfault

标签 haskell ghci haskell-stack

尝试使用 postgresql-simple 在 GHCI 中创建数据库连接时出现 GHCI 段错误。

我正在使用 GHC 8.0.1、OSX 10.11.16。我没有系统 GHC,只有堆栈安装的一个。

如果我在我的项目中执行以下操作,则会出现段错误:

$ stack ghci
Loaded GHCi configuration from /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci62972/ghci-script
gchi> :set -XOverloadedStrings
gchi> import Database.PostgreSQL.Simple
gchi> let connstr = "host=localhost port=5432 user=myusername password=mypass dbname=local"
gchi> conn <- connectPostgreSQL connstr
zsh: segmentation fault  stack ghci

我认为可能值得看一下它提到的那个文件,所以这里是内容:
> cat /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci62972/ghci-script
:load "/Users/erewok/projects/haskell/simpleservantblog/app/Main.hs" "Api" "Api.Post" "Api.User" "Config" "Html.Home" "Models.Author" "Models.Post"
:module + Api Api.Post Api.User Config Html.Home Models.Author Models.Post

它是从项目加载的所有模块的列表(编译和运行良好)。

这是从 ghci 开始的所有内容的完整输出直到段错误:
$ stack ghci
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Using main module: 1. Package `simpleservantblog' component exe:simpleservantblog-exe with main-is file: /Users/erewok/projects/haskell/simpleservantblog/app/Main.hs
Configuring GHCi with the following packages: simpleservantblog
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/erewok/.ghci
[1 of 8] Compiling Models.Author    ( /Users/erewok/projects/haskell/simpleservantblog/src/Models/Author.hs, interpreted )
[2 of 8] Compiling Models.Post      ( /Users/erewok/projects/haskell/simpleservantblog/src/Models/Post.hs, interpreted )
[3 of 8] Compiling Html.Home        ( /Users/erewok/projects/haskell/simpleservantblog/src/Html/Home.hs, interpreted )
[4 of 8] Compiling Api.User         ( /Users/erewok/projects/haskell/simpleservantblog/src/Api/User.hs, interpreted )
[5 of 8] Compiling Api.Post         ( /Users/erewok/projects/haskell/simpleservantblog/src/Api/Post.hs, interpreted )
[6 of 8] Compiling Config           ( /Users/erewok/projects/haskell/simpleservantblog/src/Config.hs, interpreted )
[7 of 8] Compiling Api              ( /Users/erewok/projects/haskell/simpleservantblog/src/Api.hs, interpreted )
[8 of 8] Compiling Main             ( /Users/erewok/projects/haskell/simpleservantblog/app/Main.hs, interpreted )
Ok, modules loaded: Api, Config, Api.Post, Api.User, Html.Home, Models.Post, Models.Author, Main.
Loaded GHCi configuration from /private/var/folders/wb/vvtxjd7n2qz02f571yjyr9j40000gs/T/ghci64266/ghci-script
gchi> :set -XOverloadedStrings
gchi> import Database.PostgreSQL.Simple
gchi> let connstr = "host=localhost port=5432 user=myusername password=mypass dbname=local"
gchi> conn <- connectPostgreSQL connstr
zsh: segmentation fault  stack ghci

更多信息

Postgresql 版本:9.5,使用 EnterpriseDB installer 安装

发布我的 stack.yaml(如下)的请求让我想起了我在 trying to install postgresql-libpq 时遇到的问题。 .这可能是相关的。

堆栈.yaml
# This file was automatically generated by stack init
# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: nightly-2016-08-25

# Local packages, usually specified by relative directory name
packages:
- '.'
- location:
    git: https://www.github.com/mattjbray/elm-export
    commit: 8868c1f09597f44c2e18e014cd9fbcf8320c3fea
  extra-dep: True
- location:
    git: https://www.github.com/mattjbray/servant-elm
    commit: e13c8def8127ea339e9801d804638854947193e8
  extra-dep: True
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps:
  - wai-make-assets-0.1.1

# Override default flag values for local packages and extra-deps
flags: {}

# Extra package databases containing global packages
extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true


# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
extra-lib-dirs: [/usr/local/opt/libiconv/lib, /usr/local/lib, /usr/lib]

带有解析器 lts-6.17 的 GHC 7.10.3 上还有段错误
gchi> conn <- connectPostgreSQL connstr
zsh: segmentation fault  stack ghci --resolver lts-6.17

我有一个想法

我认为 postgresql-libpq 的版本我使用的是用 libiconv.2.dylib 构建的为 编译PostgreSQL 9.4 ,但我尝试连接的数据库实际上是 PostgreSQL 9.5 .这可能是我的问题的原因。

受这个想法启发我做的一件事

以下是我为尝试进一步调试和/或修复此问题而采取的一些步骤。我首先链接了 Postgresql 9.5 *dylib文件到我的/usr/local/lib目录以替换与 Postgresql 9.4 版本链接的旧目录。
$ cd /usr/local/lib
$ sudo ln -s -f /Library/PostgreSQL/9.5/lib/*dylib .

之后,我尝试强制 stack重建postgresql-libpqpostgresql-simple这样:
  $ stack exec -- ghc-pkg unregister --force postgresql-simple
  $ stack exec -- ghc-pkg unregister --force postgresql-libpq
  $ rm -rf ~/.stack/precompiled/x86_64-osx/ghc-8.0.1/1.24.0.0/postgresql-libpq-0.9.1.1/
  $  rm -rf ~/.stack/precompiled/x86_64-osx/ghc-8.0.1/1.24.0.0/postgresql-simple-0.5.2.*
  $ stack build

那时,它向我 promise 它将构建和配置已删除的软件包。但是,当我运行上述内容时仍然存在段错误。

最佳答案

在尝试为我的问题生成堆栈跟踪时,我发现我可以通过以下方式启动 ghci:

$ stack ghci --ghci-options -fexternal-interpreter

然后,无论出于何种原因,段错误都没有出现,一切都按预期工作。我不知道其他人是否会觉得这很有用。

对我来说似乎很奇怪的是,在编译和运行代码时我没有遇到问题。我只在 GHCI 中遇到了问题。

无论如何,在我发现更多或有人有更好的建议之前,我会继续这样做,这样我就可以继续在 REPL 中测试我想要的东西。

关于haskell - 使用 postgresql-simple 创建数据库连接时的 GHCI Segfault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39440416/

相关文章:

haskell - 在 Yampa 程序中获取 "parse error on input ‘<-’

haskell - 四舍五入到最接近的整数奇怪的结果

Haskell 数据类型的使用

haskell - 没有 (Show ([(Char, Char)] -> Char)) 的实例

haskell - 如何使用 Stack/Cabal 构建早期部分的程序输出作为同一构建后续部分的源?

haskell - Haskero 失败并显示 "Not a valid Unicode code point!"

haskell - 如何在亚马逊网络服务上托管 haskell 应用程序?

Haskell 来自 First Principles Ch5, Ex 7,8

haskell - 访问 Haskell 函数中的命名字段

windows - 当使用堆栈构建时,有没有办法在 powershell 终端上正确格式化 GHC 错误消息?