Chinaunix首页 | 论坛 | 博客
  • 博客访问: 790285
  • 博文数量: 130
  • 博客积分: 3477
  • 博客等级: 中校
  • 技术积分: 1339
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-30 21:53
文章分类

全部博文(130)

文章存档

2024年(1)

2023年(10)

2022年(4)

2021年(10)

2020年(9)

2018年(1)

2017年(1)

2014年(4)

2013年(3)

2012年(12)

2011年(24)

2010年(2)

2009年(8)

2008年(6)

2007年(34)

2006年(1)

分类: Mysql/postgreSQL

2020-11-17 20:57:06

Build Install PostgreSQL 11.10 And Use For SCO OpenServer 6.0.0 Ni
==================================================================================================================================
在 SCO OpenServer6 系统上编译安装 PostgreSQL 11.10

纯干货,无废话。

写在前面的话:
PostgreSQL 数据库软件从 10 版本开始,就不再支持 SCO OpenServer6 系统了,但这并不代表我们无法在 SCO OpenServer 6 系统上安装使用 PostgreSQL 10 以上的数据库版本,只是相对麻烦一点。
因为 PostgreSQL 数据库是使用原生的 C 语言开发的,这对我们是一个很好的信号,我们有理由相信,经过简单的修改,我们是能够在 SCO OpenServer 6 系统上使用 PostgreSQL 11.10 的,当然,前提是你必须要有足够的耐心。


编译需要的前置条件:
1、    系统必须安装开发软件包;
2、    系统必须打上 SCO OpenServer Release 6.0.0 Maintenance Pack 4 (ver 1.0.0Ce) 补丁包;
3、    编译必须使用 gmake 3.8 或以上版本,测试中发现 3.8 或 3.8.2 的版本最好,其他版本在编译安装 make 程序包的时候需要修改程序代码。
4、           编译 PostgreSQL 11.10 必须使用 gnu m4 和 gnu bison。


编译安装 make-3.8.0 的软件包方法如下。
1、    展开 make-3.8.0.tar.bz2
2、    进入 make-3.8.0 目录
3、    执行编译前配置
# ./configure --prefix=/usr/gnu --build=i586-sco-sysv5 --host=i586-sco-sysv5
4、    编译并安装
# make
# make install
5、    建立连接
# cd /usr/bin
# ln -sf /usr/gnu/bin/make gmake

编译安装 gnu m4 的软件包的方法如下(我安装的版本是 1.4.10b)。
1、         展开 m4-1.4.10b.tar.bz2
2、         进入 m4-1.4.10b  目录
3、         执行编译前的配置
# ./configure --prefix=/usr/gnu --build=i586-sco-sysv5 --host=i586-sco-sysv5
4、        编译并安装
# gmake
# gmake install
5、        建立软链接
# cd /usr/bin
# mv m4 m4#
# ln -sf /usr/gnu/bin/m4 m4

编译安装 gnu bison 的软件包的方法如下(我安装的版本是 2.2)。
1、         展开 bison-2.2.tar.bz2
2、         进入 bison-2.2  目录
3、         执行编译前的配置
# ./configure --prefix=/usr/gnu --build=i586-sco-sysv5 --host=i586-sco-sysv5
4、        编译并安装
# gmake
# gmake install
5、        建立软链接
# cd /usr/bin
# mv yacc yacc#
# ln -sf /usr/gnu/bin/yacc yacc
# ln -sf /usr/gnu/bin/bison bison


PostgreSQL 11.10 在 SCO OpenServer 6 系统上的安装使用
做好前置工作后,我们开始进入 PostgreSQL 11.10 的安装,过程如下:
Step 1:
下载 postgresql-11.10.tar.bz2 文件,放置在 /tmp 目录下,并展开压缩文件:
# cd /tmp
# bzip2 –d -c postgresql-11.10.tar.bz2 | tar xvf -

Step 2:
修改 PostgreSQL 11.10 的安装程序源码,添加一些内容:

1、修改 postgresql-11.10/src/include/c.h 文件,在其中加入如下内容:

在:
#define C_H

下面加入:
#include

在:
#include "pg_config_manual.h" /* must be after pg_config.h */

下面加入:
#ifdef FLEXIBLE_ARRAY_MEMBER
#undef FLEXIBLE_ARRAY_MEMBER
#define FLEXIBLE_ARRAY_MEMBER 512
#else
#define FLEXIBLE_ARRAY_MEMBER 512
#endif


