Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

PostgreSQL .bash_profile Set Up


Here i explained how to set up postgresql bash_profile and what is use of postgresql bash profile.
if you set up bash_profile means you can directly access your postgresql utility anywhere in a server without going to bin path, if you see following example you will understand the benefit of bash_profile



Step 1:Go to pg_env file and open it using "cat" command Like Following 

[root@r1 ~]# cd /opt/PostgreSQL/9.3/
3rd_party_licenses.txt    installer/                scripts/
bin/                      lib/                      share/
data/                     license.txt               stackbuilder/
doc/                      pgAdmin3/                 uninstall-postgresql
include/                  pg_env.sh                 uninstall-postgresql.dat

[root@r1 ~]# cat /opt/PostgreSQL/9.3/pg_env.sh 
#!/bin/sh
# The script sets environment variables helpful for PostgreSQL

export PATH=/opt/PostgreSQL/9.3/bin:$PATH
export PGDATA=/opt/PostgreSQL/9.3/data
export PGDATABASE=postgres
export PGUSER=postgres
export PGPORT=5432
export PGLOCALEDIR=/opt/PostgreSQL/9.3/share/locale
export MANPATH=$MANPATH:/opt/PostgreSQL/9.3/share/man
Step 2:Copy the "pg_env" file and paste into the ".bash_profile"Like following 
[postgres@r1 ~]$ cat .bash_profile 
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
 
PATH=$PATH:$HOME/bin
export PATH
export PATH=/opt/PostgreSQL/9.3/bin:$PATH
export PGDATA=/opt/PostgreSQL/9.3/data
export PGDATABASE=postgres
export PGUSER=postgres
export PGPORT=5432
export PGLOCALEDIR=/opt/PostgreSQL/9.3/share/locale
export MANPATH=$MANPATH:/opt/PostgreSQL/9.3/share/man
Step 3.Connect To the database without bash_profile setup:
[postgres@r1 ~]$ cd /opt/PostgreSQL/9.3/bin/
[postgres@r1 bin]$./psql -p 5432 -d postgres -U postgres
Password for user postgres: 
psql.bin (9.3.14)
Type "help" for help.

No entry for terminal type "xterm";
using dumb terminal settings.
postgres=#  

Step 4:Run the Bash Profile as "Postgres user"
[postgres@r1 ~]$ . .bash_profile 
Step 5:Then you can easily connect the Postgres server using with "psql" Utility without going utility path
[postgres@r1 ~]$ psql
Password: 
psql.bin (9.3.14)
Type "help" for help.
 
No entry for terminal type "xterm";
using dumb terminal settings.
postgres=# 
Step 6:you can call the linux postgresql utility without going postgresql bin path if you not set bash_profile and want to take backup means first you have to go bin path(/opt/PostgreSQL/9.3/bin) then you have to issue ./pg_dump
if you set bash_profile you can call directly like pg_dump

Running bash_profile:
[postgres@r1 ~]$ . .bash_profile 
[postgres@r1 ~]$ pwd
/home/postgres
calling createdb utility:
[postgres@r1 ~]$createdb johndb
Password: 
[postgres@r1 ~]$
 calling psql utility :

[postgres@r1 ~]$psql johndb
Password: 
psql (9.1.2.2)
Type "help" for help.

No comments:

Post a Comment