PostgreSQL 9.3 – Cannot Run After Drop Table

postgresqlpostgresql-9.3

I've deleted database from PostgreSQL and after this I can do nothing.
Here what i receive with createuser

$ createuser -D new_user
createuser: could not connect to database postgres: FATAL:  role "postgres" does not exist

And this when try to run psql

$ psql
psql: FATAL:  role "postgres" does not exist

I've tried above with root, postgres, custom users. Still same output

Also I searched for pg_hba.conf like this
find / -name 'pg_hba.conf'
and got this

/var/lib/postgres-xc/DN2/pg_hba.conf
/var/lib/postgres-xc/DN1/pg_hba.conf
/var/lib/postgres-xc/CN/pg_hba.conf
/etc/postgres-xc/coordinator/CN/pg_hba.conf
/etc/postgres-xc/datanode/DN2/pg_hba.conf
/etc/postgres-xc/datanode/DN1/pg_hba.conf
/etc/postgresql/9.3/main/pg_hba.conf

I've changed connection method to trustfor localhost and IPv4 in /etc/postgresql/9.3/main/pg_hba.conf.

What should I do get rid of this error?

Does connection method in other files above should be edited too?

Best Answer

Main problem was that I could not run psql command under no user. Output I received was:

psql: FATAL:  role "any role" does not exist

any role means that I tried to run psql under each user on my system(root,postgresql,my_user)

After all I haven't figured out what the problem was, I decided to reinstall PostgreSQL.

And this process turned out rather hard to.

So if you have problems with deleting and reinstalling PostgreSQL, read on.

Here what I had to do.

echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

now we get error about missing postgresql-common to fix it we need to install above package lets determine its version

sudo apt-cache policy postgresql-common

and install it

sudo apt-get install postgresql-common=151.pgdg12.4+1

we can get error that postgresql-client-common not installed so we need to do the same determine it version

sudo apt-cache policy postgresql-client-common

and install

sudo apt-get install postgresql-client-common=151.pgdg12.4+1

after this we can install postgresql like this

sudo apt-get install postgresql-9.3 postgresql-contrib-9.3