129

I installed Postgres with this command

sudo apt-get install postgresql postgresql-client postgresql-contrib libpq-dev

Using psql --version on terminal I get psql (PostgreSQL) 9.3.4

then I installed pgadmin with

sudo apt-get install pgadmin3

Later I opened the UI and create the server with this information

enter image description here

but this error appear

enter image description here

how can I fix it?

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
  • download postgresql of v9.3 from this link [https://www.enterprisedb.com/downloads/postgres-postgresql-downloads#windows](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads#windows) and again run pgadmin III you will get local host already install need not to connect. – Dhavalkumar Prajapati Aug 18 '17 at 08:57

6 Answers6

223

Modify password for role postgres:

sudo -u postgres psql postgres

alter user postgres with password 'postgres';

Now connect to pgadmin using username postgres and password postgres

Now you can create roles & databases using pgAdmin

How to change PostgreSQL user password?

Community
  • 1
  • 1
WiredIn
  • 4,157
  • 4
  • 27
  • 23
35

You haven't created a user db. If its just a fresh install, the default user is postgres and the password should be blank. After you access it, you can create the users you need.

Eric Workman
  • 1,425
  • 12
  • 13
29

It helps me:


1. Open the file pg_hba.conf

sudo nano /etc/postgresql/9.x/main/pg_hba.conf

and change this line:

Database administrative login by Unix domain socket
local   all             postgres                                md5

to

Database administrative login by Unix domain socket
local   all             postgres                                trust
  1. Restart the server

    sudo service postgresql restart

  2. Login into psql and set password

    psql -U postgres

ALTER USER postgres with password 'new password';

  1. Again open the file pg_hba.conf and change this line:
Database administrative login by Unix domain socket
    local   all             postgres                                trust

to

    Database administrative login by Unix domain socket
    local   all             postgres                                md5
  1. Restart the server

    sudo service postgresql restart


It works.

enter image description here


Helpful links
1: PostgreSQL (from ubuntu.com)
Cerin
  • 60,957
  • 96
  • 316
  • 522
Kas Elvirov
  • 7,394
  • 4
  • 40
  • 62
  • This solved my problem, but can you explain why changing the db admin login to trust prior to setting the postgres password is needed in some instances? – HostMyBus Oct 01 '18 at 20:12
  • @HostMyBus Hi man, actually I don't recall at all this case. Try to dig some answers from the web (i think there is a good explanation about that) – Kas Elvirov Oct 02 '18 at 05:26
  • @HostMyBus this is a security feature. If it is set to trust, any user on the machine can login to the database. – Simon Zyx Feb 28 '19 at 14:43
  • And you actually don't need it: Just use WiredIn answer – Simon Zyx Feb 28 '19 at 14:45
4

Create a user first. You must do this as user postgres. Because the postgres system account has no password assigned, you can either set a password first, or you go like this:

sudo /bin/bash
# you should be root now  
su postgres
# you are postgres now
createuser --interactive

and the programm will prompt you.

Str.
  • 1,389
  • 9
  • 14
  • `sudo -u postgres -i` will lead to password question. There is no password on my system you can enter. My proposal works always (hm, hopefully). – Str. Jul 24 '14 at 19:35
  • `sudo -u postgress -i` doesn't lead to password question (at least on my Ubuntu after default installation). Either the `createuser --interactive` doesn't lead to the password prompt... :( – Ondřej Doněk Nov 28 '14 at 06:06
  • @OndřejDoněk my proposal was sudo /bin/bash first, did you do that? – Str. Nov 29 '14 at 09:20
  • what should you type in for role? – ahnbizcad Jan 31 '15 at 02:12
  • $ `createuser --interactive` Enter name of role to add: `postgres` Shall the new role be a superuser? (y/n) `y` – Elise Chant Jun 10 '17 at 20:27
3

First you should change the password using terminal. (username is postgres)

postgres=# \password postgres

Then you will be prompted to enter the password and confirm it.

Now you will be able to connect using pgadmin with the new password.

Pubudu
  • 93
  • 3
0

if you open the psql console in a terminal window, by typing

$ psql

you're super user username will be shown before the =#, for example:

elisechant=#$

That will be the user name you should use for localhost.

Elise Chant
  • 5,048
  • 3
  • 29
  • 36