Skip to main content

Posts

Showing posts with the label psql

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) ...

How to check if the postgres server is running?

Change your directory to /etc/init.d you can do that by running below command: > cd /etc/init.d then run below command for checking postgresql service > ls                         Note:  this command will list the objects in the init.d directory and this is not specific to postgres. check if the postgresql is present in the result returned by ls cmd. If it's not present then your postgres is not installed properly and try installing again. If the postgresql is present then run below cmd : > postgresql status this will ask you for postgres possword enter the password. this will return something like this : pg_ctl: server is running (PID: 6171) /usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data" [ Note : The status above indicates the server is up and running] If the server is not returning then it will be like : pg_ctl: no server running

How to login into Postgres using terminal in Linux

The default location of postgres in linux is : /opt/PostgreSQL/8.4/ You can go to this location by typing the below command > cd /opt/PostgreSQL/8.4/ change to bin directory > cd bin/ Now for logging into the postgres run following command : > /opt/PostgreSQL/8.4/bin/psql -U postgres where 'postgres' is the username that was asked to you while installing the postgres.After this command it will ask you for password. Then enter the password and you are logged in.