How to reset postgres password - postgresql

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!

Related

pgAdmin can't connect to the local database server

I've just updated pgAdmin to version 4.23 and PostgreSQL to version 12. I've also deleted all previous databases and pgAdmin installations. So it should have been a clean install (I've also cleaned up all the remains of previous versions).
Now when I'm attempting to connect to the local database server I get this before I can even type my password:
could not connect to server: Connection refused (0x0000274D/10061)Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5433? 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 5433?
The service is running, I can use command line tool and it responds correctly but I can't use pgAdmin for some reason.
>psql -V
psql (PostgreSQL) 12.3
A duplicate of your question
PostgreSQL database service
Look through this thread as it states multiple solutions
https://stackoverflow.com/questions/24917832/how-connect-postgres-to-localhost-server-using-pgadmin-on-ubuntu
To access PostgreSQL over the network
Change listen_address localhost to * in file /etc/postgresql/{version_number}/main/postgresql.conf
# - Connection Settings -
listen_addresses = '*'          # what IP address(es) to listen on;
Changes in pg_hba.conf
Add the following line in # IPv4 local connections:
host all all 0.0.0.0/0 md5
and comment
#host all all 127.0.0.1/32 md5

Permission denied in postgres

I missed a bit with chmod and permissions.
And now got a lot of problems with access to folders.
If I start server I see in browser:
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?
command
service --status-all
tells that postgres works
[ + ] postgresq works
Next I changed next files
sudo nano /etc/postgresql/9.5/main/postgresql.conf
#listen_addresses = 'localhost'
to
listen_addresses = 'localhost, server_ip, *'
sudo nano /etc/postgresql/9.5/main/pg_hba.conf
add
host all all server_ip/24 trust
then command
psql -U postgres -h server_ip
and error
psql: could not connect to server: Connection refused
Is the server running on host "95.213.200.26" and accepting
TCP/IP connections on port 5432?
The following chain of actions leads to a slightly different error
command
which psql
answer
/usr/bin/psql
sudo su - postgres
No directory, logging in with HOME=/
psql
psql: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Wich file permissions do I have to change here?
Check that unix_socket_directories on the server is set to the same directory (/var/run/postgresql) as the default socket directory that was configured when the client was compiled (this requires a server restart).
Alternatively, you can use the --host option of psql or set the PGHOST environment variable to tell the client to look for the socket file in /tmp, where the server creates it.
It looks like client and server are from different installations, otherwise the configured default should be the same for both. Or you have a bad PGHOST environment variable set by accident.
Check listen addres syntax. Use:
listen_addresses = '*'
For the server to listen on both localhost and the server ip.
This question is really hard. I made a great mistake with permissions 777 for / folder and whole system broke. So it is really easier delete server and start new project.

Lost PostgreSQL 9.6 Password

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

PostgreSQL Connection Refused

I have installed PostgreSQL. However everytime I try to connect through PGAdmin or through psql it gives me the below 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 checked the postgresql.conf file and the line: listen_addresses = '*' isn't commented out.
Also this is how my pg_hba.conf file is set:
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
Can anyone please advise on how I can resolve this issue?
Thanks!
Use services "start -> run -> services.msc" and look for the postgresql-[vers] service.
If it is not running try to start it, if it won't start open the event-viewer (start -> run -> eventvwr) and look for error messages relating to the PostgreSQL service.
In my case it was postgres.config. The port was somehow changed to 5433 in there and I do not remember doing it myself lol. So make sure your ports are matching up in your project vs postgres.config
pg_hba.conf.txt has to be called pg_hba.conf.
Beyond this, when you have en authentication error you will get a message similar to:
psql -U nonexistent
psql: FATAL: Peer authentication failed for user "nonexistent"
The error you are getting means most likely that PostgreSQL is not started on this server.
You can start PostgreSQL with:
service postgresql start
service postgresql status
This worked for me -
In C:\Program Files\PostgreSQL\data\postgresql.conf set listen_addresses ='localhost'
Then try -
pg_ctl -D "C:\Program Files\PostgreSQL\9.5\data" start
if already try restarting using pg_ctl
It works for me.
Remember, whatever comes after -D should be the path to where you installed PostgreSQL, to the data folder, which holds the pg_hba.conf and postgresql.conf files.
pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"
Maybe you can try this.
Open cmd and insert.
"C:\Program Files\PostgreSQL\11\bin\pg_ctl.exe" runservice -N "postgresql-x64-11" -D "C:\Program Files\PostgreSQL\11\data" -w
Hit enter...

postgres server running in local host, but postico, pgadmin can't access to it

I successfully installed postgres through homebrew, and i set it run automatically by doing
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
So, right now i can access to psql from my terminal (i use iterm2 + oh my zsh)
psql (9.6.1)
Type "help" for help.
ty2kim=#
The problem is, postgres management tools like postico, pgadmin cannot access to it
for postico, error message is
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5435?
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 5435?
which is weird because from my understanding, accessing to the database from terminal and management tools are basically the same if configured correctly
My pg_hba.conf and postgresql.conf are set as default (didn't make any changes there), but i tried doing
listen_addresses = 'localhost'
=>
listen_addresses = '*'
(restart server)
still didn't work
Please help!
Port 5435 is not standard for PostgreSQL. Are you sure PG is running on it? If you didn't change it in postgresql.conf it must be 5432. Please check it.
must check pg_hba.conf. If there doesn't have much restriction, you can put to end of this file by below line:
host all all all trust
After that, reload/restart instance.
Check if your PC is using firewall. If yes, please turn off it.