PostgreSQL on QNX 4
--------------------
last updated:           $Date: 2002/07/09 04:47:07 $

current maintainer:     Bernd Tegge (tegge@repas-aeg.de)
original author:        Andreas Kardos (kardos@repas-aeg.de)

This port is an important step because PostgreSQL is still the only free
relational database with full SQL and ODBC support available for QNX 4.
The only commercial databases available are Empress RDBMS and Velocis
Database Server (not supported for Digital Unix).

The most effort required the emulation of System V semaphore sets,
shared memory and IPC and of some IEEE floating-point functionality.

It is recommended to use the GNU C compiler instead of the Watcom compiler
because the Watcom compiler doesn't support a int8 datatype (long or
long long int) and it does not have a C++ frontend. The only advantage
using Watcom C would be support of Tk and pgaccess.

QNX 4 does not offer native support of shared libraries. Therefore the related
functionality cannot be used. Shared library support could probably be
implemented in future.

QNX 4 does not support UNIX domain sockets. Clients must use TCP/IP
sockets. Therefore you either have to set "tcpip_socket = true" in
your postgresql.conf or to start postmaster with the -i option.
Furthermore it's advisable to set to set the PGHOST or SOCK environment
variable for postmaster in an environment using native QNX networking.
Otherwise the postmaster might not use the IP-Address you think it does :-)

Prerequisites:
--------------

The following prerequisites have been used:

QNX standard:
QNX 4.25, Watcom C 10.6, GNU make

Available from http://www.teaser.fr/~jcmichot/
flex-2.5.4a.tar.gz (flex)
egcs-112-qnx4-r20.tar[.gz] (GNU C)

Available from ftp://ftp.visi.com/users/hawkeyd/qnx/
bison-1.2.5.tar.gz

Available from http://quics.qnx.com/cgi-bin/dir_find.cgi?/usr/free/
perl 5.004_04

from ftp://ftp.freesoftware.com/pub/infozip/zlib/
zlib 1.1.3

tcl8.0.3.tar.Z (Tcl)

In order to achieve meaningful results for the regression tests, you need
a different shell. The standard QNX shell is quite broken with regard to
scripting (even QSSL suggested to use pdksh or bash). Both are available
in source and binaries at
http://quics.qnx.com/cgi-bin/dir_find.cgi?/usr/free/

flex can be built without any problems using the Watcom or GNU C compilers.

The current version of bison (1.2.8 at the time of this writing) does not
build cleanly on QNX4 with gcc installed, but you can download src and
binary of a previous version from the above mentioned ftp site.

download source
GNU C can be installed by
/etc/install -u egcs112-qnx4-r20.tar[.gz]

Although Tcl can be built after some slight code changes using the Watcom
compiler, the GNU C compiler should be used instead. Otherwise it would be
impossible to link postgres built with GNU C together with libtcl8.0.a built
with the Watcom compiler. However, if you are going to build a Watcom version
you must build the tcl and tk libraries with Watcom too.

To make unix/tclUnixTest.c compilable uncomment
#include <sys/resource.h>
in it or
touch /usr/include/sys/resource.h
In unix/Makefile.in replace
	( echo cd $(TOP_DIR)/tests\; source all ) | ./tcltest
by
	( echo cd ../tests\; source all ) | ./tcltest
After that Tcl can be built and tested as stated in README.

Tk cannot be built with GNU C due to the lack of a stack version of the
X11 library. With the Watcom compiler Tk could be built but this is not useful
because of the link problems mentioned above.

Therefore the Tk interface and the pgaccess tool cannot be supported for a GNU C
version of PostgreSQL on QNX 4.

PostgreSQL:
-----------

On QNX 4 some headers are not in the directories expected. To avoid
modifications of the code the following links should be made:

ln -s /usr/local/bin/perl /usr/local/bin/perl5
ln -s /usr/include/errno.h /usr/include/sys/errno.h
ln -s /usr/include/ioctl.h /usr/include/sys/ioctl.h
ln -s /usr/src/pgsql/src/backend/port/qnx4/ipc.h /usr/include/sys/ipc.h
ln -s /usr/src/pgsql/src/backend/port/qnx4/sem.h /usr/include/sys/sem.h
ln -s /usr/src/pgsql/src/backend/port/qnx4/shm.h /usr/include/sys/shm.h

