Postgres: "Failed to load sql modules into the database cluster" and other errors - postgresql

I run Windows and I am trying to install postgres, but I can't get it to work. During installation, I get the error:
Failed to load sql modules into the database cluster
When I try to access the server in pgadmin or via SQL Shell, I get the error:
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?"
I have found a log in the data-folder saying:
2021-04-08 14:53:44.315 CEST [11088] LOG: starting PostgreSQL 13.2, compiled by Visual C++ build 1914, 64-bit
2021-04-08 14:53:44.321 CEST [11088] LOG: could not listen on IPv6 address "::": Permission denied
2021-04-08 14:53:44.326 CEST [11088] LOG: could not listen on IPv4 address "0.0.0.0": Permission denied
2021-04-08 14:53:44.327 CEST [11088] WARNING: could not create listen socket for "*"
2021-04-08 14:53:44.328 CEST [11088] FATAL: could not create any TCP/IP sockets
2021-04-08 14:53:44.331 CEST [11088] LOG: database system is shut down
Can someone please help me?

I had the same issue and followed different tips and tricks available on the internet but nothing worked.
I fixed that issue by following these steps:
First disable antivirus for an hour
Create a folder in either C drive or D drive and give full permission to User
Then again install a fresh application. If you have already installed then uninstall that and install from starting.
Make sure to choose that folder only at the time of installation

Related

Unable to build the PostgreSQL environment. FATAL: database "t" does not exist

I installed postgres from brew.
I got an error, I tried to delete the postmaster.id
The file seems to be missing.
rm -f data/postmaster.pid
It had no effect.
I tryed
$brew install postgres
$psql --version
psql (PostgreSQL) 14.1
$postgres --version
postgres (PostgreSQL) 14.1
$psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: database "t" does not exist
$postgres -D /usr/local/var/postgres
2022-01-28 14:27:14.406 JST [94892] LOG: starting PostgreSQL 14.1 on aarch64-apple-darwin21.1.0, compiled by Apple clang version 13.0.0 (clang-1300.0.29.3), 64-bit
2022-01-28 14:27:14.408 JST [94892] LOG: could not bind IPv6 address "::1": Address already in use
2022-01-28 14:27:14.408 JST [94892] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2022-01-28 14:27:14.408 JST [94892] LOG: could not bind IPv4 address "127.0.0.1": Address already in use
2022-01-28 14:27:14.408 JST [94892] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2022-01-28 14:27:14.408 JST [94892] WARNING: could not create listen socket for "localhost"
2022-01-28 14:27:14.408 JST [94892] FATAL: could not create any TCP/IP sockets
2022-01-28 14:27:14.409 JST [94892] LOG: database system is shut down
$rm /usr/local/var/postgres/postmaster.pid
rm: /usr/local/var/postgres/postmaster.pid: No such file or directory
$sudo lsof -i:5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 94724 t 7u IPv6 0xe42d991dab624b7 0t0 TCP localhost:postgresql (LISTEN)
postgres 94724 t 8u IPv4 0xe42d991d7856c0f 0t0 TCP localhost:postgresql (LISTEN)
I don't know why you insist in wrecking your PostgreSQL server by removing the PID file. I wish you would stop doing that.
The error message means that you are trying to connect to database t, but that database does not exist. Since you do not explicitly specify a database, the causes could be:
you are operating system user t, so the connection defaults to database t
the environment variable PGDATABASE is set to t
the environment variable PGUSER is set to t, and the connection defaults to the same database name as the user name
In any event, the solution is to pick an existing database and use
psql -d dbname

PostgreSQL errors on symfony server launch

