Where do i see postgres username and password - macos

I have installed Postgres with Homebrew, and it didn't ask me to setup any username and password. Now I am having troubles connect the ruby project with db. I don't know what username and password to use in config file.
I checked my pg_hba.conf file, all methods are set to trust, and user is mostly set to all or my profile name.
When I start Rails, the server starts and then gives PG::ConnectionBad error.
I am new to Ruby and all this and would appreciate some help.

I am not sure if you checked any docs before posting, default user is postgres, but check if postgres service is running ps aux | grep postgres and follow this doc to perform all required setup. First steps are also worth your attention.

Related

postgres throws the error psql: FATAL: role "username" does not exist

Please, I need help with my postgres server. I have problems starting the server. I was using the app here a few months ago and everything was fine. Today I spent hours trying to start it yet couldn't. I then realised I had another instance of PostgreSQL installed. I uninstalled version 9.6 blocking my app.
Now after trying again, the PostgreSQL app throws the error when I use psql:
FATAL: role "username" does not exist
I didn't set the role or user but it somehow took my username and is throwing does not exist. Please, how do I start my server. I have seen someone with a similar issue here but unlike in his case, I didn't even get to start the server. not to speak of deleting the database. Please, how do I address this? Any help would be appreciated.
I also noticed he was able to execute
which psql
which returned his supposed psql path. It does not return anything in my case. Not sure how the configuration works, this is my second time using this database and it failed right away.
Thank you for your time, as answered in one of the SO question here. Running
sudo -u postgres -i
did give me access to postgres, but if you are using the postgres app like myself here . Running psql commands would not work for you as postgres is not installed globally on your machine. But running
'/Applications/Postgres.app/Contents/Versions/9.5/bin'/psql -p5432
which is the exact command the postgres app execute when you attempt to start the service works great and start the service for me. You can then proceed and add the role and database your postgres app looks for by default. So in summary. Below is what worked for me.
$sudo -u postgres -i
$'/Applications/Postgres.app/Contents/Versions/9.*/bin'/psql -p5432
#CREATE USER postgres SUPERUSER;
#CREATE DATABASE postgres WITH OWNER postgres;

What is the default password for Postgres

I have just install Postgres 9.3 on Windows 7. The installation completed successfully. It has never asked me to provide the password for postgres user.
The service postgresql-x64-9.3 is up and running. However, I cannot connect: I do not not know the password. I've found the following answer, but it did not help:
similar question on Ubuntu
[LINUX]
might work for windows too
After installing postgres follow following steps in order to setup password for default system account of Linux execute following in terminal:
user:~$ sudo -i -u postgres
postgres#user:~$ psql
after executing above two commands you will get into postgres shell
Execute this query in postgres shell:
postgres=# ALTER USER postgres PASSWORD 'mynewpassword';
your new password is 'mynewpassword' without quotes and now you can connect with external GUI tools like DBeaver
WARNING: trust means exactly that. Anyone who can connect to the PostgreSQL server can control it. If you set trust mode that allows superusers like user postgres (or all users) to connect, they get total control of your PostgreSQL and can probably run shell commands too. You should usually only use it to change the password then restore the configuration back to the auth mode you were using before.
If you used an unattended installer script, the password will be in the script or associated config file.
Otherwise, treat it the same as if you lost/forgot the password rather than never knowing it:
Edit pg_hba.conf, setting the auth mode to trust instead of the default md5
In the Services control panel restart the PostgreSQL service
Connect with psql or PgAdmin or whatever
ALTER USER postgres PASSWORD 'mynewpassword';
Edit pg_hba.conf again and set the auth mode back to md5
Restart PostgreSQL again
pg_hba.conf is in your data directory. By default it'll be %PROGRAMFILES%\PostgreSQL\9.3\data.
To edit it you'll have to use the security tab to give yourself read/write permissions (via a UAC prompt). This might require you to set yourself as the owner of the file.
On unix systems it's more secure to prepend a
local all all peer
line to pg_hba.conf and then sudo -u postgres psql (assuming your PostgreSQL server runs as user postgres) to get an interactive psql session without using a password. That way you don't have to use trust.
On initialisation you can access the DB as:
Username: postgres
Password: postgres
By default user postgres does not have a password
Start psql and create a password:
sudo -u postgres psql
\password postgres - It will ask you enter a password for user postgres
Through trial and error I found that the password for Postgre SQL 10 for the username postgres is "admin". I kept typing in different password until I reached that password. I am using pgAdmin 4 to test out my SQL Statements, POSTGRE SQL 10 is the first server connection set up using localhost.
It seems there was no default password, but psql wouldn't accept a lack of a password (fe_sendauth: no password supplied). To get around this, I opened pgAdmin, then in the left sidebar:
Servers
Login/Group Roles
Right click postgres and click Properties,
Go to Definition tab
Set the password in the Password field
After saving, psql accepted that password. There may have been a switch I could have supplied to have it accept a lack of a password (--no-password?), but the user should probably have a password anyways, so this seemed reasonable.
go to control >> computer management >> Locaol users and group >> users >>
right click on openpgsvc >> set password.
after that now you can access with this password on openpgsvc
The simplest solution I've found is just to install PgAdmin and connect to the local server with the current Windows credentials (username + password). Then you can change the password to the postgres user.
step1: Go to control panel
Step2: Click on Administrative Tools
Step3: Click on Computer Management
Step4: There under "Local Users and Groups" Double click on user
Step:5: then right click on postgres and you can set password
refer this below image

