Sunday, December 2, 2018

Export Postgres Database In Ubuntu.

As a Postgres beginner, I was confused when I went export Postgres database in Ubuntu. Because If you installed Postgres as https://passioned91.blogspot.com/2018/12/beginners-guide-to-install-postgres.html You didn’t set a password for user postgres because it not a real Ubuntu user.


First of all, let’s check basic of how to Export Postgres database in Ubuntu. There is a standalone application call pg_dump. And also this, not a psql command, this should run is bash. To use this we have to use authentication for a postgres user.
I usually use
sudo -u postgres psql
to log into psql, so I don’t have to give a password for postgres user. So How can I give authentication to pg_dump. 
First of all, you have to change user into postgres without password?
sudo -i -u postgres

Now you can see your username is changed is bash.
let’s say you have database name school, so you command should be like below
pg_dump -U postgres school school.sql;
Now is the tricky part 😀 Where is the school.sql file? Why don’t we ask it from bash?
type pwd in the terminal, then you will see something like this
/var/lib/postgresql 
Go there and you will see you SQL dump 😀
Happy coding guys.

No comments:

Post a Comment