CGI::Se...tgresql(3)

πŸ’… CGI::Session::Driver::postgresql

Okay bestie, so this is the Perl page for CGI::Session::Driver::postgresql β€” like, it's the PostgreSQL driver for CGI::Session, filed under User Contributed Perl Documentation. Sit down, grab a strawberry drink πŸ“, and let's get into it.


✨ SYNOPSIS ✨

use CGI::Session;
$session = CGI::Session->new("driver:PostgreSQL", undef, {Handle=>$dbh});

That's it. That's the whole vibe check. πŸ¦‹


πŸŽ€ DESCRIPTION πŸŽ€

CGI::Session::PostgreSQL is a CGI::Session driver whose entire job β€” its moment, its main character energy β€” is storing your session data in a PostgreSQL table. No cap. πŸ‘‘


🌸 STORAGE 🌸

Alright, before you can use any of the DBI-based session drivers, you gotta make sure there's a compatible database table already sitting there for CGI::Session to work with. Like, it can't manifest a table out of pure vibes, bestie. πŸ’€

This command right here will produce the minimal requirements in most SQL databases:

CREATE TABLE sessions (
    id CHAR(32) NOT NULL PRIMARY KEY,
    a_session BYTEA NOT NULL
);

and then inside your code you use:

use CGI::Session;
$session = CGI::Session->new("driver:PostgreSQL", undef, {Handle=>$dbh, ColumnType=>"binary"});

Bestie. Pay attention to the ColumnType argument β€” this is the important part, iykyk. PostgreSQL's text type has problems when it tries to hold a null character. (That's the thing known as "\0" in Perl β€” do not confuse it with SQL NULL, they are literally not the same thing, okay?? 😭)

If you know there's no chance of ever having a null character in the serialized data, you can leave off the ColumnType attribute. But honestly? Using a BYTEA column type together with "ColumnType => 'binary'" is recommended when you're using Storable as the serializer, or if there's any possibility at all that a null value will show up in any of the serialized data. Just do it. Slay. ✨


πŸ¦‹ Wanna use different column names?

Mood. Just change the 'create table' statement, and then simply do this:

$s = CGI::Session->new('driver:pg', undef,
{
    TableName=>'session',
    IdColName=>'my_id',
    DataColName=>'my_data',
    DataSource=>'dbi:pg:dbname=project',
});

or

$s = CGI::Session->new('driver:pg', undef,
{
    TableName=>'session',
    IdColName=>'my_id',
    DataColName=>'my_data',
    Handle=>$dbh,
});

Two options, same energy, pick your fighter. 🫢

For more deets see CGI::Session::Driver::DBI, the parent class β€” it's giving founder, it's giving original. πŸ‘‘

Also go see the sqlite driver, which exercises a different method for dealing with binary data. Different method, different era. 🌈


Copyright (C) 2002 Cosimo Streppone. All rights reserved. This library is free software and can be modified and distributed under the same terms as Perl itself. πŸŽ€


πŸ‘‘ AUTHORS πŸ‘‘

  • Cosimo Streppone <cosimo@cpan.org> β€” heavily based on the CGI::Session::MySQL driver by Sherzod Ruzmetov, original author of CGI::Session. Respect the lineage fr fr.
  • Matt LeBlanc contributed significant updates for the 4.0 release. Iconic behavior. ⭐

πŸ’œ LICENSING πŸ’œ

For additional support and licensing see CGI::Session 🧚


Okay that's the whole page, you ate that πŸ’… β€” this was CGI::Se...tgresql(3) from the User Contributed Perl Documentation, perl v5.42.2, dated 2026-07-28. Go forth and store your sessions, bestie. πŸ¦‹πŸ’–
πŸ“¦ where this page comes from