Skip to main content

How to login into postgres without root password?

I am not a postgres guy I hardly know anything about it but when the duty calls you have to do anything to get it working.

So today duty called :) where I need to take the dump of a postgres database and import it on another machine now the biggest challenge was logging into the postgres and run the command when you don't know the root user password and the sad thing was I installed that postgres long back but didn't kept the password.

Now I have to first find the password (which was not possible) or find a way to access it somehow.

Luckily I found one solution to my problem :) . According to the article we can allow any user to do operation without any password, okayyy this was interesting. I tried them and bingo it worked :)

So I would like to share those steps here so that it will help some needful like me.

Step 1. Stop the postgres.

> service postgres stop

Step 2. Reset the authentication mechanism (assuming defaults are already being used)

Yes that's possible :) a very simple trick can do this, all you have to do is go to

'/usr/lib/pgsql/data/' location and edit the pg_hba.conf file.

So, exactly what to do, just follow below steps :

> vi /usr/lib/pgsql/data/pg_hba.conf

> 'press insert key on keyboard'

> search for something like
    local       all      all     ident

> change this to

    local       all      postgres     trust

> press 'Esc' key on keyboard and type ':wq'
   which is nothing but telling the editor to write and quite


Step 3. Start postgres service

 service postgres start

Step 4. Now try to login into the postgres again

> su - postgres

and yupieeee it's done

now you can reset your root password and and undo the changes that we did for authentication mechanism.
and now you have a user with password.

Tell me if this helped :)


So now I faced few problems with postgreSQL I decided to complete the beginners guide to it.
For now I am referring to PostgreSQL : Up and Running book you can get it too from any online stores. You can get some good deals on ebay, amazon or flipkart like sites.











Comments

Popular posts from this blog

Create Table in Liquibase

For creating table using liquibase you can use below code and add it in your liquibase file. <createTable tableName=“employee”>      <column name="id" type="int">      <constraints primaryKey="true" nullable="false"/>   </column>      <column name="first_name" type="varchar(255)"/>   <column name="last_name" type="varchar(255)"/>   <column name="username" type="varchar(255)">      <constraints unique="true" nullable="false"/>   </column> </createTable> The use is pretty simple it's the way it looks : Tag: <createTable></createTable> This is an opening/ending tag for creating a table. These tags will enclose column sub tags which will define columns for the table. Attribute:   tableName : Name of the table which you want to create. (This is a mandatory   ...

How databasechangeloglock and databasechangelog table used by liquibase?

Liquibase takes care of executing the query on the database while maintaining the list of queries executed and also maintaining the locks over the tables simultaneously. The two tables that are used by the liquibase for this purpose are : Databasechangeloglock : This table have following columns ID | LOCKED| LOCKGRANTED | LOCKEDBY. This maintains the locks information granted to the user. The primary purpose of this table is to make sure that two machines don't attempt to modify the data at the same time. Databasechangelog : This table have following columns ID | AUTHOR | FILENAME | DATEEXECUTED | ORDEREXECUTED | EXECTYPE | MD5SUM | DESCRIPTION | COMMENTS | TAG | LIQUIBASE This table maintains the list of the statements that are executed on the database.

Carnivorous Island from "Life of PI"

Yann Martel described about an floating carnivorous Island for symbolizing that something seemingly good in life can turn out to be harmful, so we should keep going with our journey of life... About the carnivorous Island from movie. In the movie 'Life of PI' after PI struggles to live in the pacific with the Bengal tiger suddenly one morning Pi  found himself at a Island. After spending so many days in the middle of the sea he found himself very lucky to find a Island. After spending some time he thought might be this was the end of his suffering and he can spend rest of his life at that island. He makes h is bed on a tree and sleeps there, in the middle of the night he wakes up and find that there were dead fish in the fresh water where he took swim in the day time. While trying to understand the mystery he plucks a fruit from the same tree and peel it off and finds a human tooth inside that fruit and then he realize that it was an carnivorous Island. The...