Обсуждение: Switch database inside psql?

Поиск
Список
Период
Сортировка

Switch database inside psql?

От
lynch@lscorp.com (Richard Lynch)
Дата:
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@lscorp.com



Re: [GENERAL] Switch database inside psql?

От
Maarten Boekhold
Дата:
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.Boekhold@et.tudelft.nl                         |
-----------------------------------------------------------------------------


Re: [GENERAL] Switch database inside psql?

От
Tom Good
Дата:
> 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@q8.nrnet.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