PostgresSQL on QNX 6
--------------------
last updated:          $Date: 2002/05/14 00:24:36 $
author/maintainer:     Igor Kovalenko (igor.kovalenko@motorola.com)

Short story
-----------

0) passwd pgsql (create user pgsql)
1) su - pgsql
2) gzip -cd <path> | tar -xvf -
3) cd <path_to_source>
4) autoconf
5) ./configure
6) make
7) make check - it should pass all regression tests
8) su
9) make install; exit

Try to run following shell script (as user pgsql):
--- cut ---
#!/bin/sh

DATABASE=$1
DATABASE=${DATABASE:-database}

echo
echo WARNING!
echo This script will destroy and recreate sample database
echo located in directory \'$DATABASE\'. The postmaster will
echo be restarted if running.
echo To use an existing database, start postmaster using pg_ctl:
echo
echo '    pg_ctl -D database -l logfile start'
echo "    ('pg_ctl -o\"-i\" -D database -l logfile start' if you're not using Unix Domain Sockets)"
echo
echo Make sure you have environment set up in your .profile
echo This script creates ~/.pgsql shell script which sets up
echo environment properly and can be sourced by you .profile
echo
echo Press Ctrl-C to cancel in 5 secs ...
sleep 5

cat <<\@ >~/.pgsql
#
# Uncomment this line to use AF_INET socket for communications
# Default is to use AF_UNIX socket
#
#export PGHOST=${PGHOST:-localhost}
export PGPATH=/usr/local/pgsql
export PATH=$PATH:${PGPATH}/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PGPATH}/lib
@

. ~/.pgsql

cat <<@ >init.sql
CREATE TABLE person (
        name            text,
        age             int4,
        location        text
);
INSERT INTO person VALUES ('igor', 32, 'Illinois');
INSERT INTO person VALUES ('cdm', 28, 'New Mexico');
INSERT INTO person VALUES ('camz', 99, 'Alberta');
@


cat <<@ >query.sql
SELECT * from person;
@

rm -rf $DATABASE
slay -f -sSIGTERM postmaster >/dev/null 2>&1
initdb -D $DATABASE
if [ ! -z PGHOST ]; then
    postmaster -i -D $DATABASE >logfile 2>&1 &
else
    postmaster -D $DATABASE >logfile 2>&1 &
fi
sleep 3
echo Setting up ODBC compatibility mode ...
psql -d template1 -f ${PGPATH}/share/odbc.sql
createdb postgres

echo
echo "Sample database '$DATABASE' ready. Populating sample table PERSON ..."
echo
psql -d postgres -f init.sql
echo
echo "Executing sample query: 'SELECT * from PERSON;'"
echo
psql -d postgres -f query.sql
echo
echo "Run 'psql -d postgres' to try your queries (case is important)."
echo
--- cut ---


Long Story
----------

The main issue with porting to QNX6 was implementation of IPC primitives
used by postgres. They are historically based on SysV shared memory and
semaphores which are messy, inefficient and caused trouble for all
platforms not derived directly from Unix.

This port is first attempt to use POSIX IPC primitives (shared memory
and semaphores) instead of struggling with emulation of SysV ones, like
all other ports used to do.

Postgres code in fact has abstraction layer for those things, which
unfortunately happens to be too SysV-oriented to use transparently.
So this port adds another (POSIX) implementation of IpcSemaphoreXXX()
and IpcSharedMemXXX() routines (see ipc.c & ipc.h) when HAVE_POSIX_IPC
is defined. The IpcSemaphoreCreate() had to be given new prototype
since old one was only suitable for SysV semaphores. Due to that, 
two other modules - spin.c and proc.c also had to be changed to call
that function with proper arguments. All changes are guarded by #ifdefs
so the code still builds and runs on systems like Linux and Solaris.

Another issue is low-level locking primitives. Postgres has assembler
implementation of spinlocks for all major supported architectures and it
actually would work on QNX6 but only on i386 and perhaps ARM, so long 
as GCC is your compiler. Spinlocks however are not really best choice
unless you're running on SMP system. Besides, on other platforms/compilers
postrges would default to using SysV sempahores as 'low-level' lock,
which makes performance unacceptable. This port adds implementation
of low-level locks using POSIX mutexes and POSIX spinlocks. Platforms
which support those need to select desired mechanism in their respective
header files (qnx6.h selects POSIX mutexes by default). See s_lock.h
for details.

The only other QNX6-ism in the code is forced definition of DBL_MAX in guc.c
which is needed because limits.h on QNX6 defines it in a way incompatible
with using as constant initializer. Another QNX-ism used to be strange
behavior of qsort() but that was taken care of when QNX4 port was made...
That port however has left QNX4-isms everywhere in form of #ifdef(__QNX__)
which is also defined on QNX6. That had to be 'unported' in some cases.
Attempt of QNX4 port to supply valid results for regression tests also
interferes with QNX6 since output of uname is close enough. That made
it necessary to have some seemingly silly rules in the resultmap for QNX6,
just to avoid being confused for QNX4.

Remaining modifications mostly deal with configure and makefiles, to enable
building dynamic libraries, etc. Some dummy code was added for that as well,
just like on Solaris - see dynaloader/qnx6.*.

Finally, pay attention to proper choice of transport protocol. The default
is Unix Domain sockets and QNX 6 does support them from version 6.2 
(although with some reservations which seem to be irrelevant to Postgres). 
That functionality however is not considered mature at this point so use at 
your own risk. For critical applications clients should use TCP/IP sockets. 
You can either set "tcpip_socket = true" in your postgresql.conf or to 
start postmaster with the -i option. You also need to set PGHOST 
variable to your host IP or name (e.g., localhost) but do NOT do that
if you use Unix Domain sockets.


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

QNX6.2 or later is strongly recommended. It may build and run on 6.1 but 
without Unix Domain sockets only. You need to have GNU autoconf installed
to generate ./configure script. Note that 6.1 had linking bugs which may or
may not bite you, so success is uncertain.


Building:
---------

Regenerate configure script with autoconf to get QNX6 recognized.
Then just ./configure; make; make check; make install


Regression tests:
-----------------

All 79 tests pass as of version 7.2.1.

Good luck,
-- igor