2、修改 postgresql-11.10/src/backend/storage/lmgr/spin.c
将其中的:
#ifndef HAVE_ATOMICS
#define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES + NUM_ATOMICS_SEMAPHORES)
#else
#define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES)
#endif /* DISABLE_ATOMICS */

修改为:
#ifndef HAVE_ATOMICS
#define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES + NUM_ATOMICS_SEMAPHORES + 128)
#else
#define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES+128)
#endif /* DISABLE_ATOMICS */
 

3、在 postgresql-11.10/src/template 目录下添加文件 sco , 内容如下:
CC="$CC -b elf"

4、在 postgresql-11.10/src/template 目录下添加文件 unixware , 内容如下:
if test "$GCC" != yes; then
  # The -Kno_host is for a bug in the compiler.  See -hackers
  # discussion on 7-8/Aug/2003.
  cat >conftest.c <<__EOF__
extern char *strcpy(char *, const char *);

static void f(char *p, int n){
        strcpy(p+n,"");
}
void g(void){
        f(0, 0);
}
__EOF__

  # Debugging and optimization are mutually exclusive
  if test "$enable_debug" != yes; then
    CFLAGS="-O"
  fi
  if $CC -c -O -Kinline conftest.c >conftest.err 2>&1; then
    CFLAGS="$CFLAGS -Kinline"
  else
    CFLAGS="$CFLAGS -Kinline,no_host"
  fi
  rm -f conftest.*

  PTHREAD_CFLAGS="-Kpthread"

# The effect of doing threading for the backend does not work
# because of a threading bug that appears in the regression tests:
#
# in make check, the plpgsql test (plpgsql.sql)
# set statement_timeout to 1000;
# select blockme();
# reset statement_timeout;
#
# per report from Olivier PRENANT

fi

# Unixware's ldap library reportedly needs these too
EXTRA_LDAP_LIBS="-llber -lresolv"

5、在 postgresql-11.10/src/backend/port/dynloader/ 目录下添加文件 sco.c , 内容如下:
/*
 * src/backend/port/dynloader/sco.c
 *
 * Dummy file used for nothing at this point
 *
 * see sco.h
 */

6、在 postgresql-11.10/src/backend/port/dynloader/ 目录下添加文件 sco.h , 内容如下:
/*-------------------------------------------------------------------------
 *
 * sco.h
 *        port-specific prototypes for SCO 3.2v5.2
 *
 *
 * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * src/backend/port/dynloader/sco.h
 *
 *-------------------------------------------------------------------------
 */
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H

#include
#include "utils/dynamic_loader.h"               /* pgrminclude ignore */

/*
 * Dynamic Loader on SCO 3.2v5.0.2
 *
 * this dynamic loader uses the system dynamic loading interface for shared
 * libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
 * library as the file to be dynamically loaded.
 */

/*
 * In some older systems, the RTLD_NOW flag isn't defined and the mode
 * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
 * if available, but it doesn't exist everywhere.
 * If it doesn't exist, set it to 0 so it has no effect.
 */
#ifndef RTLD_NOW
#define RTLD_NOW 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

#define pg_dlopen(f)    dlopen((f), RTLD_NOW | RTLD_GLOBAL)
#define pg_dlsym                dlsym
#define pg_dlclose              dlclose
#define pg_dlerror              dlerror

#endif   /* PORT_PROTOS_H */

7、在 postgresql-11.10/src/backend/port/dynloader/ 目录下添加文件 unixware.c , 内容如下:
/*
 * src/backend/port/dynloader/unixware.c
 *
 * Dummy file used for nothing at this point
 *
 * see unixware.h
 */

8、在 postgresql-11.10/src/backend/port/dynloader/ 目录下添加文件 unixware.h , 内容如下:
/*
 * src/backend/port/dynloader/unixware.h
 *
 *-------------------------------------------------------------------------
 *
 * unixware.h
 *        port-specific prototypes for Intel x86/UNIXWARE 7
 *
 *
 * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * unixware.h,v 1.2 1995/03/17 06:40:18 andrew Exp
 *
 *-------------------------------------------------------------------------
  */
#ifndef PORT_PROTOS_H
#define PORT_PROTOS_H

#include
#include "utils/dynamic_loader.h"               /* pgrminclude ignore */

