# Postgresql数据库介绍12——安装

Postgresql介绍 专栏收录该内容
20 篇文章 3 订阅

## 指令步骤

./configure

gmake

su

gmake install

mkdir /usr/local/pgsql/data

chown postgres /usr/local/pgsql/data

su - postgres

/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &

/usr/local/pgsql/bin/createdb test

/usr/local/pgsql/bin/psql test

# 要求

• 需要GNU make 版本3.80或更高版本，其他的make程序或更老版本没用。GNU make通常以名gmake被安装，该文件也将用该名字提及它。（在一些系统中，GNU make是以make为名字的默认工具。）要测试GNU make请键入：

gmake –version


• 您需要安装一个ISO/ANSI C 的编译器（至少是C89可兼容的）。我们推荐使用最近版本的gcc，但是众所周知的是可以使用来自不同厂商的许多编译器来编译PostgreSQL。

• 除了gzip和bzip2，还要求用tar来解压源码包。

• 默认使用zlib压缩库，如果您不想使用它，那么您必须在cofigure中标注--without-zlib选项。使用了该选项会阻止在pg_dump 和 pg_restore中压缩文档。

• Cannot build PL/Perl because libperl is not a shared library.
• You might have to rebuild your Perl installation.Refer to
• the documentation for details.

（如果您没有看到上面屏幕上的输出，您只是注意到PL/Perl库对象，plperl.so或类似的，不会被安装。）如果您看到这个，您必须手动重建和安装Perl来能够建立PL/Perl。在为Perl配置过程中，请求一个共享库。

# 获得源码

gunzip postgresql-9.1devel.tar.gz

tar xf postgresql-9.1devel.tar

# 安装步骤

## 1. 配置

./configure

mkdir build_dir

cd build_dir

/path/to/source/tree/configure [options go here]

gmake

/usr/local/pgsql.

--prefix=PREFIX

--exec-prefix=EXEC-PREFIX

--bindir=DIRECTORY

--sysconfdir=DIRECTORY

--libdir=DIRECTORY

--includedir=DIRECTORY

--datarootdir=DIRECTORY

--localedir=DIRECTORY

--mandir=DIRECTORY

--docdir=DIRECTORY

--htmldir=DIRECTORY

PostgreSQL的HTML格式的文件，默认是DATAROOTDIR.

Note: Care has been taken to make it possible to install PostgreSQL into shared installation locations (such as /usr/local/include) without interfering with the namespace of the rest of the system. First, the string "/postgresql" is automatically appended to datadir, sysconfdir, and docdir, unless the fully expanded directory name already contains the string "postgres" or "pgsql". For example, if you choose /usr/local as prefix, the documentation will be installed in /usr/local/doc/postgresql, but if the prefix is /opt/postgres, then it will be in /opt/postgres/doc. The public C header files of the client interfaces are installed into includedir and are namespace-clean. The internal header files and the server header files are installed into private directories under includedir. See the documentation of each interface for information about how to access its header files. Finally, a private subdirectory will also be created, if appropriate, under libdir for dynamically loadable modules.

--with-includes=DIRECTORIES

--with-libraries=DIRECTORIES

DIRECTORIES是一个冒号隔开的用来搜寻库文件的目录列表，如果您在非标准位置安装了软件包时您可能需要使用该选项（和相关的--with-includes选项）。 例如：--with-libraries=/opt/gnu/lib:/usr/sup/lib。

--enable-nls[=LANGUAGES]

--with-pgport=NUMBER

--with-perl

--with-python

--with-tcl

--with-tclconfig=DIRECTORY

Tcl安装文件tclConfig.sh，它包含了建立Tcl模块所需的配置信息，该文件通常可以在一个众所周知的位置 被自动找到，但是如果您想使用不同的Tcl版本，您可以指定寻找它的目录。

--with-gssapi

--with-krb5

--with-krb-srvnam=NAME

Kerberos服务主的默认名字（通常也被GSSAPI使用），默认为postgres。除非您有个Windows环境，通常没有理由去更改它，因为在那种环境下，它必须设置为高级的POSTGRES。

--with-openssl

--with-pam

--with-ldap

--with-libedit-preferred

--with-bonjour

--with-ossp-uuid

--with-libxml

--with-libxslt

--disable-integer-datetimes

--disable-float4-byval

Disable passing float4 values "by value", causing them to be passed "by reference" instead. This option costs performance, but may be needed for compatibility with old user-defined functions that are written in C and use the "version 0" calling convention. A better long-term solution is to update any such functions to use the "version 1" calling convention.

--disable-float8-byval

Disable passing float8 values "by value", causing them to be passed "by reference" instead. This option costs performance, but may be needed for compatibility with old user-defined functions that are written in C and use the "version 0" calling convention. A better long-term solution is to update any such functions to use the "version 1" calling convention. Note that this option affects not only float8, but also int8 and some related types such as timestamp. On 32-bit platforms, --disable-float8-byval is the default and it is not allowed to select --enable-float8-byval.

