Re: [Mojolicious] PostgreSQL connection problem

2019-08-22 Thread Dan Book
I recommend a connection manager for all DBI usage, and for Mojolicious a
great one is Mojo::Pg. A DBI object cannot handle disconnections or
reconnecting on fork, but by storing only a Mojo::Pg object, and getting a
->db from it only when you need to run queries, that ->db call can
reconnect if needed.

-Dan

On Thu, Aug 22, 2019 at 10:59 AM Mark Jones  wrote:

> Hi,
>
> I have an issue with a Mojolicious app that seems to loose connection to a
> Postgres database whenever the postgres service is restarted. Is this
> normal behavior, shouldn't the Mojo app automatically reconnect without
> having to restart hypnotoad?
>
> The error that gets logged is:
> [error] no connection to the server at /var/www/mojoApp...
>
> Postgres db connection:
>
> app->attr(db => sub {
> my $self = shift;
> my $dbh = ('dbname');
> return $dbh;
> });
>
> connect sub:
>
> my ($dbname) = shift;
>
> if($dbname && $dbname ne '')
> {
> my $host='xx.xx.xx.xx';
> my $dsn=qq(dbi:Pg:dbname=$dbname;host=$host);
> my $dbusername = xx;
> my $password = xx;
> my $dbh = DBI->connect($dsn,$dbusername,$password)||
> die("Connect error: $DBI::errstr");
> return $dbh;
> }
>
> Is there something else that I need to add?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/742b60f5-af10-44db-b303-e1631272ca15%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVX3QBP-o89NacUXYMRaCYCyd%2BRnzVYGDKf7_f_Sb3rtmw%40mail.gmail.com.


[Mojolicious] PostgreSQL connection problem

2019-08-22 Thread Mark Jones
Hi,

I have an issue with a Mojolicious app that seems to loose connection to a 
Postgres database whenever the postgres service is restarted. Is this 
normal behavior, shouldn't the Mojo app automatically reconnect without 
having to restart hypnotoad?

The error that gets logged is:
[error] no connection to the server at /var/www/mojoApp...

Postgres db connection:

app->attr(db => sub {
my $self = shift;
my $dbh = ('dbname');
return $dbh;
});

connect sub:

my ($dbname) = shift;

if($dbname && $dbname ne '')
{
my $host='xx.xx.xx.xx';
my $dsn=qq(dbi:Pg:dbname=$dbname;host=$host);
my $dbusername = xx;
my $password = xx;
my $dbh = DBI->connect($dsn,$dbusername,$password)|| 
die("Connect error: $DBI::errstr");
return $dbh;
}

Is there something else that I need to add?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/742b60f5-af10-44db-b303-e1631272ca15%40googlegroups.com.