/*
 * Dynamic Loader on UnixWare.
 *
 * this dynamic loader uses the system dynamic loading interface for shared
 * libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
 * library as the file to be dynamically loaded.
 */

/*
 * In some older systems, the RTLD_NOW flag isn't defined and the mode
 * argument to dlopen must always be 1.  The RTLD_GLOBAL flag is wanted
 * if available, but it doesn't exist everywhere.
 * If it doesn't exist, set it to 0 so it has no effect.
 */
#ifndef RTLD_NOW
#define RTLD_NOW 1
#endif
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif

#define pg_dlopen(f)    dlopen((f), RTLD_NOW | RTLD_GLOBAL)
#define pg_dlsym                dlsym
#define pg_dlclose              dlclose
#define pg_dlerror              dlerror

#endif   /* PORT_PROTOS_H */

9、在 postgresql-11.10/src/include/port/ 目录下添加文件 sco.h , 内容如下:
/*
 * src/include/port/sco.h
 *
 * see src/backend/libpq/pqcomm.c */
#define SCO_ACCEPT_BUG

#define USE_UNIVEL_CC

10、在 postgresql-11.10/src/include/port/ 目录下添加文件 unixware.h , 内容如下:
/*
 * src/include/port/unixware.h
 *
 * see src/backend/libpq/pqcomm.c */
#define SCO_ACCEPT_BUG

/***************************************
 * Define this if you are compiling with
 * the native UNIXWARE C compiler.
 ***************************************/
#define USE_UNIVEL_CC

11、在 postgresql-11.10/src/makefiles/ 目录下添加 sco 系统的编译文件 Makefile.sco ,内容如下:
AROPT = cr
export_dynamic = -Wl,-Bexport

DLSUFFIX = .so
ifeq ($(GCC), yes)
CFLAGS_SL = -fpic
else
CFLAGS_SL = -K PIC
endif

# Rule for building a shared library from a single .o file
%.so: %.o
    $(LD) -G -Bdynamic -o $@ $<

12、在 postgresql-11.10/src/makefiles/ 目录下添加 unixware 系统的编译文件 Makefile.unixware ,内容如下:
AROPT = crs
ifeq ($(with_gnu_ld), yes)
    export_dynamic = -Wl,-E
else
    export_dynamic = -Wl,-Bexport
endif

ifeq ($(ld_R_works), yes)
ifeq ($(with_gnu_ld), yes)
    rpath = -Wl,-rpath,'$(rpathdir)'
else
    rpath = -Wl,-R'$(rpathdir)'
endif
endif

# Unixware needs threads for everything that uses libpq
CFLAGS += $(PTHREAD_CFLAGS)

DLSUFFIX = .so
ifeq ($(GCC), yes)
CFLAGS_SL = -fpic
else
CFLAGS_SL = -K PIC
endif
ifeq ($(GCC), yes)
SO_FLAGS = -shared
else
SO_FLAGS = -G
endif

# Rule for building a shared library from a single .o file
%.so: %.o
    $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_SL) $(SO_FLAGS) -o $@ $<

sqlmansect = 5sql

13、在 postgresql-11.10/configure 文件中,添加编译操作系统环境描述内容,在:
openbsd*) template=openbsd ;;
下面加入:
     sco*) template=sco ;;

在:
solaris*) template=solaris ;;
下面加入:
   sysv5*) template=unixware ;;


14、在 postgresql-11.10/configure.in 文件中,添加编译操作系统环境描述内容,在:
openbsd*) template=openbsd ;;
下面加入:
     sco*) template=sco ;;

在:
solaris*) template=solaris ;;
下面加入:
   sysv5*) template=unixware ;;

15修改 postgresql-11.10/src/Makefile.shlib 文件,在其中加入共享库编译时的 sco 和 unixware 的支持。
在:
ifeq ($(PORTNAME), solaris)
  ifeq ($(GCC), yes)
    LINK.shared         = $(COMPILER) -shared
  else
    LINK.shared         = $(COMPILER) -G
  endif
  ifdef soname
    ifeq ($(with_gnu_ld), yes)
      LINK.shared       += -Wl,-soname,$(soname)
    else
      LINK.shared       += -h $(soname)
    endif
  endif
endif

下面加入:
ifeq ($(PORTNAME), sco)
  ifeq ($(GCC), yes)
    LINK.shared         = $(CC) -shared
  else
    LINK.shared         = $(CC) -G
    endif
  LINK.shared           += -Wl,-z,text
  ifdef soname
    LINK.shared         += -Wl,-h,$(soname)
  endif