I am learning Symfony,
I create my project with : symfony new myproject --full
directly after this I run symfony serve
in the console I am getting thoses errors :
Tailing Web Server log file (/Users/ben/.symfony/log/cd52af540b09d661e4ffb4f5029da4bbaf3586a9.log)
Tailing PHP-FPM log file (/Users/ben/.symfony/log/cd52af540b09d661e4ffb4f5029da4bbaf3586a9/53fb8ec204547646acb3461995e4da5a54cc7575.log)
[OK] Web server listening
The Web server is using PHP FPM 7.3.11
https://127.0.0.1:8000
[Web Server ] Jun 3 23:38:48 |DEBUG | PHP Reloading PHP versions
[Web Server ] Jun 3 23:38:48 |DEBUG | PHP Using PHP version 7.3.11 (from default version in $PATH)
[Application] Jun 3 21:29:59 |CRITICA| REQUES Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?" at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96
[Application] Jun 3 21:29:59 |CRITICA| REQUES Exception thrown when handling an exception (Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96)
[Application] Jun 3 21:29:59 |CRITICA| PHP Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
[Application] Jun 3 21:37:59 |ERROR | REQUES Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET https://127.0.0.1:8000/"" at /Users/ben/Desktop/symfonytuto/demo/vendor/symfony/http-kernel/EventListener/RouterListener.php line 136
[Application] Jun 3 21:38:00 |ERROR | REQUES Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET https://127.0.0.1:8000/favicon.ico" (from "https://127.0.0.1:8000/")" at /Users/ben/Desktop/symfonytuto/demo/vendor/symfony/http-kernel/EventListener/RouterListener.php line 136
[Application] Jun 3 21:38:00 |CRITICA| REQUES Exception thrown when handling an exception (Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96)
[Application] Jun 3 21:38:00 |CRITICA| PHP Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
[Application] Jun 3 21:38:00 |CRITICA| REQUES Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionException: "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?" at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96
[Application] Jun 3 21:38:00 |CRITICA| REQUES Exception thrown when handling an exception (Doctrine\DBAL\Exception\ConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96)
[Application] Jun 3 21:38:00 |CRITICA| PHP Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
[Web Server ] Jun 3 23:38:48 |INFO | PHP listening path="/usr/sbin/php-fpm" php="7.3.11" port=50170
[PHP-FPM ] Jun 3 23:38:48 |NOTICE | FPM fpm is running, pid 1240
[PHP-FPM ] Jun 3 23:38:48 |NOTICE | FPM ready to handle connections
After this the Symfony's default page is loading correctly but when I add a route to the url for example : https://127.0.0.1:8000/testtt
I'm getting this error :
An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
(it should be something like 'this route doesnt exist' no ?)
Please tell me how I can give you more info about my problem !
Thanks a lot !
This question pops up often enough that I think an answer is appropriate until the issue is resolved.
Assume you just created a new Symfony website-skeleton app, added a new controller and started the development server. You navigate to your new route and exceptions are tossed. Either get a 'driver not found' or a 'could connect to server'. Which of course is a bit unexpected since you have not yet done anything with the database.
The problem is that the Doctrine migrations bundle provides a data collector for Symfony's profiler bar that shows up at the bottom of the browser page when running in development mode. The data collector needs to connect to the database in order to collect migrations data. It does not care about the fact that there is no database. It just tries to connect and ends up tossing an exception.
I opened an issue on this. I am still not entirely sure if this is a feature or bug. Feel free to comment on the issue if you like.
This is a fairly recent problem though I have not tracked exactly when it first popped up. Hence many existing tutorials and step by step guides do not mention it. Consider it to be part of your development experience. Learning how to read exceptions is quite important.
There are several solutions. If you plan on using a database then go ahead and create yourself a database and adjust the DATABASE_URL to point to it. The database can be empty. The migration data collector just needs to be able to connect to it. On my local development machine I actually created a database called db_name just to avoid this error message.
A second solution is to just remove the migrations bundle with
composer remove doctrine/doctrine-migrations-bundle
And the problem goes away. If later on you need migrations then just use composer require to re-install it.
I have another solution that solves the problem without having to remove the package with composer remove ....
comment out Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], in /config/bundles.php
Then move /config/packages/doctrine_migrations.yaml up one directory so it's not longer trying to be included.
This may be a little less intimidating for new developers.
If the issue appears when you want to access the localhost.../lucky/number, go to .env file under the your "folder name" and uncomment this line:
DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
And the rest of them with mySQl and Postgres, comment them.
Hope it works for you. :)

