Skip to main content

Posts

Showing posts from June 8, 2011

Psql Commands for PostgreSql

PostgreSql is an open source  Enterprise Relational Database Management System (RDBMS). To access postgres database, you can either use the graphical user interface pgAdmin or the command line interface psql. Though pgAdmin is lot easier with the GUI, for command prompt freaks, psql is THE tool for accessing database. Though it is little tough to get used to, once you are in, I am sure nothing tastes better. I have provided the basic steps here for basic operations with the database. Refer here for configuring PostgreSql for access from psql.
Connecting to database:
psql -U username -d databasename
Eg:
psql -U postgres -d shankar
Connecting to Remote Database:
psql -U username -h hostname -d databasename
Eg:
psql -U postgres -h 192.168.1.65 -d shankar
Writing the query output to a file:
\o filename
<<Query>>
Eg:
shankar=# \o /home/shankar/person.txt
shankar=#SELECT * FROM ad_client;
This command will write the output of the query to the file person.txt
This will keep recordin…