热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Linux系统编译安装postgresql数据库

PostgreSQL作为一款优秀的开源数据库软件,是唯一支持事务、子查询、多版本并行控制系统、数据完整性检查等特性的一种自由软件的数据库管理系统,能够在多种平台下安装运行,包括linux,unix和windows。对于软件采购经费不足的企业来说,postgresql是个非常

PostgreSQL作为一款优秀的开源数据库软件,是唯一支持事务、子查询、多版本并行控制系统、数据完整性检查等特性的一种自由软件的数据库管理系统,能够在多种平台下安装运行,包括linux,unix和windows。
对于软件采购经费不足的企业来说,postgresql是个非常不错的选择。既保持了关系数据库的强大稳定又能减轻费用压力。

postgresql的安装非常简单,以下是我的安装过程,跟大家分享一下。
可以从postgresql.org网站下载源码也可以采用yum工具来安装,我采用的是源码的安装方式。
下载目录:http://www.postgresql.org/ftp/source/
postgresql版本:8.3.10
操作系统:redhat enterprise 5
系统内核:2.6.18
对下载的软件包进行解压:

[root@redhat software]# tar zxvf postgresql-8.3.10.tar.gz
[root@redhat software]#cd postgresql-8.3.10

 配置postgresql安装目录:

[root@redhat postgresql-8.3.10]# ./configure --prefix=/pgsql
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support... no
checking whether NLS is wanted... no
checking for default port number... 5432
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking if gcc supports -Wdeclaration-after-statement... yes
checking if gcc supports -Wendif-labels... yes
checking if gcc supports -fno-strict-aliasing... yes
checking if gcc supports -fwrapv... yes
configure: using CFLAGS=-O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fwrapv
checking whether the C compiler still works... yes
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... no
checking whether to build with Tcl... no
checking whether to build Perl modules... no
checking whether to build Python modules... no
checking whether to build with GSSAPI support... no
checking whether to build with Kerberos 5 support... no
checking whether to build with PAM support... no
checking whether to build with LDAP support... no
checking whether to build with Bonjour support... no
checking whether to build with OpenSSL support... no
checking for egrep... grep -E
configure: using CPPFLAGS= -D_GNU_SOURCE
configure: using LDFLAGS=
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for ranlib... ranlib
checking for strip... strip
checking whether it is possible to strip libraries... yes
checking for tar... /bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for bison... bison -y
configure: using bison (GNU Bison) 2.3
checking for flex... /usr/bin/flex
configure: using /usr/bin/flex version 2.5.4
checking for perl... /usr/bin/perl
checking for main in -lm... yes
checking for library containing setproctitle... no
checking for library containing dlopen... -ldl
checking for library containing socket... none required
checking for library containing shl_load... no
checking for library containing getopt_long... none required
checking for library containing crypt... -lcrypt
checking for library containing fdatasync... none required
checking for library containing shmget... none required
checking for -lreadline... yes (-lreadline -ltermcap)
checking for inflate in -lz... yes
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking crypt.h usability... yes
checking crypt.h presence... yes
checking for crypt.h... yes
checking dld.h usability... no
checking dld.h presence... no
checking for dld.h... no
checking fp_class.h usability... no
checking fp_class.h presence... no
checking for fp_class.h... no
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking ieeefp.h usability... no
checking ieeefp.h presence... no
checking for ieeefp.h... no
checking langinfo.h usability... yes
checking langinfo.h presence... yes
checking for langinfo.h... yes
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking pwd.h usability... yes
checking pwd.h presence... yes
checking for pwd.h... yes
checking sys/ipc.h usability... yes
checking sys/ipc.h presence... yes
checking for sys/ipc.h... yes
checking sys/poll.h usability... yes
checking sys/poll.h presence... yes
checking for sys/poll.h... yes
checking sys/pstat.h usability... no
checking sys/pstat.h presence... no
checking for sys/pstat.h... no
checking sys/resource.h usability... yes
checking sys/resource.h presence... yes
checking for sys/resource.h... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/sem.h usability... yes
checking sys/sem.h presence... yes
checking for sys/sem.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking sys/shm.h usability... yes
checking sys/shm.h presence... yes
checking for sys/shm.h... yes
checking sys/tas.h usability... no
checking sys/tas.h presence... no
checking for sys/tas.h... no
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/un.h usability... yes
checking sys/un.h presence... yes
checking for sys/un.h... yes
checking termios.h usability... yes
checking termios.h presence... yes
checking for termios.h... yes
checking utime.h usability... yes
checking utime.h presence... yes
checking for utime.h... yes
checking wchar.h usability... yes
checking wchar.h presence... yes
checking for wchar.h... yes
checking wctype.h usability... yes
checking wctype.h presence... yes
checking for wctype.h... yes
checking kernel/OS.h usability... no
checking kernel/OS.h presence... no
checking for kernel/OS.h... no
checking kernel/image.h usability... no
checking kernel/image.h presence... no
checking for kernel/image.h... no
checking SupportDefs.h usability... no
checking SupportDefs.h presence... no
checking for SupportDefs.h... no
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking for netinet/tcp.h... yes
checking readline/readline.h usability... yes
checking readline/readline.h presence... yes
checking for readline/readline.h... yes
checking readline/history.h usability... yes
checking readline/history.h presence... yes
checking for readline/history.h... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking whether byte ordering is bigendian... no
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for preprocessor stringizing operator... yes
checking for signed types... yes
checking for working volatile... yes
checking for __func__... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_zone... yes
checking for tzname... yes
checking for union semun... no
checking for struct sockaddr_un... yes
checking for struct sockaddr_storage... yes
checking for struct sockaddr_storage.ss_family... yes
checking for struct sockaddr_storage.__ss_family... no
checking for struct sockaddr_storage.ss_len... no
checking for struct sockaddr_storage.__ss_len... no
checking for struct sockaddr.sa_len... no
checking for struct addrinfo... yes
checking for struct cmsgcred... no
checking for struct fcred... no
checking for struct sockcred... no
checking for struct option... yes
checking for z_streamp... yes
checking for int timezone... yes
checking types of arguments for accept()... int, int, struct sockaddr *, size_t *
checking whether gettimeofday takes only one argument... no
checking for cbrt... yes
checking for dlopen... yes
checking for fcvt... yes
checking for fdatasync... yes
checking for getpeereid... no
checking for getrlimit... yes
checking for memmove... yes
checking for poll... yes
checking for pstat... no
checking for readlink... yes
checking for setproctitle... no
checking for setsid... yes
checking for sigprocmask... yes
checking for symlink... yes
checking for sysconf... yes
checking for towlower... yes
checking for utime... yes
checking for utimes... yes
checking for waitpid... yes
checking for wcstombs... yes
checking whether fdatasync is declared... yes
checking whether posix_fadvise is declared... yes
checking whether strlcat is declared... no
checking whether strlcpy is declared... no
checking whether F_FULLFSYNC is declared... no
checking for struct sockaddr_in6... yes
checking for PS_STRINGS... no
checking for snprintf... yes
checking for vsnprintf... yes
checking whether snprintf is declared... yes
checking whether vsnprintf is declared... yes
checking for isinf... yes
checking for crypt... yes
checking for fseeko... yes
checking for getopt... yes
checking for getrusage... yes
checking for inet_aton... yes
checking for random... yes
checking for rint... yes
checking for srandom... yes
checking for strdup... yes
checking for strerror... yes
checking for strlcat... no
checking for strlcpy... no
checking for strtol... yes
checking for strtoul... yes
checking for unsetenv... yes
checking for getaddrinfo... yes
checking for getopt_long... yes
checking for rl_completion_append_character... yes
checking for rl_completion_matches... yes
checking for rl_filename_completion_function... yes
checking for replace_history_entry... yes
checking for sigsetjmp... yes
checking whether sys_siglist is declared... yes
checking for syslog... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking for optreset... no
checking for strtoll... yes
checking for strtoull... yes
checking for atexit... yes
checking for _LARGEFILE_SOURCE value needed for large files... no
checking for fseeko... (cached) yes
checking test program... ok
checking whether long int is 64 bits... no
checking whether long long int is 64 bits... yes
checking snprintf format for long long int... %lld
checking for unsigned long... yes
checking size of unsigned long... 4
checking for size_t... yes
checking size of size_t... 4
checking for short... yes
checking alignment of short... 2
checking for int... yes
checking alignment of int... 4
checking for long... yes
checking alignment of long... 4
checking for long long int... yes
checking alignment of long long int... 4
checking for double... yes
checking alignment of double... 4
checking for int8... no
checking for uint8... no
checking for int64... no
checking for uint64... no
checking for sig_atomic_t... yes
checking for POSIX signal interface... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking for _LARGE_FILES value needed for large files... no
checking for working memcmp... yes
checking for onsgmls... onsgmls
checking for openjade... openjade
checking for DocBook V4.2... yes
checking for DocBook stylesheets... no
checking for collateindex.pl... no
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

 进行源码编译:

