diff --git a/Database/PostgreSQL/LibPQ.hsc b/Database/PostgreSQL/LibPQ.hsc
--- a/Database/PostgreSQL/LibPQ.hsc
+++ b/Database/PostgreSQL/LibPQ.hsc
@@ -229,6 +229,10 @@
                                                )
 import qualified Data.ByteString as B
 
+#if __GLASGOW_HASKELL__ >= 700
+import Control.Concurrent (newMVar, tryTakeMVar)
+#endif
+
 -- $dbconn
 -- The following functions deal with making a connection to a
 -- PostgreSQL backend server. An application program can have several
@@ -263,7 +267,7 @@
        if connPtr == nullPtr
            then fail "libpq failed to allocate a PGconn structure"
 #if __GLASGOW_HASKELL__ >= 700
-           else Conn `fmap` FC.newForeignPtr connPtr (pqfinish connPtr)
+           else Conn `fmap` newForeignPtrOnce connPtr (pqfinish connPtr)
 #else
            else Conn `fmap` newForeignPtr p_PQfinish connPtr
 #endif
@@ -276,7 +280,7 @@
        if connPtr == nullPtr
            then fail "libpq failed to allocate a PGconn structure"
 #if __GLASGOW_HASKELL__ >= 700
-           else Conn `fmap` FC.newForeignPtr connPtr (pqfinish connPtr)
+           else Conn `fmap` newForeignPtrOnce connPtr (pqfinish connPtr)
 #else
            else Conn `fmap` newForeignPtr p_PQfinish connPtr
 #endif
@@ -290,6 +294,16 @@
            -- This case may be worth investigating further
            c_PQfinish conn
      fd -> closeFdWith (\_ -> c_PQfinish conn) (Fd fd)
+
+-- | Workaround for bug in 'FC.newForeignPtr' before base 4.6.  Ensure the
+-- finalizer is only run once, to prevent a segfault.  See GHC ticket #7170
+--
+-- Note that 'getvalue' and 'maybeBsFromForeignPtr' do not need this
+-- workaround, since their finalizers are just 'touchForeignPtr' calls.
+newForeignPtrOnce :: Ptr a -> IO () -> IO (ForeignPtr a)
+newForeignPtrOnce ptr fin = do
+    mv <- newMVar fin
+    FC.newForeignPtr ptr $ tryTakeMVar mv >>= maybe (return ()) id
 #endif
 
 -- | Allocate a Null Connection,  which all libpq functions
diff --git a/postgresql-libpq.cabal b/postgresql-libpq.cabal
--- a/postgresql-libpq.cabal
+++ b/postgresql-libpq.cabal
@@ -1,5 +1,5 @@
 Name:                postgresql-libpq
-Version:             0.8.2
+Version:             0.8.2.1
 Synopsis:            low-level binding to libpq
 
 Description:         This is a binding to libpq: the C application
@@ -38,4 +38,4 @@
 source-repository this
   type:     git
   location: http://github.com/lpsmith/postgresql-libpq
-  tag:      v0.8.2
+  tag:      v0.8.2.1