--with-segsize=SEGSIZE

Set the segment size, in gigabytes. Large tables are divided into multiple operatingsystem files, each of size equal to the segment size. This avoids problems with file size limits that exist on many platforms. The default segment size, 1 gigabyte, is safe on all supported platforms. If your operating system has "largefile" support (which most do, nowadays), you can use a larger segment size. This can be helpful to reduce the number of file descriptors consumed when working with very large tables. But be careful not to select a value larger than is supported by your platform and the file systems you intend to use. Other tools you might wish to use, such as tar, could also set limits on the usable file size. It is recommended, though not absolutely required, that this value be a power of 2. Note that changing this value requires an initdb.

--with-blocksize=BLOCKSIZE

Set the block size, in kilobytes. This is the unit of storage and I/O within tables. The default, 8 kilobytes, is suitable for most situations; but other values may be useful in special cases. The value must be a power of 2 between 1 and 32 (kilobytes). Note that changing this value requires an initdb.

--with-wal-segsize=SEGSIZE

Set the WAL segment size, in megabytes. This is the size of each individual file in the WAL log. It may be useful to adjust this size to control the granularity of WAL log shipping. The default size is 16 megabytes. The value must be a power of 2 between 1 and 64 (megabytes). Note that changing this value requires an initdb.

--with-wal-blocksize=BLOCKSIZE

Set the WAL block size, in kilobytes. This is the unit of storage and I/O within the WAL log. The default, 8 kilobytes, is suitable for most situations; but other values may be useful in special cases. The value must be a power of 2 between 1 and 64 (kilobytes). Note that changing this value requires an initdb.

--disable-spinlocks

Allow the build to succeed even if PostgreSQL has no CPU spinlock support for the platform. The lack of spinlock support will result in poor performance; therefore, this option should only be used if the build aborts and informs you that the platform lacks spinlock support. If this option is required to build PostgreSQL on your platform, please report the problem to the PostgreSQL developers.

Disable the thread-safety of client libraries. This prevents concurrent threads in libpq and ECPG programs from safely controlling their private connection handles.

--with-system-tzdata=DIRECTORY

PostgreSQL includes its own time zone database, which it requires for date and time operations. This time zone database is in fact compatible with the "zoneinfo" time zone database provided by many operating systems such as FreeBSD, Linux, and Solaris, so it would be redundant to install it again. When this option is used, the system-supplied time zone database in DIRECTORY is used instead of the one included in the PostgreSQL source distribution. DIRECTORY must be specified as an absolute path. /usr/share/zoneinfo is a likely directory on some operating systems. Note that the installation routine will not detect mismatching or erroneous time zone data. If you use this option, you are advised to run the regression tests to verify that the time zone data you have pointed to works correctly with PostgreSQL. This option is mainly aimed at binary package distributors who know their target operating system well. The main advantage of using this option is that the PostgreSQL package won't need to be upgraded whenever any of the many local daylight-saving time rules change. Another advantage is that PostgreSQL can be cross-compiled more straightforwardly if the time zone database files do not need to be built during the installation.

--without-zlib

--enable-debug

--enable-coverage

--enable-profiling

--enable-cassert

--enable-depend

--enable-dtrace

./configure CC='gcc -m64' --enable-dtrace DTRACEFLAGS='-64' ...

./configure CC='/opt/SUNWspro/bin/cc -xtarget=native64' --enable-dtrace DTRACEFLAGS='-64' ...

./configure CC=/opt/bin/gcc CFLAGS='-O2 -pipe'

BISON

Bison 程序

CC

C 编译器

CFLAGS

CPP

C 预处理

CPPFLAGS

DTRACE

Dtrace程序的位置

DTRACEFLAGS

FLEX

Flex 程序

LDFLAGS

LDFLAGS_EX

LDFLAGS_SL

MSGFMT

PERL

Perl注释器的完整路径。它将用来决定编译PL/Perl的管理。

PYTHON

Python注释器的完整路径。它将用来决定编译PL/Python的管理。同样，Python2或3是否在这指定决定了哪种PL/Python语言可用。参考42.1获取更多信息。

TCLSH

Tcl注释器的完整路径。它将用来决定编译PL/Tcl的管理，并且被提交到Tcl脚本中。

XML2_CONFIG

## 2. 编译

gmake

（记住使用GNU make）根据您的硬件编译要花几分钟的时间，最后一行应该显示

gmake world


## 3. 复原测试

gmake check

（超级用户不使用，以普通用户执行它）30章包含了关于解释测试结果的详细信息，您可以在之后的任何时间用同样的命令重复该测试。

## 4. 安装文件

gmake install

gmake install-docs

gmake install-world

gmake -C src/bin install gmake -C src/include install gmake -C src/interfaces install gmake -C doc install

