build install postgresql 14.0 and use for sco openserver 6.0.0 d2m1
	==================================================================================================================================
	在 sco openserver6 系统上编译安装 postgresql 14.0
	纯干货,无废话。
	写在前面的话:
	postgresql 数据库软件从 10 版本开始,就不再支持 sco openserver6 系统了,但这并不代表我们无法在 sco openserver 6 系统上安装使用 postgresql 10 以上的数据库版本,只是相对麻烦一点。
	因为 postgresql 数据库是使用原生的 c 语言开发的,这对我们是一个很好的信号,我们有理由相信,经过简单的修改,我们是能够在 sco openserver 6 系统上使用 postgresql 14.0 的,当然,前提是你必须要有足够的耐心。
	编译需要的前置条件:
	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 14.0 必须使用 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 14.0 在 sco openserver 6 系统上的安装使用
	做好前置工作后,我们开始进入 postgresql 14.0 的安装,过程如下:
	step 1:
	下载 postgresql-14.0.tar.bz2 文件,放置在 /tmp 目录下,并展开压缩文件:
	# cd /tmp
	# bzip2 –d -c postgresql-14.0.tar.bz2 | tar xvf -
	step 2:
	修改 postgresql 14.0 的安装程序源码,添加一些内容:
	1、修改 postgresql-14.0/src/include/c.h 文件,在其中加入如下内容:
	在:
	下面加入:
	查找:
	
		
		
			
				- 
					#define flexible_array_member /* empty */
				
 
			
		 
	 
 
	将其修改为:
	
	
		
		
			
				- 
					#ifndef flexible_array_member
				 
				- 
					#define flexible_array_member  512 /* empty */
				 
				- 
					#endif
				
 
			
		 
	 
 
	2、修改 postgresql-14.0/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_semaphores128)
				 
				- 
					#endif /* disable_atomics */
				
 
			
		 
	 
 
	
	3、在 postgresql-14.0/src/template 目录下添加文件 sco , 内容如下:
	4、在 postgresql-14.0/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-14.0/src/bin/psql/describe.c 文件,将其中的:
	
	
		
		
			
				- 
					processsqlnamepattern(pset.db, &buf, pattern,
				 
				- 
					                                                  !showsystem && !pattern, false,
				 
				- 
					                                                  null, "n.nspname", null,
				 
				- 
					                                                  null);
				
 
			
		 
	 
 
	全部修改成:
	
	
		
		
			
				- 
					processsqlnamepattern(pset.db, &buf, pattern,
				 
				- 
					                                                  (!showsystem && !pattern) ? true : false, false,
				 
				- 
					                                                  null, "n.nspname", null,
				 
				- 
					                                                  null);
				
 
			
		 
	 
 
	=======================================================================================================
	= 注意:这个文件中类似的地方,有多处,需要耐心修改。
	= 这个函数的传入参数 !showsystem && !pattern 表示 showsystem 不等于 0 并且 pattern 不等于 0 的时候,返回“真”
	= 否则返回 “假” , 但是 sco openserver 6.0.0ni 上的 c99 不支持在函数中的参数类似 !showsystem && !pattern 写法,
	= 等价的写法必须是 (!showsystem && !pattern) ? true : false
	= 明确的告知函数中传入的 bool 值是 true 或者是 false ,否则编译时会报 error 没有定义的错误。
	======================================================================================================
	6、修改 postgresql-14.0/src/backend/optimizer/util/plancat.c 文件,在函数:
	
	
		
		
			
				- 
					bool
				 
				- 
					relation_excluded_by_constraints(plannerinfo *root,
				 
				- 
					                                                                 reloptinfo *rel, rangetblentry *rte)
				
 
			
		 
	 
 
	中找到如下位置:
	
	
		
		
			
				- 
					include_notnull = (!rte->inh || rte->relkind == relkind_partitioned_table);
				
 
			
		 
	 
 
	将其修改为:
	
	
		
		
			
				- 
					include_notnull = (rte->inh == 0 || rte->relkind == relkind_partitioned_table) ? true : false ;
				
 
			
		 
	 
 
	================================================================================================================
	= 注意:这个地方的赋值操作,(!rte->inh || rte->relkind == relkind_partitioned_table) 表示 !rte->inh 不为“真”,
	= 或者是 rte->relkind 等于 relkind_partitioned_table 时,返回真值,否则返回“假”,并将该布尔值赋值给 include_notnull
	= 该写法在 sco openserver 6.0 的 c 编译器中不支持,会报 error 没有定义的错误。
	= 等价的写法为:include_notnull = (rte->inh == 0 || rte->relkind == relkind_partitioned_table) ? true : false ;
	================================================================================================================
	7、修改  postgresql-14.0/src/backend/access/nbtree/nbtinsert.c 文件:
	在:
	
		
		
			
				- 
					static void
				 
				- 
					_bt_delete_or_dedup_one_page(relation rel, relation heaprel, ...
				
 
			
		 
	 
 
	函数的最后部分,找到:
	
	
		
		
			
				- 
					if (btgetdeduplicateitems(rel) && itup_key->allequalimage)
				 
				- 
					                _bt_dedup_pass(rel, buffer, heaprel, insertstate->itup,
				 
				- 
					                                           insertstate->itemsz, (indexunchanged || uniquedup) );
				
 
			
		 
	 
 
	修改为:
	
	
		
		
			
				- 
					if (btgetdeduplicateitems(rel) && itup_key->allequalimage)
				 
				- 
					                _bt_dedup_pass(rel, buffer, heaprel, insertstate->itup,
				 
				- 
					                                           insertstate->itemsz, (indexunchanged || uniquedup) ? true : false );
				
 
			
		 
	 
 
	说明:
	================================================================================================================
	= 注意:与前面的原因一样
	= 这个函数中的 (indexunchanged || uniquedup) 部分表示 indexunchanged 或者是 uniquedup 为真时,返回“真”,否则返回“假”,
	= 但是这种写法在 sco openserver 6.0 的 c 编译器中不支持,在编译的时候会报 error 没有定义的错误信息,等价的写法为:
	= (indexunchanged || uniquedup) ? true : false
	=================================================================================================================
	8、在 postgresql-14.0/src/include/port/ 目录下添加文件 sco.h , 内容如下:
	
	
		
		
			
				- 
					/*
				 
				- 
					 * src/include/port/sco.h
				 
				- 
					 *
				 
				- 
					 * see src/backend/libpq/pqcomm.c */
				 
				- 
					#define sco_accept_bug
				 
				- 
					
				 
				- 
					#define use_univel_cc
				
 
			
		 
	 
 
	9、在 postgresql-14.0/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
				
 
			
		 
	 
 
	10、在 postgresql-14.0/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 $@ $<
				
 
			
		 
	 
 
	11、在 postgresql-14.0/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
				
 
			
		 
	 
12、在 postgresql-14.0/configure 文件中,添加编译操作系统环境描述内容,在:
 
	
	
		
		
			
				- 
					openbsd*) template=openbsd ;;
				
 
			
		 
	 
 
	下面加入:
	在:
	
	
		
		
			
				- 
					solaris*) template=solaris ;;
				
 
			
		 
	 
 
	下面加入:
	
	
		
		
			
				- 
					sysv5*) template=unixware ;;
				
 
			
		 
	 
 
	在:
	
		
		
			
				- 
					if test "$ac_cv_prog_cc_c99" = no; then
				
 
				- 
					as_fn_error $? "c compiler \"$cc\" does not support c99" "$lineno" 5
				
 
				- 
					fi
				
 
			
		 
	 
 
	上面加入
	变成:
	
	
		
		
			
				- 
					ac_cv_prog_cc_c99=yes
				
 
				- 
					if test "$ac_cv_prog_cc_c99" = no; then
				
 
				- 
					as_fn_error $? "c compiler \"$cc\" does not support c99" "$lineno" 5
				
 
				- 
					fi
				
 
			
		 
	 
