diff --git a/.travis.yml b/.travis.yml
index aa001f0ff523f9a7c275bc1a32cb8aea6f4d68ff..cc0ba0f2c76ca9796f59550c7d83d02d521437be 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,6 +11,7 @@ branches:
 install:
   - sudo apt-get update > /dev/null
   - sudo apt-get -q install binutils-dev python-daemon python-yaml
+  - sudo apt-get -q install libmysqlclient-dev libpq-dev postgresql-server-dev-all
 
 script:
   - mkdir ./build && cd ./build && cmake .. -DCMAKE_BUILD_TYPE=RelWithDebugInfo
diff --git a/client/tarantool/main.c b/client/tarantool/main.c
index 75aa71f83f44c29dc02500f83ef3278e538f0108..15740a4fa8d023e0037e752e49a2237cf57d8993 100644
--- a/client/tarantool/main.c
+++ b/client/tarantool/main.c
@@ -53,7 +53,7 @@ tc_init(void)
 		free(tc.opt.pager);
 	if (tc.opt.delim)
 		free(tc.opt.delim);
-	tc.pager_fd = fileno(stdout);
+	tc.pager_stream = stdout;
 	tc.pager_pid = 0;
 	tb_sesinit(&tc.console);
 }
diff --git a/client/tarantool/main.h b/client/tarantool/main.h
index 1195a2735b4a1cc41801ea0feb0d61a90b15e907..17ada9393daf679de762d46229bcc07520f2fa91 100644
--- a/client/tarantool/main.h
+++ b/client/tarantool/main.h
@@ -40,7 +40,7 @@
 struct tarantool_client {
 	struct tbses console;
 	struct tc_opt opt;
-	int pager_fd;
+	FILE *pager_stream;
 	pid_t pager_pid;
 };
 
diff --git a/client/tarantool/pager.c b/client/tarantool/pager.c
index 8babcca1d793aa50d5c8a5ccf61d768008e33b10..0b0784cf499e7ea0f799f23bd2289b4453d7078c 100644
--- a/client/tarantool/pager.c
+++ b/client/tarantool/pager.c
@@ -45,7 +45,7 @@ void tc_pager_start()
 	if (tc.pager_pid != 0)
 		tc_pager_kill();
 	if (tc.opt.pager == NULL) {
-		tc.pager_fd = fileno(stdout);
+		tc.pager_stream = stdout;
 		return;
 	}
 	int pipefd[2];
@@ -63,7 +63,7 @@ void tc_pager_start()
 		tc_error("Can't start pager! Errno: %s", strerror(errno));
 	} else {
 		close(pipefd[0]);
-		tc.pager_fd = pipefd[1];
+		tc.pager_stream = fdopen(pipefd[1], "w");
 		tc.pager_pid = pid;
 	}
 }