For ecgs-2.91.60 the file
/usr/local/lib/gcc-lib/i386-pc-qnx4/egcs-2.91.66/include/g++/stl_alloc.h
had to be patched (extern "C++" { ... } // extern "C++").
See attached patch.

If all prerequisites are available postgres can be built and installed by
cd pgsql/src
./configure --with-tcl --without-tk --with-perl
gmake > make.log 2>&1
gmake install > make.install.log 2>&1
su
cd interfaces/perl5
gmake install
exit

All other steps can be carried out as stated in the INSTALL file.

Make problems:
--------------

Sometimes the Watcom library manager wlib crashes with SIGSEGV on some
object files. This is a general problem and not PostgreSQL related.
Currently bootstrap.o causes such a crash. The workaround is not to include
the object file into the SUBSYS.o but link it directly. For further information
see backend/Makefile and backend/bootstrap/Makefile.
libpgsql.a currently cannot be generated because of the same problem. But this
doesn't matter since shared libraries are not supported.
(The Makefiles are already changed to ignore this, you don't have to
do anything)

Regression tests:
-----------------
please don't use the QNX shell for the parallel regression tests. Download
bash from quics.qnx.com and run 'make SHELL=/usr/local/bin/bash check'
instead.

The majority of regression tests succeeded. The following tests failed:

geometry:
Some slight deviation in the last digit and "0" instead of "-0".
Can be ignored.

timestamp, tinterval, abstime, horology:
Differences for years before the UNIX epoch. The QNX library probably treats
time_t as unsigned -> dates before 1970 get moved into the far future.
Can be ignored.

create_function_1, create_function_2, create_type, create_operator,
create_view, select_views, triggers, misc, plpgsql:
Error messages due to the lack of shared library support.

rules, select_views:
looks like it fails because it depends on tables created by previously
failing tests.

alter_table:
An expected failure message contains one blank more than expected.
Possibly a faulty output file.

int8, subselect, union
fails for Watcom version because of lacking int8 support.

The current state of this port should be sufficient for lot of applications.


Have fun!

Andreas Kardos
2000-04-04

Bernd Tegge
tegge@repas-aeg.de
2001-12-10

---------------------------------------------------------------------------

*** ./stl_alloc.h.orig	Sat Feb 28 05:17:28 1998
--- ./stl_alloc.h	Tue Nov 23 04:14:09 1999
***************
*** 120,125 ****
--- 120,126 ----
  #pragma set woff 1174
  #endif
  
+ extern "C++" {
  // Malloc-based allocator.  Typically slower than default alloc below.
  // Typically thread-safe and more storage efficient.
  #ifdef __STL_STATIC_TEMPLATE_MEMBER_BUG
***************
*** 682,687 ****
--- 683,689 ----
  # endif
  
  #endif /* ! __USE_MALLOC */
+ } // extern "C++"
  
  #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
  #pragma reset woff 1174


Patch required to build with gcc:

*** /usr/src/postgresql-7.2b3/src/backend/port/qnx4/sem.h       Thu Nov  8 21:37:52 2001
--- src/backend/port/qnx4/sem.h Mon Dec 10 13:22:18 2001
***************
*** 55,60 ****
--- 55,71 ----
        ushort_t        sem_num;                /* semaphore #                  */
        short           sem_op;                 /* semaphore operation          */
        short           sem_flg;                /* operation flags              */
+ };
+
+ /*
+  * command union for semctl.
+  */
+
+ union semun {
+   int val;                    /* value for SETVAL */
+   struct semid_ds *buf;       /* buffer for IPC_STAT, IPC_SET */
+   unsigned short int *array;  /* array for GETALL, SETALL */
+   struct seminfo *__buf;      /* buffer for IPC_INFO */
  };

  extern int    semctl(int semid, int semnum, int cmd, /* ... */ union semun arg);
