在 Linux 上从源代码安装和配置PostgreSQL的9个步骤

网友投稿 867 2022-05-29

与 mySQL 类似,postgresql 是非常有名且功能丰富的免费开源数据库。

在本文中,让我们回顾一下如何从源代码在 Linux 上安装 postgreSQL 数据库。

第一步:下载postgreSQL源代码

从postgreSQL 下载站点 中,选择位于您所在国家/地区的镜像站点。

# wget http://wwwmaster.postgresql.org/redir/198/f/source/v8.3.7/postgresql-8.3.7.ta r.gz

第 2 步:安装 postgreSQL

# tar xvfz postgresql-8.3.7.tar.gz # cd postgresql-8.3.7 # ./configure checking for sgmlspl... no configure: creating ./config.status config.status: creating GNUmakefile config.status: creating src/Makefile.global config.status: creating src/include/pg_config.h config.status: creating src/interfaces/ecpg/include/ecpg_config.h config.status: linking ./src/backend/port/tas/dummy.s to src/backend/port/tas.s config.status: linking ./src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c config.status: linking ./src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c config.status: linking ./src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c config.status: linking ./src/backend/port/dynloader/linux.h to src/include/dynloader.h config.status: linking ./src/include/port/linux.h to src/include/pg_config_os.h config.status: linking ./src/makefiles/Makefile.linux to src/Makefile.port # make make[3]: Leaving directory `/usr/save/postgresql-8.3.7/contrib/spi' rm -rf ./testtablespace mkdir ./testtablespace make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src' make -C config all make[1]: Entering directory `/usr/save/postgresql-8.3.7/config' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config' All of PostgreSQL successfully made. Ready to install. # make install make -C test/regress install make[2]: Entering directory `/usr/save/postgresql-8.3.7/src/test/regress' /bin/sh ../../../config/install-sh -c pg_regress '/usr/local/pgsql/lib/pgxs/src/test/regress/pg_regress' make[2]: Leaving directory `/usr/save/postgresql-8.3.7/src/test/regress' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/src' make -C config install make[1]: Entering directory `/usr/save/postgresql-8.3.7/config' mkdir -p -- /usr/local/pgsql/lib/pgxs/config /bin/sh ../config/install-sh -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh' /bin/sh ../config/install-sh -c -m 755 ./mkinstalldirs '/usr/local/pgsql/lib/pgxs/config/mkinstalldirs' make[1]: Leaving directory `/usr/save/postgresql-8.3.7/config' PostgreSQL installation complete.

以下是可以传递给 ./configure 的各种选项:

–prefix=PREFIX 在 PREFIX 中安装与体系结构无关的文件。默认安装位置是 /usr/local/pgsql

–enable-integer-datetimes 启用 64 位整数日期/时间支持

–enable-nls[=LANGUAGES] 启用本地语言支持

--disable-shared 不构建共享库

–disable-rpath 不要在可执行文件中嵌入共享库搜索路径

--disable-spinlocks 不使用自旋锁

– 使用调试符号 (-g) 启用调试构建

– 启用分析构建启用分析

--enable-dtrace 构建与 DTrace 支持

--enable-depend 开启自动依赖追踪

–enable-cassert 启用断言检查(用于调试)

--enable-thread-safety 使客户端库线程安全

--enable-thread-safety-force 强制线程安全,尽管线程测试失败

–disable-largefile 省略对大文件的支持

–with-docdir=DIR 安装 DIR 中的文档 [PREFIX/doc]

–without-docdir 不安装文档

–with-includes=DIRS 在 DIRS 中寻找额外的头文件

在 Linux 上从源代码安装和配置PostgreSQL的9个步骤

–with-libraries=DIRS 在 DIRS 中查找其他库

–with-libs=DIRS –with-libraries 的替代拼写

–with-pgport=PORTNUM 更改默认端口号 [5432]

–with-tcl 构建 Tcl 模块 (PL/Tcl)

–with-tclconfig=DIR tclConfig.sh 在 DIR 中

–with-perl 构建 Perl 模块 (PL/Perl)

–with-python 构建 Python 模块 (PL/Python)

–with-gssapi 使用 GSSAPI 支持构建

–with-krb5 构建,支持 Kerberos 5

–with-krb-srvnam=NAME 在 Kerberos [postgres] 中的默认服务主体名称

–with-pam 构建支持 PAM

–with-ldap 使用 LDAP 支持构建

–with-bonjour 使用 Bonjour 支持构建

–with-openssl 构建支持 OpenSSL

–without-readline 不使用 GNU Readline 或 BSD Libedit 进行编辑

–with-libedit-preferred 比 GNU Readline 更喜欢 BSD Libedit

–with-ossp-uuid 在构建 contrib/uuid-ossp 时使用 OSSP UUID 库

–with-libxml 使用 XML 支持构建