endif

ifeq ($(PORTNAME), unixware)
  ifeq ($(GCC), yes)
    LINK.shared         = $(CC) -shared
  else
    LINK.shared         = $(CC) -G
  endif
  LINK.shared           += -Wl,-z,text
  ifdef soname
    LINK.shared         += -Wl,-h,$(soname)
  endif
endif


Step 3:开始准备编译环境:
1、创建编译目录环境,建立一个编译目录,如 /tmp/objdir

2、写编译配置文件 build.sh,内容如下:
../postgresql-11.10/configure \
        --prefix=/opt/PostgreSQL/11.10 \
        --build=i586-sco-sysv5 \
        --host=i586-sco-sysv5 \
        --disable-spinlocks \
        --disable-thread-safety \
        --without-tcl \
        --with-perl \
        --with-ldap \
        --with-openssl

3、修改其权限为 0755
# chmod 0755 build.sh

4、进入 /tmp/objdir 目录,开始编译前环境配置。
# cd /tmp/objdir
# ../build.sh

Step 4:编译安装 PostgreSQL 11.10 软件
1、开始编译
# gmake
# gmake install

注意事项:在编译的过程中,发现在编译 psql 可执行文件的时候,会出现 describe.o 文件报 ERROR 没有定义的错误,通过程序查找,没有找到程序中使用了 ERROR 的地方,但确实是报了这个 ERROR 没有定义的错误,原因未知,我的解决办法时采用 postgresql 10.15 编译好的 describe.o 文件进行替换,该文件我已经编译好了,并放置在源码的 build.obj 目录下,方法如下:
    a、拷贝文件 describe.o 文件到编译文件夹的 src/bin/psql 目录下
       # cp /tmp/postgresql-11.10/build.obj/describe.o /tmp/objdir/src/bin/psql

    b、进入编译文件夹的 src/bin/psql 目录下,对 psql 进行单独编译
       # cd /tmp/objdir/src/bin/psql
       # gmake

    c、再次进入编译文件夹 /tmp/objdir ,对剩余的目标文件进行完整编译
       # cd /tmp/objdir/
       # gmake


Step 5:配置使用环境,使用 PostgreSQL 11.10
1、创建用户,进行使用前初始化。
# groupadd postgres
# mkdir /home
# chmod 0775 /home
# useradd -d /home/postgres -g postgres -s /bin/bash -m postgres
# passwd postgres
<选择 1 , 连续两次输入用户密码 >
2、编辑 /home/postgres/.bash_profile 文件,添加环境变量参数。
在:
export BASH_ENV
下面加入:
source $BASH_ENV

3、编辑 /home/postgres/.bashrc 文件,添加环境变量参数。
在文件最后,加入如下语句:
export PG_VERSION=11.10
export PG_HOME=/opt/PostgreSQL/${PG_VERSION}
export PGDATA=${HOME}/data
export PGLOG=${PGDATA}/pg_log
export PATH=$PATH:$PG_HOME/bin:.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PG_HOME/lib:.

4、切换用户到 postgres
# su – postgres

5、创建数据库实例目录
$ mkdir data

6、初始化数据库实例
$ initdb -E utf-8 -U postgres –W
连续两次数据 postgres 密码

进入 data 目录,修改数据库配置文件
$ cd data
$ mkdir pg_log
$ chmod 0700 pg_log
$ vi pg_hba.conf
修改
local   all             all                                     trust

local   all             all                                     md5

修改
host    all             all             127.0.0.1/32            trust

host    all             all             127.0.0.1/32            md5
并在其下面添加
host    all             all               0.0.0.0/0             md5

修改 postgresql.conf 文件
$ vi postgresql.conf

修改:
#listen_addresses = 'localhost'


listen_addresses = '*'

修改
#port = 5432

port = 5432

修改
#password_encryption = md5

password_encryption = md5

启动 postgresql 数据库实例
$ pg_ctl -D ${PGDATA} -l ${PGDATA}/pg_log/startlog start

查看是否正常:
$ psql –l
$ passwd:
数据数据库用户(postgres)密码

如果显示:
                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres  | postgres | UTF8     | C       | C     |
 template0 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | C       | C     | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(3 rows)

则表示成功




阅读(786) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~