I get segfault GHCI when I try to create a database connection in GHCI with postgresql-simple.
I am using GHC 8.0.1, OSX 10.11.16. I do not have a system GHC, only the one that has the stack installed.
If the following is done in my project:
$ 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
I thought it was worth looking at this file that he mentions, so here is the content:
> 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
This is a list of all the modules loaded from the project (which compiles and works fine).
Here's the complete output of everything from ghci to seg fault:
$ 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
Additional Information
Postgresql Version: 9.5 installed using the EnterpriseDB installer
The request to publish my stack.yaml (which below) reminded me of the problem I had when trying to install postgresql-libpq . This is probably related.
Stack.yaml
# This file was automatically generated by stack init
Also segfaults on GHC 7.10.3 using resolver lts-6.17
gchi> conn <- connectPostgreSQL connstr zsh: segmentation fault stack ghci --resolver lts-6.17
I have an idea
I think the version of postgresql-libpq that I use was built using libiconv.2.dylib compiled for Postgresql 9.4 , but the database I'm trying to connect to is actually Postgresql 9.5 . This may be causing my problem.
The thing that I inspired with this idea
Here are a few steps that I took to try to debug further actions and / or fix it. I first linked the Postgresql 9.5 *dylib in my /usr/local/lib directory to replace the old Postgresql 9.4 version related ones.
$ cd /usr/local/lib $ sudo ln -s -f /Library/PostgreSQL/9.5/lib/*dylib .
After that, I tried to get stack rebuild postgresql-libpq and postgresql-simple as follows:
$ 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
At what point did he promise me that he would create and configure remote packages. However, despite the fact that I ran higher, I still broke off.