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

全部博文(129)

文章存档

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-12-23 23:56:19

纯干货,无废话。

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


编译需要的前置条件:
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 12.5 必须使用 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 12.5 的安装,过程如下:
Step 1:
下载 postgresql-12.5.tar.bz2 文件,放置在 /tmp 目录下,并展开压缩文件:
# cd /tmp
# bzip2 –d -c postgresql-12.5.tar.bz2 | tar xvf -

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

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

点击(此处)折叠或打开

  1. #define C_H

下面加入:

点击(此处)折叠或打开

  1. #include <sys/time.h>

在:

点击(此处)折叠或打开

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

下面加入:

点击(此处)折叠或打开

  1. #ifdef FLEXIBLE_ARRAY_MEMBER
  2. #undef FLEXIBLE_ARRAY_MEMBER
  3. #define FLEXIBLE_ARRAY_MEMBER 512
  4. #else
  5. #define FLEXIBLE_ARRAY_MEMBER 512
  6. #endif

2、修改 postgresql-12.5/src/backend/storage/lmgr/spin.c
将其中的:

点击(此处)折叠或打开

  1. #ifndef HAVE_ATOMICS
  2. #define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES + NUM_ATOMICS_SEMAPHORES)
  3. #else
  4. #define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES)
  5. #endif /* DISABLE_ATOMICS */

修改为:

点击(此处)折叠或打开

  1. #ifndef HAVE_ATOMICS
  2. #define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES + NUM_ATOMICS_SEMAPHORES + 128)
  3. #else
  4. #define NUM_EMULATION_SEMAPHORES (NUM_SPINLOCK_SEMAPHORES+128)
  5. #endif /* DISABLE_ATOMICS */

3、在 postgresql-12.5/src/template 目录下添加文件 sco , 内容如下:

点击(此处)折叠或打开

  1. CC="$CC -b elf"

4、在 postgresql-12.5/src/template 目录下添加文件 unixware , 内容如下:

点击(此处)折叠或打开

  1. if test "$GCC" != yes; then
  2.   # The -Kno_host is for a bug in the compiler. See -hackers
  3.   # discussion on 7-8/Aug/2003.
  4.   cat >conftest.c <<__EOF__
  5. extern char *strcpy(char *, const char *);

  6. static void f(char *p, int n){
  7.         strcpy(p+n,"");
  8. }
  9. void g(void){
  10.         f(0, 0);
  11. }
  12. __EOF__

  13.   # Debugging and optimization are mutually exclusive
  14.   if test "$enable_debug" != yes; then
  15.     CFLAGS="-O"
  16.   fi
  17.   if $CC -c -O -Kinline conftest.c >conftest.err 2>&1; then
  18.     CFLAGS="$CFLAGS -Kinline"
  19.   else
  20.     CFLAGS="$CFLAGS -Kinline,no_host"
  21.   fi
  22.   rm -f conftest.*

  23.   PTHREAD_CFLAGS="-Kpthread"

  24. # The effect of doing threading for the backend does not work
  25. # because of a threading bug that appears in the regression tests:
  26. #
  27. # in make check, the plpgsql test (plpgsql.sql)
  28. # set statement_timeout to 1000;
  29. # select blockme();
  30. # reset statement_timeout;
  31. #
  32. # per report from Olivier PRENANT <ohp@pyrenet.fr>

  33. fi

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

5、修改 postgresql-12.5/src/bin/psql/describe.c 文件,将其中的:

点击(此处)折叠或打开

  1. processSQLNamePattern(pset.db, &buf, pattern,
  2.                                                   !showSystem && !pattern, false,
  3.                                                   NULL, "n.nspname", NULL,
  4.                                                   NULL);

全部修改成:

点击(此处)折叠或打开

  1. if ( !showSystem && !pattern )
  2.         processSQLNamePattern(pset.db, &buf, pattern,
  3.                                                   true, false,
  4.                                                   NULL, "n.nspname", NULL,
  5.                                                   NULL);
  6. else
  7.         processSQLNamePattern(pset.db, &buf, pattern,
  8.                                                   false, false,
  9.                                                   NULL, "n.nspname", NULL,
  10.                                                   NULL);
=======================================================================================================
= 注意:这个文件中类似的地方,有多处,需要耐心修改。
= 主要的原因是 sco openserver 6.0.0Ni 上的 c99 不支持在函数中的类似 !showSystem && !pattern 写法,必须
= 明确的告知函数中传入的 bool 值是 true 或者是 false ,否则编译时会报 ERROR 没有定义的错误。
======================================================================================================

