Lost PostgreSQL 9.6 Password - postgresql

I have lost my password for PostgreSQL. I have already tried googling around a bit, however the
local all all trust
solution didn't work for me. Does anyone know how to recover / reset this password in another way? Thanks!
EDIT
Here is the error I received:
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 did try out the solution posted here I forgot the password I entered during postgres installation

I assume you are referring yourself to the procedure described here:
http://www.postgresqltutorial.com/postgresql-reset-password/
Actually the described procedure is a bit wrong, as you should not add the line "local all all trust" after the comment lines, but rather modify all the methods from "md5" to "trust". Doing so I could connect to the server without indicating a password and then I could reset the password.
On windows I had to change the lines "host all all 127.0.0.1/32 md5" to "host all all 127.0.0.1/32 trust".
Hope that helps

Related

Cannot connect postgreSQL server to pgAdmin 4

I know there are a lot of similar questions on this site, but so far I've been unable to find any answers. I have a postgres 13 server running on a WSL distro, ubuntu 20.04. I am trying to connect a gui to the server. I've tried Postbird and pgAdmin 4, both give me a similar error:
'Unable to connect to server:
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?'
Steps I have tried:
I can connect to the server inside of ubuntu by running psql.
I have changed the postgresql.conf file to include listen_addresses = '*'
I have modified the pg_hba.conf file to look like:
pg_hba.conf
I have confirmed that the server is indeed running on port 5432.
Thanks for reading. Any advice would be greatly appreciated.
Ok! So my issue was indeed the pg_hba.conf file. I had to add a line at the bottom
host all all 0.0.0.0/0 trust
Once I did that, I restarted my server and was able to connect.

Postgres pg_hba.conf localhost confusion

I've run into a scenario where an application couldn't see the database. My pg_hba.conf file had the following:
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
Security aside, the application was telling me it couldn't see the database at all, while other clients could see it:
PG::ConnectionBad: 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?
(Sequel::DatabaseConnectionError)
I had to point my application to the public IP of that box, and add that in my pg_hba.conf for it to work. Also, it was confused with localhost, as it apparently looked at the IP6 route then the IP4 route, both throwing an error:
Could not spawn process for application /var/www/pints: The application encountered the following error: PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
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 5432?
(Sequel::DatabaseConnectionError)
Question: What is the best way to force this into using the IP4 route, and to best use IP4 resources to handle communications while on the same box? localhost was blind, as was 127.0.0.1, so I'm confused. Cheers

How to connect pgadmin 4 to an external server?

I just created a server (droplets) in digital ocean, install postgresql, up there well, it works on the console. My problem is when I try to connect through pgadmin.
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "165.22.184.123" and accepting
TCP/IP connections on port 5432?
Look for information and modify the file
/etc/postgresql/10/main/postgresql.conf
where says listen_addresses='localhost' by listen_addresses='*'.
Also add a line to host all all 0.0.0.0/0 md5 to the file /etc/postgresql/10/main/pg_hba.conf and I still have the same problem. Do I have to do some additional configuration?

How to reset postgres password

I am on Windows 10 using WAMP, I added PostgreSQL and PhpPgAdmin, everything was working fine. Today I can not log in to PostgreSQL through PhpPgAdmin or a php_pdo web app.
I tried editing pg_hba.conf in 2 locations c:\PostgreSQL\pg96\init\ and c:\PostgreSQL\data\pg96\ and changed the 'method' to trust as per many answers here, none of the CLI answers worked either.
I also restarted "WAMP" and even the whole computer, but no luck.
The default password worked before postgres and root but not now.
How do I reset the postgre password?
UPDATE
runing psql -U postgres returns;
psql: 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?
contents of pg_hba.conf
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# IPv4 local & remote connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 trust
so after a lot more diging, it was not that the password was wrong, but for whatever reason PostgreSQL was not even running. Windows is such a PITA!
in the end, running pg_ctl -D "C:\PostgreSQL\data\pg96" start from CMD got it going. Now we will see if it starts tomorrow.... I miss my Unix Environment.
----- UPDATE -----
While the above code works, it is moving in the wrong direction.
goto Control Panel->Administrative Tools->Services and find 'PostgreSQL ...' in the list. Right click and open Properties.
My Startup type: was set to 'Automatic' but it was not starting, I set it to 'Automatic (Delayed Start)' and now it is working, automagically!

Can't connect to the default server of pgAdmin 4

I have just installed the pgAdmin-4, and trying to connect to the default server installed with it (PostgreSQL 9.5). It asks for the password (Which I assume by default it's "postgres"), however, I keep receiving the following message:
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 am working on Windows 7.
Any ideas on how to fix this problem?
The first thing is to remove pgadmin from the problem. Try to connect with the command line using psql - if you get the same message you know that the problem is not with pgadmin. If the problem continues with psql then probably your configuration of postgresql is not complete. The issue might be in the file pg_hba.conf - this file controls who is allowed to connect to the backend. You might also check that the server application is running, using an appropriate Windows utility.