Locked out of postgresql

createdb foo gives an invalid password for user (my username)
I can't login with
sudo psql
How do I reset my postgres user accounts?
Is it something I can do in the hba_conf file?
EDIT:
I was beginning a Postgres tutorial and wanted to have a fresh install. I ran
brew update
brew uninstall postgresql
brew install postgresql
pg_ctl -D some/path
createdb
This could be two things: you lost/misset the password, or Postgres might be configured in a way that prevents you from logging in.
Resetting the password:
Most of the time Postgres runs as user "postgres". Try su - postgres as root, and then run psql. If that doesn't work, you'll need to figure out what user postgres is running as, and su to that user. From there you can reset the password for the user. Also, make sure that your user is allowed to log in -- the default is to disable login for a new role .
Changing the configuration:
Find the pg_hba.conf file and edit it to permit password login. This file is usually loacted in /var/lib somewhere. On my Scientific Linux server its at: /var/lib/pgsql/9.2/data/pg_hba.conf, but on my Gentoo server its at /etc/postgresql-9.3/pg_hba.conf -- so locate pg_hba.conf might help you find it. This file is usually fairly well commented, and there is a manual page for it here: http://www.postgresql.org/docs/devel/static/auth-pg-hba-conf.html.

PostgreSQL under Lion: What's the password?

I got my new lion machine. Ran the PostgreSQL installer from the PostgreSQL site for Mac and i have no multiple apps installed. One of them is "pgAdmin III.app". When I open it there is already one server connection available. localhost:5432
Whenever I try to connect to the server with a doubleclick the programm asks me for a password. I have no idea what to enter. It's not my admin password, it's not "postgres", it's not "localhost", it's not empty.
I just can't seem to connect to the server. Even when I check the properties of the localhost server the password field seems empty. However I'm not allowed to leave the password field empty.
Any idea what to do? I really need to setup postgres?
On my Mac OSX Lion, PostgreSQL configuration files are stored under /Library/PostgreSQL/9.0/data/
Haven't tried it on OSX, but on Ubuntu you can login as the system user 'postgres' to the default database 'postgres' without a password with
su postgres -c psql
You can then (re)set the password of the database superuser 'postgres'.
You can also edit the configuration file pg_hba.conf (don't know where it is located on a default OSX installation, on Ubuntu it is /etc/postgresql/8.4/main/pg_hba.conf) and grant access to the default database without authentication
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host postgres postgres 127.0.0.1/32 trust
After editing pg_hba.conf you must reload the configuration with
pg_ctlcluster 8.4 main reload
You can then connect with pgAdmin and (re)set the password, but don't forget to change the authentication method back to md5 again...
here's a better answer (works in OSX HighSierra): the account used is the one you're logged onto OSX with, therefore, the password is your password!
A similar question has been asked a short time ago. The steps described there should be appropriate for Lion also.
Postgresql: password authentication failed for user "postgres"

Forgotten password for Postgresql - Resetting password - Mac OS X Leopard

I used blog entry by Robby on Rails site:
http://www.robbyonrails.com/articles/2008/01/22/installing-ruby-on-rails-and-postgresql-on-os-x-third-edition
Got to the end, but when I tried accessing the pg database I was denied.
I've tried to change pg_hba.config file to trust so that I can gain access anyway (without a password), but proved fruitless.
Please help. Thanks in advance.
Restart postgresql after you alter the pg_hba.config file to make sure your changes are read. Next, type
psql -U myUser template1
in a terminal, where myUseris the name of the user running the postgres proces. That should make you log in as administrator. Next, in the psql session, write
ALTER USER realUser PASSWORD 'myNewPassword';
in order to reset the password. Here realUseris the user of the database you are trying to connect to.

Resources