diff options
author | Mark Felder <felderado@gmail.com> | 2009-05-21 00:50:06 -0500 |
---|---|---|
committer | Andreas Unterkircher <unki@netshadow.at> | 2009-05-27 20:04:24 +0200 |
commit | 7ec5e634d78ebc0df5940b6523e346d5e5a8d8bc (patch) | |
tree | 293a139635f3665f995569ecc217fbc7a74afb66 /lib/exilog_sql.pm | |
parent | fb6b47fd9ef31681bb65703bf4439dad095f01ac (diff) | |
download | exilog-7ec5e634d78ebc0df5940b6523e346d5e5a8d8bc.zip exilog-7ec5e634d78ebc0df5940b6523e346d5e5a8d8bc.tar.gz exilog-7ec5e634d78ebc0df5940b6523e346d5e5a8d8bc.tar.bz2 |
* PostgreSQL fixes
- missing set/clear action subroutines added for postgres
- postgres doesn't need to run the optimize routine
assuming autovacuum isn't disabled
- postgres was missing heartbeat table -- added in the
sql schema
- extended the shadow_transport column from 128 to 255
chars -- was
- running into issues with too long fields trying to be
inserted
- fix heartbeat feature - PostgreSQL doesn't support a
REPLACE SQL function, fixes #178
Signed-off-by: Mark Felder <felderado@gmail.com>
Diffstat (limited to 'lib/exilog_sql.pm')
-rw-r--r-- | lib/exilog_sql.pm | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/lib/exilog_sql.pm b/lib/exilog_sql.pm index 8dcc348..e1dd3cd 100644 --- a/lib/exilog_sql.pm +++ b/lib/exilog_sql.pm @@ -149,10 +149,20 @@ sub _pgsql_sql_count { return @{$tmp}[0]; }; +# Postgres has no REPLACE command so the best thing to do is +# check to see if there exists any heartbeat record before +# attempting to UPDATE one. If it's not there, lets INSERT one. sub _pgsql_sql_update_heartbeat { my $now = time(); + my $existing_beat = $dbh->do("SELECT timestamp from heartbeats WHERE server = '". $config->{agent}->{server} ."'"); - $dbh->do("REPLACE heartbeats SET server='". $config->{agent}->{server} ."', timestamp='". $now ."'"); + if ($existing_beat != '1') { + $dbh->do("INSERT INTO heartbeats(timestamp, server) VALUES('". $now ."', '". $config->{agent}->{server} ."')"); + } + else + { + $dbh->do("UPDATE heartbeats SET timestamp = '". $now ."' WHERE server = '". $config->{agent}->{server} ."'"); + } }; sub _pgsql_sql_queue_delete { @@ -213,15 +223,26 @@ sub _pgsql_sql_queue_add { $dbh->do("INSERT INTO queue (".join(',',@fields).") VALUES(".join(',',@vals).")"); }; -sub _pgsql_sql_optimize { - my $where = shift || "nothing"; +sub _pgsql_sql_queue_set_action { + my $server = shift; + my $message_id = shift; + my $action = shift; - my $sql = "OPTIMIZE TABLE ".$where; - my $sh = $dbh->prepare($sql); - $sh->execute; - $sh->finish; + $dbh->do("UPDATE queue SET action=".$dbh->quote($action). + " WHERE server=".$dbh->quote($server). + " AND message_id=".$dbh->quote($message_id)); +}; - return 1; +sub _pgsql_sql_queue_clear_action { + my $server = shift; + my $message_id = shift; + + $dbh->do("UPDATE queue SET action=NULL WHERE server=".$dbh->quote($server). + " AND message_id=".$dbh->quote($message_id)); +}; + +sub _pgsql_sql_optimize { + return 1; #postgres doesn't need to do anything as long as autovaccum is on }; sub _pgsql_sql_delete { |