pg_Ctl -data directory has wrong ownership

I am unable to start the Postgres server and whenever I use pg_ctl I am getting the following error - can some one help me to fix this. I changed the folder permissions using CHmod and tried running with Sudo -s also but still the problem exists.
one error I did was, I deleted the Postmaster.pid when the server was running- post this I am getting this issue when ever I try to start the server through pg_ctl and another error when I use the pgadmin.
Any suggestions here will be really helpful- thanks.
Using Macos Shell command :
'pg_ctl start -D /Library/PostgreSQL/12/data waiting for server to start....2020-05-05 11:40:04.838 IST [1216] FATAL: data directory "/Library/PostgreSQL/12/data" has wrong ownership 2020-05-05 11:40:04.838 IST [1216] HINT: The server must be started by the user that owns the data directory. stopped waiting pg_ctl: could not start server Examine the log output.'
Using pgadmin the error is as follows :
'could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5434? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5434?'
p.s. : I modified the hba.conf and also the postgres.conf files to allow connection from the local ip
Error received on 5May
waiting for server to start....2020-05-05 19:54:13.029 IST [7274] LOG: starting PostgreSQL 12.2 on x86_64-apple-darwin, compiled by Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn), 64-bit
2020-05-05 19:54:13.030 IST [7274] LOG: listening on IPv6 address "::", port 5433
2020-05-05 19:54:13.030 IST [7274] LOG: listening on IPv4 address "0.0.0.0", port 5433
2020-05-05 19:54:13.030 IST [7274] LOG: listening on Unix socket "/tmp/.s.PGSQL.5433"
2020-05-05 19:54:13.039 IST [7274] LOG: redirecting log output to logging collector process... 2020-05-05 19:54:13.039 IST [7274] HINT: Future log output will appear in directory "log" stopped waiting .. pg_ctl: could not start server
Examine the log output.
Log file details
2020-05-05 21:29:30.748 IST [8853] LOG: invalid authentication method "0.0.0.0/0"
2020-05-05 21:29:30.748 IST [8853] CONTEXT: line 80 of configuration file "/Library/PostgreSQL/12/data/pg_hba.conf"
2020-05-05 21:29:30.748 IST [8853] FATAL: could not load pg_hba.conf
2020-05-05 21:29:30.749 IST [8853] LOG: database system is shut down
Details of my pg_HBA conf
# "local" is for Unix domain socket connections only
local all all 0.0.0.0/0 md5
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
host all all 0.0.0.0/0 md5
host all all ::/0 md5
latest log file
bash-3.2$ cat postgresql-2020-05-05_221328.log
2020-05-05 22:13:28.794 IST [9834] LOG: database system was interrupted; last known up at 2020-05-05 22:13:09 IST
2020-05-05 22:13:28.872 IST [9834] LOG: database system was not properly shut down; automatic recovery in progress
2020-05-05 22:13:28.874 IST [9834] LOG: redo starts at 0/17742C8
2020-05-05 22:13:28.874 IST [9834] LOG: invalid record length at 0/1774300: wanted 24, got 0
2020-05-05 22:13:28.874 IST [9834] LOG: redo done at 0/17742C8
2020-05-05 22:13:28.881 IST [9832] LOG: database system is ready to accept connections
......
also I found this error while staring the server and the PID is chaning everytime..
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start....2020-05-05 22:09:21.941 IST [9746] FATAL: lock file "postmaster.pid" already exists
2020-05-05 22:09:21.941 IST [9746] HINT: Is another postmaster (PID 9735) running in data directory "/Library/PostgreSQL/12/data"?
stopped waiting
pg_ctl: could not start server
Examine the log output.
bash-3.2$ kill -9 9735
bash-3.2$ pg_ctl start -D /Library/PostgreSQL/12/data
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start....2020-05-05 22:09:35.829 IST [9758] FATAL: lock file "postmaster.pid" already exists
2020-05-05 22:09:35.829 IST [9758] HINT: Is another postmaster (PID 9747) running in data directory "/Library/PostgreSQL/12/data"?
stopped waiting
pg_ctl: could not start server
Examine the log output.
502 9833 9832 0 10:13PM ?? 0:00.00 postgres: logger
502 9835 9832 0 10:13PM ?? 0:00.00 postgres: checkpointer
502 9836 9832 0 10:13PM ?? 0:00.04 postgres: background writer
502 9837 9832 0 10:13PM ?? 0:00.01 postgres: walwriter
502 9838 9832 0 10:13PM ?? 0:00.01 postgres: autovacuum launcher
502 9839 9832 0 10:13PM ?? 0:00.01 postgres: stats collector
502 9840 9832 0 10:13PM ?? 0:00.00 postgres: logical replication launcher
0 9641 9504 0 10:03PM ttys000 0:00.02 sudo -u postgres -s /bin/bash
502 9904 9642 0 10:37PM ttys000 0:00.00 grep postgres
The data directory should be owned by the postgres user and have user-only access (700 or u+rwx)
Does this match what you have set up?
Thom Brown
Disclosure: I am an EnterpriseDB employee.
Try running this code
pg_ctl -D /usr/local/var/postgres start