@@ -71,8 +71,8 @@ void tc_pager_start()
 void tc_pager_stop()
 {
 	if (tc.pager_pid != 0) {
-		close(tc.pager_fd);
-		tc.pager_fd = fileno(stdout);
+		fclose(tc.pager_stream);
+		tc.pager_stream = stdout;
 		waitpid(tc.pager_pid, NULL, 0);
 		tc.pager_pid = 0;
 	}
diff --git a/client/tarantool/print.c b/client/tarantool/print.c
index a0042e349cedc6398619032da828bf936e98935a..0e6b4fd50c0f00a6ca06c20267ff6c56c3cf13ce 100644
--- a/client/tarantool/print.c
+++ b/client/tarantool/print.c
@@ -41,23 +41,17 @@
 extern struct tarantool_client tc;
 
 void tc_print_buf(char *buf, size_t size) {
-	printf("%-.*s", (int)size, buf);
-	fflush(stdout);
+	fprintf(tc.pager_stream, "%-.*s", (int)size, buf);
+	fflush(tc.pager_stream);
 }
 
 void tc_printf(char *fmt, ...) {
-	char *str;
 	va_list args;
 	va_start(args, fmt);
-	ssize_t str_len = vasprintf(&str, fmt, args);
-	if (str_len == -1)
-		tc_error("Error in vasprintf - %d", errno);
-	ssize_t stat = write(tc.pager_fd, str, str_len);
-	if (stat == -1)
+	int stat = vfprintf(tc.pager_stream, fmt, args);
+	if (stat < 0)
 		tc_error("Can't write into pager - %d", errno);
 	va_end(args);
-	if (str)
-		free(str);
 	return;
 }
 
diff --git a/cmake/FindPostgreSQL.cmake b/cmake/FindPostgreSQL.cmake
new file mode 100644
index 0000000000000000000000000000000000000000..33702cd67e76fb4efb1f411811fc24df9c6d45a2
--- /dev/null
+++ b/cmake/FindPostgreSQL.cmake
@@ -0,0 +1,165 @@
+# - Find the PostgreSQL installation.
+# In Windows, we make the assumption that, if the PostgreSQL files are installed, the default directory
+# will be C:\Program Files\PostgreSQL.
+#
+# This module defines
+#  PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking
+#  PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers
+#  PostgreSQL_VERSION_STRING - the version of PostgreSQL found (since CMake 2.8.8)
+
+#=============================================================================
+# Copyright 2004-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# ----------------------------------------------------------------------------
+# History:
+# This module is derived from the module originally found in the VTK source tree.
+#
+# ----------------------------------------------------------------------------
+# Note:
+# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
+# version mumber of the implementation of PostgreSQL.
+# In Windows the default installation of PostgreSQL uses that as part of the path.
+# E.g C:\Program Files\PostgreSQL\8.4.
+# Currently, the following version numbers are known to this module:
+# "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
+#
+# To use this variable just do something like this:
+# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
+# before calling find_package(PostgreSQL) in your CMakeLists.txt file.
+# This will mean that the versions you set here will be found first in the order
+# specified before the default ones are searched.
+#
+# ----------------------------------------------------------------------------
+# You may need to manually set:
+#  PostgreSQL_INCLUDE_DIR  - the path to where the PostgreSQL include files are.
+#  PostgreSQL_LIBRARY_DIR  - The path to where the PostgreSQL library files are.
+# If FindPostgreSQL.cmake cannot find the include files or the library files.
+#
+# ----------------------------------------------------------------------------
+# The following variables are set if PostgreSQL is found:
+#  PostgreSQL_FOUND         - Set to true when PostgreSQL is found.
+#  PostgreSQL_INCLUDE_DIRS  - Include directories for PostgreSQL
+#  PostgreSQL_LIBRARY_DIRS  - Link directories for PostgreSQL libraries
+#  PostgreSQL_LIBRARIES     - The PostgreSQL libraries.
+#
+# ----------------------------------------------------------------------------
+# If you have installed PostgreSQL in a non-standard location.
+# (Please note that in the following comments, it is assumed that <Your Path>
+# points to the root directory of the include directory of PostgreSQL.)
+# Then you have three options.
+# 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to <Your Path>/include and
+#    PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is
+# 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/PostgreSQL<-version>. This will allow find_path()
+#    to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file
+#    set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
+# 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have
+#    installed PostgreSQL, e.g. <Your Path>.
+#
+# ----------------------------------------------------------------------------
+
+set(PostgreSQL_INCLUDE_PATH_DESCRIPTION "top-level directory containing the PostgreSQL include directories. E.g /usr/local/include/PostgreSQL/8.4 or C:/Program Files/PostgreSQL/8.4/include")
+set(PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}")
+set(PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.")
+set(PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}")
+set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to where PostgreSQL is found on the machine E.g C:/Program Files/PostgreSQL/8.4")
+
+set(PostgreSQL_KNOWN_ROOTS "/usr/include" "/usr/include/postgres"
+    "/usr/include/pgsql" "/usr/include/postgresql")
+set(PostgreSQL_KNOWN_VERSIONS "9.3" "9.2" "9.1" "9.0")
+
+set(PostgreSQL_ROOT_DIRECTORIES)
+foreach (root ${PostgreSQL_KNOWN_ROOTS} )
+    list(APPEND PostgreSQL_ROOT_DIRECTORIES "${root}")
+    foreach (version ${PostgreSQL_KNOWN_VERSIONS} )
+        list(APPEND PostgreSQL_ROOT_DIRECTORIES "${root}/${version}" )
+    endforeach()
+endforeach()
+
+#
+# Look for an installation.
+#
+find_path(PostgreSQL_INCLUDE_DIR
+  NAMES libpq-fe.h
+  PATHS
+   # Look in other places.
+   ${PostgreSQL_ROOT_DIRECTORIES}
+  PATH_SUFFIXES
+    pgsql
+    postgresql
+    include
+  # Help the user find it if we cannot.
+  DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
+)
+
+find_path(PostgreSQL_TYPE_INCLUDE_DIR
+  NAMES catalog/pg_type.h
+  PATHS
+   # Look in other places.
+   ${PostgreSQL_ROOT_DIRECTORIES}
+  PATH_SUFFIXES
+    server
+    postgresql
+    pgsql/server
+    postgresql/server
+    include/server
+  # Help the user find it if we cannot.
+  DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
+)
+
+# The PostgreSQL library.
+set (PostgreSQL_LIBRARY_TO_FIND pq)
+# Setting some more prefixes for the library
+set (PostgreSQL_LIB_PREFIX "")
+if ( WIN32 )
+  set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib")
+  set ( PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND})
+endif()
+
+find_library( PostgreSQL_LIBRARY
+ NAMES ${PostgreSQL_LIBRARY_TO_FIND}
+ PATHS
+   ${PostgreSQL_ROOT_DIRECTORIES}
+ PATH_SUFFIXES
+   lib
+)
+get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH)
+
+if (PostgreSQL_INCLUDE_DIR AND EXISTS "${PostgreSQL_INCLUDE_DIR}/pg_config.h")
+  file(STRINGS "${PostgreSQL_INCLUDE_DIR}/pg_config.h" pgsql_version_str
+       REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"")
+
+  string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
+         PostgreSQL_VERSION_STRING "${pgsql_version_str}")
+  unset(pgsql_version_str)
+endif()
+
+# Did we find anything?
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PostgreSQL
+                                  REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR
+                                  VERSION_VAR PostgreSQL_VERSION_STRING)
+set( PostgreSQL_FOUND  ${POSTGRESQL_FOUND})
+
+# Now try to get the include and library path.
+if(PostgreSQL_FOUND)
+
+  set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
+  set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
+  set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND})
+
+  #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}")
+  #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}")
+  #message("Final PostgreSQL libraries:   ${PostgreSQL_LIBRARIES}")
+endif()
+
+mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR PostgreSQL_LIBRARY )
diff --git a/debian/control b/debian/control
index d54d407fbc6043cdb200db3c32046e214f2aca4a..e78c1bb25b97fed89ea1006e4683882c00c16273 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,8 @@ Build-Depends: cdbs, debhelper (>= 8),
  libncurses5-dev,
  libiberty-dev | binutils-dev,
  libmysqlclient-dev,
- libpq-dev
+ libpq-dev,
+ postgresql-server-dev-all
 Section: database
 Standards-Version: 3.9.5
 Homepage: http://tarantool.org/
diff --git a/src/module/pg/CMakeLists.txt b/src/module/pg/CMakeLists.txt
index 7c9a002a6b3139ead094a9c4e780c79ce1f21f89..e060f45294bc4956c19f4c2200b75c74a77f80c7 100644
--- a/src/module/pg/CMakeLists.txt
+++ b/src/module/pg/CMakeLists.txt
@@ -1,5 +1,3 @@
-# A special hack for buggy FindPostgreSQL.cmake in Debian/Ubuntu
-set(PostgreSQL_ROOT /usr/include/postgresql;/usr/include/postgres)
 find_optional_package(PostgreSQL)
 
 if (PostgreSQL_FOUND)