Recipe for postgresql 9.6

I need to build a custom image keeping torizon-core-docker as the base. The custom image i need requires postgresql-9.6 as one of its packages.
bitbake-layers show-recipes shows only postgresql 12.0. How can i make a recipe for postgreql 9.6.
I got into “how to make a custom recipe” section in yocto project documentation. But i am really confused where to start for creating this custom recipe to build postgresql 9.6. Please help.

Started with building postgres 9.4 from sumo branch. But got an error.
~/build-torizon$ devtool add http://ftp.postgresql.org/pub/source/v9.4.20/postgresql-9.4.20.tar.bz2
~/build-torizon/workspace/recipes/postgresql$ bitbake -b postgresql_9.4.20.bb

error log :

> ERROR: postgresql-9.4.20-r0
> do_package: Error executing a python
> function in exec_python_func()
> autogenerated:
> 
> The stack trace of python calls that
> resulted in this exception/failure
> was: File: 'exec_python_func()
> autogenerated', lineno: 2, function:
> 
>      0001:  *** 0002:package_prepare_pkgdata(d)
>      0003: File: '/home/ubuntu/build-torizon/conf/../../layers/openembedded-core/meta/classes/package_pkgdata.bbclass',
> lineno: 44, function:
> package_prepare_pkgdata
>      0040:
>      0041:    # Detect bitbake -b usage
>      0042:    nodeps = d.getVar("BB_LIMITEDDEPS") or False
>      0043:    if nodeps:  *** 0044:        staging_package_populate_pkgdata_dir(pkgdatadir,
> d)
>      0045:        return
>      0046:
>      0047:    start = None
>      0048:    configuredeps = [] Exception: NameError: name
> 'staging_package_populate_pkgdata_dir'
> is not defined
> 
> WARNING: postgresql-9.4.20-r0
> do_package:
> /home/ubuntu/bitbake/lib/bb/build.py:582:
> ResourceWarning: unclosed file
> <_io.TextIOWrapper
> name='/home/ubuntu/build-torizon/workspace/sources/postgresql/singletask.lock'
> mode='a+' encoding='UTF-8'>  
> exec_func(task, localdata)
> 
> ERROR: Logfile of failure stored in:
> /home/ubuntu/build-torizon/tmp-torizon/work/armv7at2hf-neon-tdx-linux-gnueabi/postgresql/9.4.20-r0/temp/log.do_package.7084
> ERROR: Task
> (/home/ubuntu/build-torizon/workspace/recipes/postgresql/postgresql_9.4.20.bb:do_package)
> failed with exit code '1'

Please help how to resolve this error and hence build postgres_9.4.20.

Greetings @Dishant,

While the method of adding postgresql to yocto is fine and can work there may be an easier alternative.

With Torizon we don’t really intend for people to customize the base image too much and rather have them build on top of it using Docker containers. There is already an official container image provided by docker here: Docker Hub

Though if this method doesn’t work for you then may I ask why?

Best Regards,
Jeremias

Greetings @jeremias.tx ,

I am aware that it is not recommended that the base image is customised too much. I will tell you why we want to customise the base image itself with packages like postgres_9.6 and instead not having them using docker containers.

The thing is we already have a software architecture which is dependent on the base image utilities. Using docker containers for such utilities will hamper back compatibility, changes in software architecture and maybe introduce some unknown behaviour. So we are reluctant to use docker containers for such utilities like postgres_9.6.

Unfortunately, in yocto zeus branch only postgres_12.0 exists which can be successfully built. It will be great if you help with building postgres_9.6.

We tried building postgres_9.6 in the base image after flashing a torizon-core-docker base image in the eMMC. And then we also tried taking a clone of the same image from eMMC and could successfully re-flash it. Could you please throw some light on this practice ? What if we prepare a customised base image this way, do you think there are any drawbacks we might not be aware about ?

Best Regards,
Dishant

@jeremias.tx okay i will let you know if i have any further questions. Thanks for your help.

Hi @Dishant

You are welcome. Thanks for the feedback.

@Dishant,

Ok I understand your position better now, but I must ask what about Torizon do you plan to leverage if not the container aspect?

Anyways regarding your original question, the best way to build the right version of postgres would be to create the recipe with the right version yourself. As you’ve noted the zeus branch of the meta-openembedded layer has postgres but version 12.0. The sumo branch has a closer version to what you’re looking for at 9.4.2. What I would suggest is to take reference of this recipe: postgresql\recipes-dbs\meta-oe - meta-openembedded - Collection of OpenEmbedded layers

Basically copy it into your own meta layer therefore creating your own postgres recipe. Then to get the version you desire you’ll have to mess with the SRC_URI variables in the recipe files such that it pulls and builds the right source files for postgres 9.6. Finally you can then just add the postgres 9.6 recipe to the IMAGE_INSTALL list of torizon-core-docker to add it to the image.

Do note that while this does seem straightforward there is no gurantee that simply bumping the version source from 9.4 to 9.6 will just work. There may be build dependencies and other changes required between these two versions.

I still must suggest you at least consider the Docker container method of obtaining postgres 9.6, especially if you are rather new to using the yocto build system. Either way whichever method you choose let me know if I can answer any further questions.

Best Regards,
Jeremias