PostgreSQL client for uClinux

This is about compiling and running the PostgreSQL client libraries on uClinux. Only the client part of PostgreSQL is build, the PostgreSQL tarball contains also the server which makes it bigger than necessary (for uClinux). But I prefer to publish a patch on the original tarball than building a specific source package.

Software download

The uClinux distribution needed is 20040218.

Download the following files :

Installation

extract the postgresql tarball into the uClinux-dist/user directory, rename it to postgresql then apply the patch as follow :

cd postgresql
zcat path_to_postgresql_patch_file | patch -p1

Compilation

Quick setup

In uClinux-dist/user/makefile add the postgresql directory in the list of directories to compile :

dir_y += games
dir_y += postgresql    # this is the line to add

all: config

then compile a new image.

Normal setup

Create a new config option to compile postgresql in uClinux-dist/config/config.in and add the corresponding rule in uClinux-dist/user/Makefile. For more info, have a look at Adding-User-Apps-HOWTO in the uClinux-dist/Documentation directory.

then compile a new image.

Test installation

In the example below, 192.168.1.2 is the IP address of the uClinux board, and 192.168.1.10 is the IP address of the PostgreSQL server.

Install postgresql on a server, do not forget to allow TCPIP connection in the server configuration file postgresql.conf :

tcpip_socket = true

And allow the client to connect to the server by adding client adress in the pg_hba.conf file :

# TYPE  DATABASE    USER        IP-ADDRESS        IP-MASK           METHOD
host    all         all         192.168.1.2       255.255.255.255   trust

Log on the uClinux machine and run :

# testlibpq "hostaddr=192.168.1.10 user=postgres dbname=template1"
datname        datdba         encoding       datistemplate  datallowconn   datl
astsysoid  datvacuumxid   datfrozenxid   datpath        datconfig      datacl
                                                                               
                                                                                                                                                           
                                                                                
template1      1              0              t              t              1697
4          427            427                                          {=,postg
res=CT}
template0      1              0              t              f              1697
4          427            427                                          {=,postg
res=CT}

Sample Makefile for uClinux using the PostgreSQL client libs

CPPFLAGS += \
        -I../postgresql/src/interfaces/libpq \
        -I../postgresql/src/include/libpq \
        -I../postgresql/src/include
LDFLAGS += \
        -L../postgresql/src/interfaces/libpq \
        -L../postgresql/src/port
LDLIBS := -lpq -lpgport $(LIBCRYPT) $(LDLIBS)

EXEC = your_prog
OBJS = your_prog.o

all: $(EXEC)

$(EXEC): $(OBJS)
        $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)

romfs:
        $(ROMFSINST) /bin/$(EXEC)

clean:
        -rm -f $(EXEC) *.elf *.gdb *.o

uClinux port bug

Don't trust the pg_config.h file in my patch, I have generated it on a x86 linux machine, most of the define here are not used by the PostgreSQL client libraries and I left them untouched in the file even so they are not right for uClinux. If you want to compile other modules from the PostgreSQL tarball, be prepared to modify this file for uClinux.

sig