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 :


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


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/ 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, is the IP address of the uClinux board, and 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   trust

Log on the uClinux machine and run :

# testlibpq "hostaddr= 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
template0      1              0              t              f              1697
4          427            427                                          {=,postg

Sample Makefile for uClinux using the PostgreSQL client libs

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

EXEC = your_prog
OBJS = your_prog.o

all: $(EXEC)

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

        $(ROMFSINST) /bin/$(EXEC)

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