News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

suddenly getting DB "Connection Problems"

Started by Geremia16, October 22, 2022, 11:26:40 PM

Previous topic - Next topic

Geremia16

My forum suddenly now gives the
QuoteConnection Problems
Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.
error. I didn't upgrade the database (Postgres), the webserver, or PHP. How can I debug what's going on?

repair_settings.php says:
QuoteSome settings are not being shown because the database connection information is incorrect.
Check your database login details, table prefix and that the database actually contains your SMF tables.
They do contain all these things.

I even changed my database password and updated Settings.php, to no avail.

Aleksi "Lex" Kilpinen

In both cases, that error simply means your database can't be used for one reason or another.
So that's what I would turn my attention to, is the database and database server OK and reachable?

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Doug Heffernan

Quote from: Geremia16 on October 22, 2022, 11:26:40 PMConnection Problems
Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.

If the database details are correct, the issue lies with the host. Have you contacted them? But seeing the other error quoted below, I think that the database info are not correct. Double check all the database info again to make really sure that everything is correct. Another thing to check for is the database user 's permissions to the database.

Quote from: Geremia16 on October 22, 2022, 11:26:40 PMSome settings are not being shown because the database connection information is incorrect.
Check your database login details, table prefix and that the database actually contains your SMF tables.

Geremia16

Quote from: Doug Heffernan on October 23, 2022, 08:21:05 AMIf the database details are correct, the issue lies with the host. Have you contacted them?
I am the DB host.
Quote from: Doug Heffernan on October 23, 2022, 08:21:05 AMBut seeing the other error quoted below, I think that the database info are not correct. Double check all the database info again to make really sure that everything is correct.
I'm at a loss about what changed. It was working just fine.
After I ran into the connection issues problem, I changed the database password and updated Settings.php, but I'm still getting the same issue.
Quote from: Doug Heffernan on October 23, 2022, 08:21:05 AMAnother thing to check for is the database user 's permissions to the database.
I can runsudo -u postgres psql just fine.

Geremia16

Quote from: Aleksi "Lex" Kilpinen on October 23, 2022, 01:19:26 AMSo that's what I would turn my attention to, is the database and database server OK and reachable?
Yes, the DB runs locally, and runs just fine. The issue is the connection to the database.

Geremia16

pg_hba.conf:# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
Should the method be something different? I tried scram-sha-256, too, but to no avail.

Geremia16

🆗, so there was an issue with; Enable pgsql extension module
extension=pgsql.so
of /etc/php.d/pgsql.ini not being commented out. Now,<?php
    $connection 
pg_connect ("host=localhost dbname=smf user=postgres password=<redacted>");
    if(
$connection) {
       echo 
'connected';
    } else {
        echo 
'there has been an error connecting';
    } 
?>
returns "connected", but the SMF forum still says
QuoteConnection Problems
Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.

Geremia16

I'm still getting "Connection Problems". How can I find out why?

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Geremia16

Quote from: Kindred on October 25, 2022, 07:59:38 PMTalk to your host
As I mentioned above, I am the database host, and PHP's pg_connect() function connects to it just fine. It's an SMF issue.

shawnb61

What version of SMF?
What version of PHP?
What version of pg?

Something must have changed...  You cannot think of any updates made around the time this started?
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Doug Heffernan

Quote from: Geremia16 on October 25, 2022, 11:45:50 PMIt's an SMF issue.

If the database details have been entered correctly to the Settings.php file, then it is not a Smf issue at all.

In your op you say:

Quote from: Geremia16 on October 22, 2022, 11:26:40 PMMy forum suddenly now gives the
Quote from: Geremia16 on October 22, 2022, 11:26:40 PMMy forum suddenly now gives the
QuoteConnection Problems
Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.

That never happens suddenly, just out of blue. Something must have triggered it. What was the latest change/nodification made prior to that happening.

shawnb61

Note there was a similar error for mysql users, caused by a PHP issue where it did not fully support more recent DB versions (e.g., mysql 8.0) on old (< 7.4) versions of PHP.  The fix there was to alter the user to use a more old school authentication plugin.  My initial suspicion is we are seeing something similar on the pg side.

Reference: https://www.simplemachines.org/community/index.php?topic=574573.0

But the examples we saw earlier were triggered by php/db upgrades. 

My second suspicion is PHP 8.1 - which has big problems with pg on SMF 2.0.x.


This is why knowing the SMF version, PHP version, and pg version would help. 
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

m4z

Are you seeing the errors permanently or intermittently?
Which OS and release are you using?
Did you install any updates, added IP addresses, changed anything?
If you compare Settings.php and Settings_bak.php, does everything look ok? Do you have backups (of files and the db) that you can compare to?


