Login to PostgreSQL - Login failed Login to PostgreSQL - Login failed postgresql postgresql

Login to PostgreSQL - Login failed


There is no default username and password without you creating one. The simplest possible setup is to follow these steps to set up your own user as a superuser.

At a terminal prompt, create a postgres user with your own username

sudo -u postgres createuser --superuser $USER

Start the postgresql command prompt as your username but running as root since you didn't set a password yet;

sudo -u postgres psql

At the postgresql prompt, set your password;

\password $USER

After that, you should be able to log on just fine.

The setup is more thoroughly documented here.

EDIT:

If you get stuck not being able to authenticate automatically as the postgres user, you may want to compare your /etc/postgresql/9.1/main/pg_hba.conf (ie authentication config file) with the following lines from mine that works; you can get the uncommented ones using

grep -v ^# pg_hba.conf

The "local" lines should be the essential ones in this case since you can't authenticate even from the same machine;

local   all             postgres                                peerlocal   all             all                                     peerhost    all             all             127.0.0.1/32            md5host    all             all             ::1/128                 md5


During the installation process you've probably missed steps:

Now we need to reset the password for the ‘postgres’ admin account for the server, so we can use this for all of the system administration tasks. Type the following at the command-line (substitute in the password you want to use for your administrator account):

sudo su postgres -c psql template1template1=# ALTER USER postgres WITH PASSWORD 'password';template1=# \q

That alters the password for within the database, now we need to do the same for the unix user ‘postgres’:

sudo passwd -d postgressudo su postgres -c passwd

Now enter the same password that you used previously.

http://hocuspokus.net/2008/05/install-postgresql-on-ubuntu-804/


There is a good article by digital ocean here.

Key point:Without creating another user,access postgres as the default account named 'postgres'

$ sudo -u postgres psql

One can always exit using \q