postgreSQL password authentication failed for user - windows-10

I'm taking a full WebDev course and got really hard stuck on this matter. I've installed postgreSQL 14.2 for Windows 10 and the instructor said that pgAdmin4 would come together, which it didn't, so then i installed pgAdmin4 individually. I've setted everything up and created a testing database, which is called 'test', and also a table, everything through Windows Powershell command lines, following the course instructions. Now, when i try to access this database through PowerShell command psql 'test' and type the requested password for the OS user i get a Fatal Error, which follows:
PS C:\Users\theu_\desktop> psql 'test'
Password for user theu_:
psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "theu_"
I've tried my OS username password and the postgreSQL password, none of them works. What am i missing or did wrong?
Thanks in advance

Try accessing postgres by using psql -U postgres in cmd, postgres being the name of the superuser for postgres itself (if you did a basic install) - while windows is probably trying to access postgres with your windows name.
You should also be able to use SQL Shell to access your database without denoting a user.

Related

Why can I login to my database using my .pgpass credentials, but not use pg_dump?

After updating my computer I am unable to do automatic backups of my PostgreSQL 12 database, which has the version:
psql (PostgreSQL) 12.8 (Ubuntu 12.8-Ubuntu0.20.04.1)
Before updating, I was able to run the following code, both manually and using crontab:
pg_dump -h localhost -p 5432 -U brian -d example_db > '/home/brian/.../example_db.bak'
The error I now get is:
pg_dump: error: connection to database "example_db" failed: FATAL: password authentication failed for user "brian"
password retrieved from file "/home/brian/.pgpass"
FATAL: password authentication failed for user "brian"
password retrieved from file "/home/brian/.pgpass"
I have confirmed that my ".pgpass"-file lives up to the manual described here:
PostgreSQL 12 Manual: pgpass
I am also able to log in to my database without being prompted for a password:
brian#pc:~$ psql -U brian -d example_db
Would anyone have an idea why I am unable to use pg_dump when I am able to login to my database without being prompted for my password?

Accidentally removed super user privilege from user: postgres on postgres 10. How to get it back without re installing?

I accidentally removed the super user privilege from user: postgres. I don't know how to get another super user. I stopped the postgres service and tried logging in with single-user mode:
/usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data
I get this error:
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
In Linux, how can I start Postgres in single-user mode so I can fix the super user privilege?
Edit: I used this link for reference, but I'm getting the error mentioned above.
Accidently removed postgres default superuser privileges - can I get it back?
I combined solutions from these three links:
Accidently removed postgres default superuser privileges - can I get it back?
Restoring the superuser account on the postgres server
“root” execution of the PostgreSQL server is not permitted
After stopping the postgresql service, I ran this command:
sudo -u postgres /usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data
/usr/pgsql-10/bin/postgres is the location of my postgres binary
/var/lib/pgsql/10/data is the location of my postgresql conf
This allowed me to access single user mode, where I just typed this command:
ALTER USER postgres SUPERUSER;
So if anyone is experiencing the same scenario as me, please give the posted command a try.
just adding this for postgresql 12 (Ubuntu) and possibly up
sudo -su postgres /usr/lib/postgresql/12/bin/postgres --single -D /etc/postgresql/12/main

Failed to connect to mLab by mongo

I tried to connect to mLab on my terminal when I followed the instruction on the website
This is the command that I typed
mongo ds151461.mlab.com:51461/simplelogin -u <dbuser> -p <dbpassword>
This is the result I got:
MongoDB shell version v3.4.4
connecting to: mongodb://ds151461.mlab.com:51461/simplelogin
MongoDB server version: 3.2.13
WARNING: shell and server versions do not match
2017-06-12T19:12:35.498-0400 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1459:20
#(auth):6:1
#(auth):1:2
exception: login failed
Btw, when I run the local mongoDB, I use mongod to make it work and mongo does not work
As the error suggests you have an authentication error.
Which is possibly happening because you are using credentials of a user that is not valid for the database "simplelogin".
(You can't use mlab credentials here, I made this mistake, might help someone, so worth a mention.)
If you don't have a user in the database yet. Follow following steps to create a user.
1 - Go to your database page, by clicking on the database from the landing page.
Or use following url, https://mlab.com/databases/simplelogin (you have to be logged in for this to work)
2 - From there click the "Users" tab. Click on the button that says "Add database user", and enter username and password (lets say username - "myuser" and password - "mypassword" for this illustration). Click the "Create" button.
3 - Use those credentials to connect to your database.
mongo ds151461.mlab.com:51461/simplelogin -u myuser -p mypassword
And it should work.
Does this help?

Login as postgres user in mac

I have a new installation of postgres in my mac using brew install.
I am trying to login to postgres user using sudo -su postgres
I get the error postgres does not know where to find the server configuration file. You must specify the --config-file or -D invocation option or set the PGDATA environment variable in mac
Can anyone please assist to point out where the error is originating from?
I want to log in as postgres and then create a new role,then create a database with owner 'newrole'.
Regards

Installing Postgresql and PgAdmin3 on Linux

I use Postgesql and PgAdmin on Windows without any problems but am struggling to get it working on Linux (I'm a Linux N00b). I have installed the 64bit version on my Fedora box following these instructions (except substituting version 9.3 for 9.2). Everything works well until I get to launching pgsql with:
sudo -u postgres psql template1
Here I get an error "Permission denied" as is attempts to change to my home directory.
I can change the password for 'postgres' as per the instructions and I presume this is just so I can use 'md5' rather than 'trust' in pg_hba.conf (if not, then I don't understand why I need this step).
When I fire up PgAdmin3, initially I have no connections. Attempting to connect to the server gives me an authentication error for user 'postgres'. I have tried resetting pg_hba.conf to 'trust' but that doesn't work either.
I would appreciate an explanation of the 'postgres' user in Linux as it appears to be a separate actual user on the Linux system (unlike Windows where it is just a 'disembodied' user relevant only to Postgress). Secondly, help in getting PgAdmin speaking to Postgresql would be gratefully received.
psql -U postgres template1
It will prompt for password if you set md5 in pg_hba.conf
After much digging about I found that most of the documentation is incomplete. I needed a combination of connecting via Cefull Lo's solution (+1) and NOT (as in most of the documentation):
sudo -U postgres psql
Then to change the password I need a more explicit SQL command as follows
template1=# ALTER USER postgres with encrypted password ‘yourpassword’;
I presume that I need to explicitly state 'with encrypted password' because I am using md5, though again, 90% of the documentation fails to point this out and advises a basic change of password together with md5. Maybe this is specific to Fedora, who knows, but now I can connect via PgAdmin3.

Resources