PostgreSQL (AKA postgres) is the one of the well-known relational database. It is pretty capable of doing everything such as storing JSON object, DB replication and so on. Beside that it is also open source software. In this post I demonstrate some basic commands of PostgreSQL for beginners.
The first thing you need to know is installation procedure of PostgreSQL which is fairly easy in Ubuntu. You can install postures by following the tutorial this link.
Now here is the list of the some of the most useful PostgreSQL commands,
- Version:
psql -version
- End of each commend should end with
;
- Enter to database:
psql [dbname]
- Quit:
\q
- Create database:
createdb [mydb]
- Drop database:
dropdb [mydb]
- Stop the service:
service postgresql stop
Or/etc/init.d/postgresql stop
- Start the service:
service postgresql start
Or/etc/init.d/postgresql start
- Restart the service:
service postgresql restart
Or/etc/init.d/postgresql restart
- Reload the service:
service postgresql reload
Or/etc/init.d/postgresql reload
- Add a normal user to db:
createuser [kasra]
- Add a super user to db:
createuser -s [kasra]
- Getting a list of available databases:
psql -l
- Backup database:
pg_dump -O dbName > dumpFileName.pg_dump
- Populate database:
psql -f dumpFileName dbName