[root@redhat postgresql-8.3.10]# make
.....省略
make[2]: Leaving directory `/opt/software/postgresql-8.3.10/src/test/regress'
make[1]: Leaving directory `/opt/software/postgresql-8.3.10/src'
make -C config all
make[1]: Entering directory `/opt/software/postgresql-8.3.10/config'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/opt/software/postgresql-8.3.10/config'
All of PostgreSQL successfully made. Ready to install.

进行安装:

[root@redhat postgresql-8.3.10]# make install
make[2]: Leaving directory `/opt/software/postgresql-8.3.10/src/test/regress'
make[1]: Leaving directory `/opt/software/postgresql-8.3.10/src'
make -C config install
make[1]: Entering directory `/opt/software/postgresql-8.3.10/config'
mkdir -p -- /pgsql/lib/pgxs/config
/bin/sh ../config/install-sh -c -m 755 ./install-sh '/pgsql/lib/pgxs/config/install-sh'
/bin/sh ../config/install-sh -c -m 755 ./mkinstalldirs '/pgsql/lib/pgxs/config/mkinstalldirs'
make[1]: Leaving directory `/opt/software/postgresql-8.3.10/config'
PostgreSQL installation complete.

 创建用户与组:

[root@redhat postgresql-8.3.10]# groupadd postgres
[root@redhat postgresql-8.3.10]# useradd -g postgres postgres
[root@redhat postgresql-8.3.10]# cd /pgsql/
[root@redhat pgsql]# chown postgres:postgres data/

配置环境变量:

[root@redhat pgsql]# su - postgres
[postgres@redhat ~]$ vi .bash_profile
[postgres@redhat ~]$ source ./.bash_profile
[postgres@redhat ~]$ echo $PG_DATA
/pgsql/data

初始化数据库:

[postgres@redhat data]$ initdb -E UNICODE -D /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 text search configuration will be set to "english".

fixing permissions on existing directory

/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 /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:

postgres

-D /pgsql/data
or
pg_ctl -D /pgsql/data -l logfile start

创建日志文件:

[postgres@redhat data]$ touch pgsql.log
[postgres@redhat data]$ ls -l
total 64
drwx------ 5 postgres postgres 4096 Aug 13 20:33 base
drwx------ 2 postgres postgres 4096 Aug 13 20:33 global
drwx------ 2 postgres postgres 4096 Aug 13 20:32 pg_clog
-rw------- 1 postgres postgres 3429 Aug 13 20:32 pg_hba.conf
-rw------- 1 postgres postgres 1460 Aug 13 20:32 pg_ident.conf
drwx------ 4 postgres postgres 4096 Aug 13 20:32 pg_multixact
-rw-rw-r-- 1 postgres postgres 0 Aug 13 20:34 pgsql.log
drwx------ 2 postgres postgres 4096 Aug 13 20:32 pg_subtrans
drwx------ 2 postgres postgres 4096 Aug 13 20:32 pg_tblspc
drwx------ 2 postgres postgres 4096 Aug 13 20:32 pg_twophase
-rw------- 1 postgres postgres 4 Aug 13 20:32 PG_VERSION
drwx------ 3 postgres postgres 4096 Aug 13 20:32 pg_xlog
-rw------- 1 postgres postgres 16665 Aug 13 20:32 postgresql.conf

修改监听地址与端口参数:

[postgres@redhat data]$ vi postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart)
[root@redhat pgsql]$exit

创建系统自启动服务文件:

[root@redhat pgsql]# cp /opt/software/postgresql-8.3.10/contrib/start-scripts/linux /etc/rc.d/init.d/postgresql
[root@redhat pgsql]# chmod u+x /etc/rc.d/init.d/postgresql
[root@redhat pgsql]# 修改自启动服务文件的参数: [root@redhat pgsql]# vi /etc/rc.d/init.d/postgresql
# Installation prefix
prefix=/pgsql

# Data directory
PGDATA

="/pgsql/data"

# Who to run the postmaster

as, usually "postgres". (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG

="$PGDATA/pgsql.log"

添加自启动服务并启动数据库服务:

[root@redhat pgsql]# chkconfig --add postgresql
[root@redhat pgsql]# service postgresql start
Starting PostgreSQL: ok
[root@redhat pgsql]# more data/pgsql.log
LOG: could not create IPv6 socket: Address family not supported by protocol
LOG: could not resolve "localhost": Temporary failure in name resolution
LOG: disabling statistics collector for lack of working socket
WARNING: autovacuum not started because of misconfiguration
HINT: Enable the "track_counts" option.
LOG: database system was shut down at 2010-08-13 20:33:02 CST
LOG: database system is ready to accept connections

数据库连接测试:

[root@redhat pgsql]# su - postgres
[postgres@redhat ~]$ psql
Welcome to psql 8.3.10, 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

postgres

=# select count(*) from pg_class;
count
-------
226
(1 row)

postgres

=#\q
[postgres@redhat ~]$

除了采用源码方式,还可以使用yum工具,后者安装也非常的简单。


推荐阅读
  • 本文探讨了如何使用ls -lsh命令排除总大小输出,仅显示文件大小的方法,并提供了几种实现这一目标的解决方案。 ... [详细]
  • 通常情况下,修改my.cnf配置文件后需要重启MySQL服务才能使新参数生效。然而,通过特定命令可以在不重启服务的情况下实现配置的即时更新。本文将详细介绍如何在线调整MySQL配置,并验证其有效性。 ... [详细]
  • Symfony是一个功能强大的PHP框架,以其依赖注入(DI)特性著称。许多流行的PHP框架如Drupal和Laravel的核心组件都基于Symfony构建。本文将详细介绍Symfony的安装方法及其基本使用。 ... [详细]
  • 本文详细介绍了 Python 中的条件语句和循环结构。主要内容包括:1. 分支语句(if...elif...else);2. 循环语句(for, while 及嵌套循环);3. 控制循环的语句(break, continue, else)。通过具体示例,帮助读者更好地理解和应用这些语句。 ... [详细]
  • 优化Flask应用的并发处理:解决Mysql连接过多问题
    本文探讨了在Flask应用中通过优化后端架构来应对高并发请求,特别是针对Mysql 'too many connections' 错误的解决方案。我们将介绍如何利用Redis缓存、Gunicorn多进程和Celery异步任务队列来提升系统的性能和稳定性。 ... [详细]
  • 主调|大侠_重温C++ ... [详细]
  • 本文详细介绍了如何解决 Microsoft SQL Server 中用户 'sa' 登录失败的问题。错误代码为 18470,提示该帐户已被禁用。我们将通过 Windows 身份验证方式登录,并启用 'sa' 帐户以恢复其访问权限。 ... [详细]
  • Shell脚本中变量操作详解
    本文基于《鸟哥的Linux私房菜》一书,详细介绍了Shell脚本中变量的使用方法,包括变量的赋值规则、字符串处理技巧以及环境变量的管理等,旨在帮助读者更好地理解和使用Shell中的变量。 ... [详细]
  • cJinja:C++编写的轻量级HTML模板引擎
    本文介绍了cJinja,这是一个用C++编写的轻量级HTML模板解析库。它利用ejson来处理模板中的数据替换(即上下文),其语法与Django Jinja非常相似,功能强大且易于学习。 ... [详细]
  • 本文详细探讨了Java命令行参数的概念、使用方法及在实际编程中的应用,包括如何通过命令行传递参数给Java程序,以及如何在Java程序中解析这些参数。 ... [详细]
  • 本文探讨了在构建应用程序时,如何对不同类型的数据进行结构化设计。主要分为三类:全局配置、用户个人设置和用户关系链。每种类型的数据都有其独特的用途和应用场景,合理规划这些数据结构有助于提升用户体验和系统的可维护性。 ... [详细]
  • 本文深入探讨了 PHP 实现计划任务的方法,包括其原理、具体实现方式以及在不同操作系统中的应用。通过详细示例和代码片段,帮助开发者理解和掌握如何高效地设置和管理定时任务。 ... [详细]
  • 本文介绍如何配置SecureCRT以正确显示Linux终端的颜色,并解决中文显示问题。通过简单的步骤设置,可以显著提升使用体验。 ... [详细]
  • 本文深入探讨了 Delphi 中类对象成员的核心概念,包括 System 单元的基础知识、TObject 类的定义及其方法、TClass 的作用以及对象的消息处理机制。文章不仅解释了这些概念的基本原理,还提供了丰富的补充和专业解答,帮助读者全面理解 Delphi 的面向对象编程。 ... [详细]
  • 中断向量是计算机系统中用于指向中断服务程序的入口地址。每个中断向量对应一个特定的中断事件,存储在内存中的中断向量表中。该表通常包含256个条目,每个条目占用4个字节,用于存放跳转指令或直接指向中断处理程序的地址。 ... [详细]
author-avatar
寄到家的_259
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有