Re: [GENERAL] Switch database inside psql?

Lists: pgsql-general
From: lynch(at)lscorp(dot)com (Richard Lynch)
To: pgsql-general(at)postgreSQL(dot)org
Subject: Switch database inside psql?
Date: 1998-08-06 23:45:04
Message-ID: v02140b77b1efa8a7d563@[207.152.64.133]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I'd like to have a single file.sql that will create the same database and
some tables on several different systems. Is it possible to 'switch' to a
different database after one does the create database? So that tables
created would go in the new database and not template1? Or does this
already happen and is just not documented?... I'd be guessing a big no on
the latter, since the psql prompt still says 'template1' after I create a
database...

I get an error message when I try createdb from the command line, but once
I've done psql -u, I can do it, so I guess if I had to do this from some
sort of Perl/sed/awk/??? script (none of which I could write anyway), I'd
need to know how to convince createdb that I *am* a valid database-creator,
by golly.

--
--
-- "TANSTAAFL" Rich lynch(at)lscorp(dot)com


From: Maarten Boekhold <maartenb(at)dutepp2(dot)et(dot)tudelft(dot)nl>
To: Richard Lynch <lynch(at)lscorp(dot)com>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Switch database inside psql?
Date: 1998-08-07 09:10:29
Message-ID: Pine.SUN.3.91.980807110900.13396B-100000@dutepp2.et.tudelft.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, 6 Aug 1998, Richard Lynch wrote:

> I'd like to have a single file.sql that will create the same database and
> some tables on several different systems. Is it possible to 'switch' to a
> different database after one does the create database? So that tables
> created would go in the new database and not template1? Or does this
> already happen and is just not documented?... I'd be guessing a big no on
> the latter, since the psql prompt still says 'template1' after I create a
> database...

use '\connect database name' from witnin psql. Maybe you have to include a
username, don't know.

> I get an error message when I try createdb from the command line, but once

Probably because of authentication problems. You can set the PGUSER and
PGPASSWORD environment variables to use authentication always (ie. you
don;t have to specify a '-u' switch anymore).

> I've done psql -u, I can do it, so I guess if I had to do this from some
> sort of Perl/sed/awk/??? script (none of which I could write anyway), I'd
> need to know how to convince createdb that I *am* a valid database-creator,
> by golly.

Maarten

_____________________________________________________________________________
| TU Delft, The Netherlands, Faculty of Information Technology and Systems |
| Department of Electrical Engineering |
| Computer Architecture and Digital Technique section |
| M(dot)Boekhold(at)et(dot)tudelft(dot)nl |
-----------------------------------------------------------------------------


From: Tom Good <tomg(at)nrnet(dot)org>
To: Richard Lynch <lynch(at)lscorp(dot)com>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Switch database inside psql?
Date: 1998-08-07 12:42:05
Message-ID: Pine.LNX.3.95.980807082624.1047A-100000@mailhost.nrnet.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

> On Thu, 6 Aug 1998, Richard / Maarten wrote:
>
> > I'd like to have a single file.sql that will create the same database and
> > some tables on several different systems. Is it possible to 'switch' to a
> > different database after one does the create database? So that tables
> > created would go in the new database and not template1? Or does this
> > already happen and is just not documented?... I'd be guessing a big no on
> > the latter, since the psql prompt still says 'template1' after I create a
> > database...
>
> use '\connect database name' from witnin psql. Maybe you have to include a
> username, don't know.

Hello Rich, goedemorgen Maarten...

Just a footnote, as a clumsy typist I prefer the short form: \c new_db_name
BTW, one can do this from a dump file. Or you can make calls from perl
scripts...I like to build things both ways.

I often do psql -e db < makedb.sql (when I'm too lazy to connect to
a db and run \i...)

> > I've done psql -u, I can do it, so I guess if I had to do this from some
> > sort of Perl/sed/awk/??? script (none of which I could write anyway), I'd
> > need to know how to convince createdb that I *am* a valid database-creator,
> > by golly.

Rich, I'd be very pleased to be able to assist with perl - if you like.
As a guy accustomed to procedural languages (PROGRESS, et al.) I am rather
fond of Edmund Mergl's dbd-Pg module. I use perl as a sort of 4GL.
(Rather nifty, if functions like a 4GL but has syntax reminiscent of ESQL/C.)

All of the code we develop here is public domain stuff so I'd be happy
to pass along whatever is of interest, including my dba.pl script.
Just say the word, big guy...I owe ya. ;-)

Cheers,
Tom

----------- Sisters of Charity Medical Center ----------
Department of Psychiatry
----
Thomas Good, System Administrator <tomg(at)q8(dot)nrnet(dot)org>
North Richmond CMHC/Residential Services Phone: 718-354-5528
75 Vanderbilt Ave, Quarters 8 Fax: 718-354-5056
Staten Island, NY 10304 www.panix.com/~ugd
----
Powered by PostgreSQL 6.3.2 / Perl 5.004 / DBI-0.91::DBD-PG-0.69