13、在 postgresql-14.0/configure.in 文件中,添加编译操作系统环境描述内容,在:
 
	
	
		
		
			
				- 
					openbsd*) template=openbsd ;;
				
 
			
		 
	 
下面加入:
 
	在:
	
	
		
		
			
				- 
					solaris*) template=solaris ;;
				
 
			
		 
	 
 
	下面加入:
	
	
		
		
			
				- 
					sysv5*) template=unixware ;;
				
 
			
		 
	 
 
	在:
	
	
		
		
			
				- 
					if test "$ac_cv_prog_cc_c99" = no; then
				
 
				- 
					ac_msg_error([c compiler "$cc" does not support c99])
				
 
				- 
					fi
				
 
			
		 
	 
 
	上面加入:
	变成:
	
	
		
		
			
				- 
					ac_cv_prog_cc_c99=yes
				
 
				- 
					if test "$ac_cv_prog_cc_c99" = no; then
				
 
				- 
					ac_msg_error([c compiler "$cc" does not support c99])
				
 
				- 
					fi
				
 
			
		 
	 
 
	14、修改 postgresql-14.0/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
				
 
			
		 
	 
 
	15、拷贝 postgresql-14.0/src/backend/utils/adt/jsonpath_scan.c 到 postgresql-14.0/src/include
	
	
		
		
			
				- 
					# cp postgresql-14.0/src/backend/utils/adt/jsonpath_scan.c postgresql-14.0/src/include
				
 
			
		 
	 
