PostgreSQL 9 bytea_output and CGI::Session

PostgreSQL 9 introduces a new bytea output format, hex. This new format can cause problems for programs expecting the traditional output format.

I ran into this problem with several perl scripts using CGI::Application::Plugin::Session. I had just upgraded a database server from PostgreSQL 8.3 to 9.1. The scripts could connect to the but would report errors like the following:

	Error executing class callback in prerun stage: No session object!
	This module depends on CGI::Application::Plugin::Session!
	(or you need to use the -dont_use_session config parameter) at ...

It turns out that the culprit was the new hex output format used by PostgreSQL 9.x. CGI::Session was unable to decode the resulting data and would fail to load existing sessions.

The fix is easy. Simply use the following command to set the bytea output format for a given database:

	ALTER DATABASE database SET bytea_output = 'escape';

Additional details can be found in the Client Connection Defaults section of the PostgreSQL documentation.

Comments are closed.