Send data from PLCNext to PostgreSQL

Hello! I’m trying to send data to PostgreSQL server. The DBFL_SQL Library provided by Phoenix Contact supports MS-SQL and MySQL, and according to my experience does not work with PostgreSQL. What would be the best way to do this? Thank You!

Hello chemicont, I think the simplest way to send data to PostgreSQL server is via C/C++ API (in C++ program), please see the information under following link: https://www.postgresql.org/docs/7.2/libpq.html http://pqxx.org/development/libpqxx/ As integration example, please see the published article in the Makers Blog, demonstrating how to link to sqlite from a PLCnext C++ project. Thanks & Best Regards Eduard

Hi Eduard,

For the following libraries, what is the easiest way to use them on the PLCnext? Do they have to be built from source as there is no apt manager. There is a post about setting up an apt manager, but it is out of date and requires the packages to be updated.
https://www.postgresql.org/docs/7.2/libpq.htmlhttp://pqxx.org/development/libpqxx/

Hello chemicont,</p>\nI think the simplest way to send data to PostgreSQL server is via C/C++ API (in C++ program), please see the information under following link:</p>\n[</a>[https://www.postgresql.org/docs/7.2/libpq.html</a></p>\n[http://pqxx.org/development/libpqxx/</a></p>\n </p>\nAs integration example, please see the published [article in the Makers Blog</a>, demonstrating how to link to sqlite from a PLCnext C++ project.</p>\n </p>\nThanks & Best Regards</p>\nEduard</p>

Hi,
Is there any advice you can provide on how to do this?

Hello CDrive,

I’m not familiar with PostgreSQL server project and can’t give you a detailed description or a working example. I would like to recommend you follows:

                                               1. Compile the project with the needed plcnext SDK (32bit or 64bit system). If the project is compiled for Raspberry Pi (32bit Arm), it can work for AXCF2152 and AXCF1152 controllers without recompiling.
                                               2. Include the binaries and headers into the prroject structure in Eclipse or VS (please use the plcnext project template for consumable libraries)
                                               3. Add the headers and libs in YourProject CMakeList.txt. For example it can be configured as follows (include the needed package). Please see the [libpqxx/BUILDING-cmake.md at master · jtv/libpqxx · GitHub](https://github.com/jtv/libpqxx/blob/master/BUILDING-cmake.md) and **CMake tutorial** for more information.

################# add link targets ####################################################
find_package(ArpDevice REQUIRED)
find_package(ArpProgramming REQUIRED)
find_package(libpqxx REQUIRED)
target_link_libraries(YOUR_PROJECTNAME PRIVATE ArpDevice ArpProgramming pqxx)
###################################################################################
4.It may be neccessary to copy the needed .so-files on the plcnext target under usr/lib (and load it via ldconfig command).
I hope it helps.
BR Eduard

Hello. A new sql library has been released. why is there still no default postgres there…

That’s a good question, which the library developers will be able to answer. You can contact the library developers using the “Contact Developer” button near the top of the app page in the PLCnext Store.