Thursday 24 July 2014

Tip : Connect to postgresq SQL from command line Cent OS 32 bit OS ( Postgres installed with Jasper Server )

Hi Guys,

This tip will let you know how to connect to postgres SQL server from command prompt.

Most of the times, we go for bundled installation of jasper server which also installs postgres SQL server with it.

In windows, it is easy to use pgAdmin client tool to perform various operations on postgresql db...

In Cent OS ?? pgAdmin is specific for windows(or is it not?)....

If we install postgres separately, the logging into it is completely different scenario & the installation must goes into different locations...


To logging into postgres from command prompt follow below steps.

Step 1 : Navigate to below location with su(super user) permission of your cent OS. 

/home/sadakar123/jasperreports-server-5.6/postgresql/bin

Step 2:fire below command
[root@localhost bin]# ./psql
Password: postgres
 postgres=#

Step 3: Show databases

 postgres=#\list

 Step 5 : Connecting to database
Syntax : \connect (or \c) dbname
 
Example:
 
postgres-# \c foodmart
You are now connected to database "foodmart".
foodmart-# 
 
 
Step 6: Creating new Database 
 
foodmart=# create database test;
CREATE DATABASE
foodmart=# 
foodmart=# \c test;
You are now connected to database "test".

Step 7 : List all the tables in selected database

\dt lists all tables in the current database 



References :
1) http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/
 
 
 
Sadakar
BI developer