Skip site navigation (1) Skip section navigation (2)

Re: Database connectivity using a unix shell

From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Database connectivity using a unix shell
Date: 2006-06-29 18:30:34
Message-ID: 60d5crx19x.fsf@dba2.int.libertyrms.com (view raw or flat)
Thread:
Lists: pgsql-general
jsbali(at)gmail(dot)com ("Jasbinder Bali") writes:
> in my bash script where and how do i specify the database connection
> parameters

There are three ways:

1.  You can store them in environment variables:

PGDATABASE=my_database
PGPORT=8901
PGUSER=superman
PGHOST=some.host.somewhere
export PGDATABASE PGPORT PGUSER PGHOST

2.  You can specify them in command line parameters:

psql -h some.host.somewhere -p 8901 -U superman -d my_database

3.  You could specify a service name

PGSERVICE=my_fave_db psql

where the pg_service.conf in your PostgreSQL installation contains an
entry:

[my_fave_db]
dbname=my_database
user=superman
host=some.host.somewhere
port=8901

4.  You can mix these; perhaps start by having PGSERVICE provide part
of the information, then environment variables may add to/override
some of that, then command line parameters may add to/override
further...

For a lot of our production environments, we have set up a big,
comprehensive pg_service.conf file; local accounts then pick favorite
values for PGSERVICE...
-- 
let name="cbbrowne" and tld="acm.org" in String.concat "@" [name;tld];;
http://cbbrowne.com/info/lsf.html
"Why use Windows, since there is a door?"
-- <fachat(at)galileo(dot)rhein-neckar(dot)de> Andre Fachat

In response to

pgsql-general by date

Next:From: eleinDate: 2006-06-29 18:37:53
Subject: Re: Database connectivity using a unix shell
Previous:From: Martijn van OosterhoutDate: 2006-06-29 16:47:17
Subject: Re: [GENERAL] UUID's as primary keys

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group