6、修改 postgresql-12.5/src/backend/options/util/plancat.c 文件,在函数:

点击(此处)折叠或打开

  1. bool
  2. relation_excluded_by_constraints(PlannerInfo *root,
  3.                                                                  RelOptInfo *rel, RangeTblEntry *rte)

中找到如下位置:

点击(此处)折叠或打开

  1. include_notnull = (!rte->inh || rte->relkind == RELKIND_PARTITIONED_TABLE);

将其修改为:

点击(此处)折叠或打开

  1. include_notnull = ( rte->inh == 0 || rte->relkind == RELKIND_PARTITIONED_TABLE) ? true : false ;
========================================
=  原因同第 5 点
========================================

7、在 postgresql-12.5/src/include/port/ 目录下添加文件 sco.h , 内容如下:

点击(此处)折叠或打开

  1. /*
  2.  * src/include/port/sco.h
  3.  *
  4.  * see src/backend/libpq/pqcomm.c */
  5. #define SCO_ACCEPT_BUG

  6. #define USE_UNIVEL_CC

8、在 postgresql-12.5/src/include/port/ 目录下添加文件 unixware.h , 内容如下:

点击(此处)折叠或打开

  1. /*
  2.  * src/include/port/unixware.h
  3.  *
  4.  * see src/backend/libpq/pqcomm.c */
  5. #define SCO_ACCEPT_BUG

  6. /***************************************
  7.  * Define this if you are compiling with
  8.  * the native UNIXWARE C compiler.
  9.  ***************************************/
  10. #define USE_UNIVEL_CC

9、在 postgresql-12.5/src/makefiles/ 目录下添加 sco 系统的编译文件 Makefile.sco ,内容如下:

点击(此处)折叠或打开

  1. AROPT = cr
  2. export_dynamic = -Wl,-Bexport

  3. DLSUFFIX = .so
  4. ifeq ($(GCC), yes)
  5. CFLAGS_SL = -fpic
  6. else
  7. CFLAGS_SL = -K PIC
  8. endif

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

10、在 postgresql-12.5/src/makefiles/ 目录下添加 unixware 系统的编译文件 Makefile.unixware ,内容如下:

点击(此处)折叠或打开

  1. AROPT = crs
  2. ifeq ($(with_gnu_ld), yes)
  3.     export_dynamic = -Wl,-E
  4. else
  5.     export_dynamic = -Wl,-Bexport
  6. endif

  7. ifeq ($(ld_R_works), yes)
  8. ifeq ($(with_gnu_ld), yes)
  9.     rpath = -Wl,-rpath,'$(rpathdir)'
  10. else
  11.     rpath = -Wl,-R'$(rpathdir)'
  12. endif
  13. endif

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

  16. DLSUFFIX = .so
  17. ifeq ($(GCC), yes)
  18. CFLAGS_SL = -fpic
  19. else
  20. CFLAGS_SL = -K PIC
  21. endif
  22. ifeq ($(GCC), yes)
  23. SO_FLAGS = -shared
  24. else
  25. SO_FLAGS = -G
  26. endif

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

  30. sqlmansect = 5sql

11、在 postgresql-12.5/configure 文件中,添加编译操作系统环境描述内容,在:

点击(此处)折叠或打开

  1. openbsd*) template=openbsd ;;

下面加入:

点击(此处)折叠或打开

  1. sco*) template=sco ;;

在:

点击(此处)折叠或打开

  1. solaris*) template=solaris ;;

下面加入:

点击(此处)折叠或打开

  1. sysv5*) template=unixware ;;

在:

点击(此处)折叠或打开

  1. if test "$ac_cv_prog_cc_c99" = no; then
  2.     as_fn_error $? "C compiler \"$CC\" does not support C99" "$LINENO" 5
  3. fi

上面加入

点击(此处)折叠或打开

  1. ac_cv_prog_cc_c99=yes

变成:

点击(此处)折叠或打开

  1. ac_cv_prog_cc_c99=yes
  2. if test "$ac_cv_prog_cc_c99" = no; then
  3.     as_fn_error $? "C compiler \"$CC\" does not support C99" "$LINENO" 5
  4. fi

12、在 postgresql-12.5/configure.in 文件中,添加编译操作系统环境描述内容,在:

点击(此处)折叠或打开

  1. openbsd*) template=openbsd ;

下面加入:

点击(此处)折叠或打开

  1. sco*) template=sco ;

在:

点击(此处)折叠或打开

  1. solaris*) template=solaris ;

下面加入:

