How to Setup Postgresql in Ubuntu and Perform Dump/restore

This write up will try to explain how to install postgresql and attempt to perform database dump and restore. Which should be a basic functionality but is not present in pgadmin.

 1.) Install postgresql (execute in terminal):
sudo apt-get install postgresql postgresql-contrib

2.) Setup postgres user:
sudo -u postgres psql
alter user postgres password 'postgres'
//close the terminal after.

3.) To check install pgadmin via "Ubuntu Update Center", and try to login using postgres/postgres account.
4.) Perform dump/restore. But before performing the ff commands, you should login as postgres first:
sudo su postgres

+Create the dumps:
//dump the roles
pg_dumpall -g -U postgres > roles.sql

+Dump the schema
pg_dump -Fp -s -v -f schema.sql -U postgres databaseName

+Dump the data
pg_dump -Fc -v -f data.dump -U postgres databaseName

+How to restore
psql -f roles.sql
psql -f schema.sql databaseName
pg_restore -a -d databaseName -Fc data.dump

Note: Got this somewhere else, just added some more statements.

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post
NERV Open Source
Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.