wordpress-heroku
wordpress-heroku copied to clipboard
Error establishing a database connection
Whenever I visit my site for the first time in the morning, I get: Error establishing a database connection
I receive the same error until I refresh 3-4 times, and then the site works as long as I keep hitting it.
It seems like something isn't running / needs to boot up / etc. but I have no idea how to configure the heroku/wordpress combo to keep the database running.
I'm seeing same thing :(
Try explicitly defining your DB host and port in wp-config. On line 31, replace
$db["host"]
with
'youramazonec2url.com:port'
which you can find by logging into Heroku Postgres. For me, line 31 looks now:
define('DB_HOST', 'ec2-54-243-238-144.compute-1.amazonaws.com:5432');
I was also experiencing this issue, but this fix seems to working well for me (touch wood!).
Thanks for your reply, joshuawalker.
I've made the changes and will wait a few hours to see if when everything goes to "sleep" again, it continues to work.
No problems since! Awesome -- thanks.
FYI I replaced line 18 w/ full URL, which you can get from running heroku config
$db = parse_url('postgres://user:[email protected]:5432/xxx');
No idea why this works tho :) PHP loses access to ENV variable?
Thanks for that, @ryw - seems like a more reliable fix.
Problem occurred again this morning, despite the fix above. :/
Interesting that mine was down too when I hit the URL, and came back a minute later...
Seems like the PHP app needs a way to automatically reconnect like how in Rails database.yml
one can set reconnect: true
and the app magically works "better".
Also experienced the issues again. Just tinkering, I changed the pg4wp plugin driver file to open a persistent, always open connection to the DB: on line 90, pg_connect
to pg_pconnect
. I don't actually know if this does or will do anything, but it functions at the moment...
Should be said that pconnect
isn't suitable for heavy-load websites: http://www.manticmoo.com/articles/jeff/programming/postgresql/difference-between-pg_connect-and-pg_pconnect.php
Thanks for idea @joshuawalker — just implemented that on my attempt, so far so good.
Haven't experienced any connection issues thus far - will report back here if they come back.
Database errors again this morning. :(
An I right in assuming that this somehow has to do with Heroku spinning down the apache process when there's no active connections to the site for a while?
@catspaw Have you tried pg_pconnect
? I haven't experienced any connection issues since changing it.
My wordpress site has been running on heroku for longer than a year...
Now I have tried to migrate my heroku wordpress to a simple hosting php+postgresql and I get this error all the time "Error establishing a database connection".
Any clues or help to fix it? :)
I solved in the end... I had a typo error in my wp-config.php. If anybody interested I set it like so:
// ** Heroku Postgres settings - from Heroku Environment ** // //$db = parse_url($_ENV["DATABASE_URL"]);
// ** MySQL settings - You can get this info from your web host * // /* The name of the database for WordPress */ define('DB_NAME', "dbname");
/** MySQL database username */ define('DB_USER', "dbuser");
/** MySQL database password */ define('DB_PASSWORD', "dbuserpassword");
/** MySQL hostname */ define('DB_HOST', "localhost");
/** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');