点击(此处)折叠或打开

  1. sysv5*) template=unixware ;;

在:

点击(此处)折叠或打开

  1. if test "$ac_cv_prog_cc_c99" = no; then
  2.     AC_MSG_ERROR([C compiler "$CC" does not support C99])
  3. fi

上面加入:

点击(此处)折叠或打开

  1. ac_cv_prog_cc_c99=yes

变成:

点击(此处)折叠或打开

  1. ac_cv_prog_cc_c99=yes
  2. if test "$ac_cv_prog_cc_c99" = no; then
  3.     AC_MSG_ERROR([C compiler "$CC" does not support C99])
  4. fi

13、修改 postgresql-12.5/src/Makefile.shlib 文件,在其中加入共享库编译时的 sco 和 unixware 的支持。
在:

点击(此处)折叠或打开

  1. ifeq ($(PORTNAME), solaris)
  2.   ifeq ($(GCC), yes)
  3.     LINK.shared = $(COMPILER) -shared
  4.   else
  5.     LINK.shared = $(COMPILER) -G
  6.   endif
  7.   ifdef soname
  8.     ifeq ($(with_gnu_ld), yes)
  9.       LINK.shared += -Wl,-soname,$(soname)
  10.     else
  11.       LINK.shared += -h $(soname)
  12.     endif
  13.   endif
  14. endif

下面加入:

点击(此处)折叠或打开

  1. ifeq ($(PORTNAME), sco)
  2.   ifeq ($(GCC), yes)
  3.     LINK.shared = $(CC) -shared
  4.   else
  5.     LINK.shared = $(CC) -G
  6.     endif
  7.   LINK.shared += -Wl,-z,text
  8.   ifdef soname
  9.     LINK.shared += -Wl,-h,$(soname)
  10.   endif
  11. endif

  12. ifeq ($(PORTNAME), unixware)
  13.   ifeq ($(GCC), yes)
  14.     LINK.shared = $(CC) -shared
  15.   else
  16.     LINK.shared = $(CC) -G
  17.   endif
  18.   LINK.shared += -Wl,-z,text
  19.   ifdef soname
  20.     LINK.shared += -Wl,-h,$(soname)
  21.   endif
  22. endif

14、拷贝 postgresql-12.5/src/backend/utils/adt/jsonpath_scan.c 到 postgresql-12.5/src/include
    # cp 
postgresql-12.5/src/backend/utils/adt/jsonpath_scan.c postgresql-12.5/src/include

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

2、写编译配置文件 build.sh,内容如下:

点击(此处)折叠或打开

  1. ../postgresql-12.5/configure \
  2.         --prefix=/opt/PostgreSQL/12.5 \
  3.         --build=i586-sco-sysv5 \
  4.         --host=i586-sco-sysv5 \
  5.         --disable-spinlocks \
  6.         --disable-thread-safety \
  7.         --without-tcl \
  8.         --with-perl \
  9.         --with-ldap \
  10.         --with-openssl

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

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

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

Step 5:配置使用环境,使用 PostgreSQL 12.5
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 文件,添加环境变量参数。
在:

点击(此处)折叠或打开

  1. export BASH_ENV

下面加入:

点击(此处)折叠或打开

  1. source $BASH_ENV

3、编辑 /home/postgres/.bashrc 文件,添加环境变量参数。
在文件最后,加入如下语句:

点击(此处)折叠或打开

  1. export PG_VERSION=12.5
  2. export PG_HOME=/opt/PostgreSQL/${PG_VERSION}
  3. export PGDATA=${HOME}/data
  4. export PGLOG=${PGDATA}/pg_log
  5. export PATH=$PATH:$PG_HOME/bin:.
  6. 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
修改

点击(此处)折叠或打开

  1. local all all trust

为:

点击(此处)折叠或打开

  1. local all all md5

修改

点击(此处)折叠或打开

  1. host all all 127.0.0.1/32 trust

为:

点击(此处)折叠或打开

  1. host all all 127.0.0.1/32 md5

并在其下面添加:

点击(此处)折叠或打开

  1. host all all 0.0.0.0/0 md5

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

修改:

点击(此处)折叠或打开

  1. #listen_addresses = 'localhost'

为:

点击(此处)折叠或打开

  1. listen_addresses = '*'

修改

点击(此处)折叠或打开

  1. #port = 5432

为:

点击(此处)折叠或打开

  1. port = 5432

修改

点击(此处)折叠或打开

  1. #password_encryption = md5

为:

点击(此处)折叠或打开

  1. 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)

则表示成功
















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