Change PostgreSQL data directory to directory created by PostgresSQL on another machine

I have a database stored on an external hard drive. The database was created using PostgreSQL 11, on an Ubuntu 18.04 machine. The folder it's stored in was the data directory of my PostgreSQL instance on my Ubuntu machine, everything worked fine. I don't have access to this Ubuntu machine anymore, and this will last for a few months, but I have the external drive. I'm working under macOS 14.6 in the meantime. I setup PostgreSQL on my Mac using the Postgres.app. I created a new server, making sure to use version 11. The defaut data directory was of course not the one I want, so I changed its path in postgresql.conf to point to my existing data dir:
data_directory = 'path_to_external_HDD_data_directory'
Note that this is all I changed in the .conf file (should I change anything else?). When I try to connect to the server via Postgres.app, I get the following error:
pg_ctl: server did not start in time
And the log is:
2019-10-21 22:06:47.628 CEST [72547] LOG: listening on IPv6 address "::1", port 5432
2019-10-21 22:06:47.629 CEST [72547] LOG: listening on IPv4 address "127.0.0.1", port 5432
2019-10-21 22:06:47.654 CEST [72547] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-10-21 22:06:47.742 CEST [72548] LOG: database system was interrupted; last known up at 2019-10-21 22:00:07 CEST
2019-10-21 22:06:58.263 CEST [72548] LOG: database system was not properly shut down; automatic recovery in progress
2019-10-21 22:06:58.266 CEST [72548] LOG: redo starts at 4A/B2804E40
2019-10-21 22:06:58.266 CEST [72548] LOG: invalid record length at 4A/B2804E78: wanted 24, got 0
2019-10-21 22:06:58.266 CEST [72548] LOG: redo done at 4A/B2804E40
2019-10-21 22:06:58.314 CEST [72547] LOG: database system is ready to accept connections
Postgres.app then tells me that the port is in use. Running lsof -n -i4TCP:5432, I see that postgres is listening. I killed it and retried but got the same pg_ctl error. Any idea of what I can do?
Your server started successfully. You don't use pg_ctl to connect to PostgreSQL, but the command line client psql.
Anyway, you should stop what you are doing right now before any damage is done.
It is not supported to use a PostgreSQL data directory created with one architecture (Linux) on a different architecture (MacOS).
If the server starts, it is by coincidence. Connecting might work, but it might just as well corrupt your database.

The socket connection to localhost failed..ErrorCode: 10061

When I type localhost on my browser , I am unable to successfully connect..I am getting
The socket connection to localhost failed.
ErrorCode: 10061.
No connection could be made because the target machine actively refused it 127.0.0.1:80
How can I fix it?
You start a web server on your localhost listening on port 80. At present there isn't one.