step 3:开始准备编译环境:
 
	1、创建编译目录环境,建立一个编译目录,如 /tmp/objdir
	2、写编译配置文件 build.sh,内容如下:
	
	
		
		
			
				- 
					../postgresql-14.0/configure \
				
 
				- 
					--prefix=/opt/postgresql/14.0 \
				
 
				- 
					--build=i586-sco-sysv5 \
				
 
				- 
					--host=i586-sco-sysv5 \
				
 
				- 
					--disable-spinlocks \
				
 
				- 
					--disable-thread-safety \
				
 
				- 
					--without-tcl \
				
 
				- 
					--with-perl \
				
 
				- 
					--with-openssl
				
 
			
		 
	 
 
	3、修改其权限为 0755
	
	
4、进入 /tmp/objdir 目录,开始编译前环境配置。
 
	
	
		
		
			
				- 
					# cd /tmp/objdir
				
 
				- 
					# ../build.sh
				
 
			
		 
	 
 
	step 4:编译安装 postgresql 14.0 软件
	1、开始编译
	
	
step 5:配置使用环境,使用 postgresql 14.0
 
	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=14.0
				
 
				- 
					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                                     scram-sha-256
	修改
	host    all             all             127.0.0.1/32            trust
	为
	host    all             all             127.0.0.1/32            scram-sha-256
	并在其下面添加
	host    all             all               0.0.0.0/0             scram-sha-256
	修改 postgresql.conf 文件
	$ vi postgresql.conf
	修改:
	#listen_addresses = 'localhost'
	为
	listen_addresses = '*'
	修改
	#port = 5432
	为
	port = 5432
	修改
	#password_encryption = scram-sha-256
	为
	password_encryption = scram-sha-256
	启动 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)
	则表示成功
=============================================
特别注意:
    本版本是在 sco openserver 6 d2m1 编译的,如果在 sco openserver 6.0.0 上使用,你可能还有其它的代码需要修改。我比较懒 ^_^. ,没有针对 sco openserver 6.0.0 ni 的系统进行修改。一个简单的使用办法是:
将 sco openserver 6.0 d2m1 服务器上 /usr/lib/libssl.so.1.0 和 /usr/lib/libcrypto.so.1.0 拷贝到 sco openserver 6.0.0 ni 机器的 /usr/lib 目录下,即可正常使用。
^_^.