–with-libxslt 在构建 contrib/xml2 时使用 XSLT 支持

--with-system-tzdata=DIR 使用 DIR 中的系统时区数据

–without-zlib 不使用 Zlib

–with-gnu-ld 假设 C 编译器使用 GNU ld [default=no]

在 postgreSQL 安装期间执行 ./configure 时,您可能会遇到以下错误消息。

# ./configure checking for -lreadline... no checking for -ledit... no configure: error: readline library not found If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support.

安装 readline-devel 和 libtermcap-devel 即可解决上述问题。

# rpm -ivh libtermcap-devel-2.0.8-46.1.i386.rpm readline-devel-5.1-1.1.i386.rpm warning: libtermcap-devel-2.0.8-46.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159 Preparing... ########################################### [100%] 1:libtermcap-devel ########################################### [ 50%] 2:readline-devel ########################################### [100%]

第 3 步:验证 postgreSQL 目录结构

安装完成后,确保在默认的/usr/local/pgsql 目录下创建了bin、doc、include、lib、man 和share 目录,如下所示。

# ls -l /usr/local/pgsql/ total 24 drwxr-xr-x 2 root root 4096 Apr 8 23:25 bin drwxr-xr-x 3 root root 4096 Apr 8 23:25 doc drwxr-xr-x 6 root root 4096 Apr 8 23:25 include drwxr-xr-x 3 root root 4096 Apr 8 23:25 lib drwxr-xr-x 4 root root 4096 Apr 8 23:25 man drwxr-xr-x 5 root root 4096 Apr 8 23:25 share

第 4 步:创建 postgreSQL 用户帐户

# adduser postgres # passwd postgres Changing password for user postgres. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.

第 5 步:创建 postgreSQL 数据目录

创建 postgres 数据目录并使 postgres 用户成为所有者。

# mkdir /usr/local/pgsql/data # chown postgres:postgres /usr/local/pgsql/data # ls -ld /usr/local/pgsql/data drwxr-xr-x 2 postgres postgres 4096 Apr 8 23:26 /usr/local/pgsql/data

第 6 步:初始化 postgreSQL 数据目录

在开始创建任何 postgreSQL 数据库之前,应使用 initdb 命令初始化在上述步骤中创建的空数据目录,如下所示。

# su - postgres # /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/ The files belonging to this database system will be owned by user postgres This user must also own the server process. The database cluster will be initialized with locale en_US.UTF-8. The default database encoding has accordingly been set to UTF8. The default text search configuration will be set to "english". fixing permissions on existing directory /usr/local/pgsql/data ... ok creating subdirectories ... ok selecting default max_connections ... 100 selecting default shared_buffers/max_fsm_pages ... 32MB/204800 creating configuration files ... ok creating template1 database in /usr/local/pgsql/data/base/1 ... ok initializing pg_authid ... ok initializing dependencies ... ok creating system views ... ok loading system objects' descriptions ... ok creating conversions ... ok creating dictionaries ... ok setting privileges on built-in objects ... ok creating information schema ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the -A option the next time you run initdb. Success. You can now start the database server using: /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data or /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

步骤 7:验证 postgreSQL 数据目录

确保所有 postgres DB 配置文件(例如 postgresql.conf)都创建在数据目录下,如下所示。

$ ls -l /usr/local/pgsql/data total 64 drwx------ 5 postgres postgres 4096 Apr 8 23:29 base drwx------ 2 postgres postgres 4096 Apr 8 23:29 global drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_clog -rw------- 1 postgres postgres 3429 Apr 8 23:29 pg_hba.conf -rw------- 1 postgres postgres 1460 Apr 8 23:29 pg_ident.conf drwx------ 4 postgres postgres 4096 Apr 8 23:29 pg_multixact drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_subtrans drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_tblspc drwx------ 2 postgres postgres 4096 Apr 8 23:29 pg_twophase -rw------- 1 postgres postgres 4 Apr 8 23:29 PG_VERSION drwx------ 3 postgres postgres 4096 Apr 8 23:29 pg_xlog -rw------- 1 postgres postgres 16592 Apr 8 23:29 postgresql.conf

第八步:启动postgreSQL数据库

使用 postgres postmaster 命令在后台启动 postgreSQL 服务器,如下所示。

$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 & [1] 2222 $ cat logfile LOG: database system was shut down at 2016-04-08 23:29:50 PDT LOG: autovacuum launcher started LOG: database system is ready to accept connections

第 9 步:创建 postgreSQL DB 并测试安装

创建一个测试数据库并连接到它以确保安装成功,如下所示。

$ /usr/local/pgsql/bin/createdb test $ /usr/local/pgsql/bin/psql test Welcome to psql 8.3.7, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit test=#

Linux PostgreSQL

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Git基础与命令
下一篇:科技抗疫!云脉疫情防控登记系统强化园区复工防控
相关文章