src/bin有一些服务器专用的二进制文件，但是它们很小。

regsvr32 pgsql_library_directory/pgevent.dll

# 安装后设置

## 1 共享库

psql: error in loading shared libraries libpq.so.2.1: cannot open shared object file: No such file or directory

# 平台的详细说明

## 1 AIX

PostgreSQL可以在AIX上工作，但是正确安装它具有挑战性。AXI4.3.3到6.1版本被认为支持PostgreSQL，您可以使用GCC或IBM编译器xlc。一般来说，使用最近版本的AIX和PostgreSQL是支持的。核对build farm获得关于哪个版本的AIX被认为可以运行的更新信息。

The minimum recommended fix levels for supported AIX versions are: AIX 4.3.3 Maintenance Level 11 + post ML11 bundle AIX 5.1 Maintenance Level 9 + post ML9 bundle AIX 5.2 Technology Level 10 Service Pack 3 AIX 5.3 Technology Level 7 AIX 6.1 Base Level

GCC Issues

## 2 Cygwin

• 在Windows实用程序之前设置使用Cygwin bin目录的路径，这会有助于阻止编辑时出错。

• GNU make命令是make而不是gmake。

• 不支持su命令，在Windows NT，2000，或XP中使用ssh来模拟su，其它情况请跳过此步。

• 不支持OpenSSL

• 启动cygserver来支持共享内存，要执行这个，键入命令/usr/sbin/cygserver&，任何时候您启动PostgreSQL服务器或初始化一个数据库集群时必须运行该程序。必须得更改默认cygserver 配置来阻止因为系统资源的缺乏而导致的失败。

• 编译在某些系统上也许会失败，在这些系统中，使用的是locale而不是C。要安装这个，在编译前通过export LANG=C.utf8设置locale到C，并且在您安装完PostgreSQL后将其设回到初始的设置。

• 类似的复原测试（make check）由于过多的listen（）backlog queue可能生成假的回归测试失败，这些backlog queue导致连接遭拒错误或暂停。您可以使用make变量MAX_CONNECTIONS来限制连接的数目：

Make MAX_CONNECTIONS=5 check

## 3 HP-UX

postgreSQL 7.3+应该在运行HP-UX 10.X 或11.X的序列700/800 PA-RISC机器上工作，给定合适的系统路径和编译工具。至少有一个开发商在HP-UX 10.20上测试过，并且我们已经有在HP-UX11.00 和11.11成功安装的报告。

PHSS_30966 s700_800 ld(1) 和linker tools cumulative patch

PHSS_30848 s700_800 HP C Compiler (A.05.57) PHSS_30849 s700_800 u2comp/be/plugin library Patch

./configure CC=cc

## 6 SCO OpenServer and SCO UnixWare

1.Skunkware

2.GNU Make

Readline 库在Skunkware CD中，但它不包含在UnixWare 7.1 Skunkware CD中，如果您有UnixWare7.0.0或7.0.1Skunkware CDs，您可以从那里安装。否则请试 http://www.sco.com/skunkware/ 。

./configure --with-libraries=/usr/local/lib --with-includes=/usr/local/include

4.在OpenServer上使用UDK

./configure --with-libraries=/udk/usr/lib --with-includes=/udk/usr/include

./configure --with-libraries="/udk/usr/lib /usr/local/lib" --with-includes="/udk/usr/include /usr/local/include"

5. 阅读PostgreSQL Man Pages

MANPATH=/usr/lib/scohelp/ %L/man:/usr/dt/man:/usr/man:/usr/share/man:scohelp:/usr/local/man:/usr/local/pgsql/man

6.特征补充的C99 问题

## 7 Solaris

Solaris非常支持PostgreSQL，您的操作系统版本越新，将遇到的问题会越少；参考下面的细节.

1. 需求工具

2 OpenSSL的问题

• src/backend/libpq/crypt.c
• src/interfaces/libpq/fe-auth.c
• src/interfaces/libpq/fe-connect.c

3 configure抱怨一个失败的测试程序

configure ... LDFLAGS="-R /usr/sfw/lib:/opt/sfw/lib:/usr/local/lib"

4 64位编译有时会死机

LIBOBJS =

LIBOBJS = snprintf.o

（在这个变量中也许存在其他的文件，顺序没关系）然后按正常顺序编译。

5 最佳操作的编译

6 使用DTrace 跟踪PostgreSQL

Undefined first referenced

symbol                             in file


AbortTransaction utils/probes.o CommitTransaction utils/probes.o ld: fatal: Symbol referencing errors. No output written to postgres collect2: ld returned 1 exit status gmake: *** [postgres] Error 1

• 0
点赞
• 0
评论
• 0
收藏
• 扫一扫，分享海报

11-28 1万+

06-08 184
08-05 4598
07-01 5795
12-15 1万+
01-26 2419
01-19 2064
11-01 95
10-18 8869
04-02 2288