Quote from: Geremia16 on October 23, 2022, 06:26:21 PM
Quote from: Doug Heffernan on October 23, 2022, 08:21:05 AMAnother thing to check for is the database user 's permissions to the database.
I can run
sudo -u postgres psql just fine.

Surely your SMF uses a different user? Can you login with that user?


Quote from: Geremia16 on October 23, 2022, 06:33:39 PMpg_hba.conf:
# TYPE  DATABASE        USER            ADDRESS                METHOD

# "local" is for Unix domain socket connections only
local  all            all                                    trust
# IPv4 local connections:
host    all            all            127.0.0.1/32            trust
# IPv6 local connections:
host    all            all            ::1/128                trust
[...]
Should the method be something different? I tried scram-sha-256, too, but to no avail.

I've never tested with "trust" and don't know how it works (I guess you don't need a password on login?), might not work with SMF. Reading the docs ("anyone who can connect to the server is authorized to access the database with whatever database user name they specify (even superuser names)") I think you'd want a different method just to have more security.


Quote from: Geremia16 on October 23, 2022, 06:51:00 PM$connection = pg_connect ("host=localhost dbname=smf user=postgres password=<redacted>");

Ugh, you really are using the main postgres user. I hope at least SMF is the only software using the DB?
"Faith is what you have in things that don't exist."
--Homer Simpson

Es gibt hier im Forum ein deutsches Support-Board!

Geremia16


Geremia16

Quote from: m4z on October 26, 2022, 02:22:47 PMyou really are using the main postgres user. I hope at least SMF is the only software using the DB?
Yes.

shawnb61

So the connection is erroring out for some reason. 

Note that SMF won't display internal DB errors to an end user (just the generic 'connection issues') error.  So, I think there are two ways to get it to give us the error:

(1) Create a new DB and perform a new install of 2.1.2.  Since SMF knows the admins are doing installs, it will display detailed error info.

(2)  Echo the error being produced.  Early in Subs-Db-postgresql.php, ~line 97 or so, you will see $pg_connect_error and $pg_connect_errno getting populated.  Display those.


I don't yet have a pg15 install.  In my pg14 install, all the methods are scram-sha-256.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Geremia16

Quote from: shawnb61 on October 27, 2022, 12:16:06 AM(1) Create a new DB and perform a new install of 2.1.2.  Since SMF knows the admins are doing installs, it will display detailed error info.
"install.php?step=2" is a blank page. I get lots of errors in error_log:

[Thu Oct 27 17:16:48.006075 2022] [php7:notice] [pid 21416:tid 140032570541760] [client ::1:48266] PHP Notice:  Trying to access array offset on value of type null in /var/www/htdocs/smf/install.php on line 386, referer: https://<redacted>/smf/install.php?step=0
[Thu Oct 27 17:16:48.006165 2022] [php7:notice] [pid 21416:tid 140032570541760] [client ::1:48266] PHP Notice:  Undefined index:  in /var/www/htdocs/smf/install.php on line 818, referer: https://<redacted>/smf/install.php?step=0
[Thu Oct 27 17:16:48.006178 2022] [php7:notice] [pid 21416:tid 140032570541760] [client ::1:48266] PHP Notice:  Trying to access array offset on value of type null in /var/www/htdocs/smf/install.php on line 818, referer: https://<redacted>/smf/install.php?step=0
[Thu Oct 27 17:16:48.006208 2022] [php7:error] [pid 21416:tid 140032570541760] [client ::1:48266] PHP Fatal error:  Uncaught Error: Function name must be a string in /var/www/htdocs/smf/install.php:818\nStack trace:\n#0 /var/www/htdocs/smf/install.php(164): DatabaseSettings()\n#1 {main}\n  thrown in /var/www/htdocs/smf/install.php on line 818, referer: https://<redacted>/smf/install.php?step=0

Quote from: shawnb61 on October 27, 2022, 12:16:06 AM(2)  Echo the error being produced.  Early in Subs-Db-postgresql.php, ~line 97 or so, you will see $pg_connect_error and $pg_connect_errno getting populated.  Display those.

shawnb61

Wow, those errors are all over the place.  Feels more like an OS level issue.

This looks like you are missing all or part of critical files, e.g., Settings.php...  Line 386 is trying to access your default language (from settings.php) and line 818 is accessing your db type (from settings.php). 

I would start by re-copying all files from the install .zip, and triple checking file permissions throughout your file system. 

I would confirm all files in the install .zip are in your file system.  Count them.  And that they are writeable.

And trying the install again.

Also, if you have mod security enabled, disable it...
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

shawnb61

I would also view settings.php.  Make sure it looks good.
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: