Unix Technical Forum

move from 1 database to another

This is a discussion on move from 1 database to another within the Pgsql General forums, part of the PostgreSQL category; --> Hi, I would like to know how can i move from 1 database to another one ? basically i ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 10:55 AM
P.M
 
Posts: n/a
Default move from 1 database to another

Hi,

I would like to know how can i move from 1 database to another one ?

basically i want to run a *.sql script in which i connect under a particular database (for example : template1 or postgres) and my *.sql script should create a new database (for example : test) and after execute several SQL command under test database.

thanks a lot,

Maileen


---------------------------------
Blab-away for as little as 1¢/min. Make PC-to-Phone Calls using Yahoo! Messenger with Voice.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-09-2008, 10:55 AM
Jim Nasby
 
Posts: n/a
Default Re: move from 1 database to another

On May 25, 2006, at 1:52 PM, P.M wrote:
> I would like to know how can i move from 1 database to another one ?
>
> basically i want to run a *.sql script in which i connect under a
> particular database (for example : template1 or postgres) and my
> *.sql script should create a new database (for example : test) and
> after execute several SQL command under test database.


CREATE DATABASE new_database TEMPLATE = database_to_copy;
-- Insert additional SQL here...

--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 10:55 AM
Michael Fuhr
 
Posts: n/a
Default Re: move from 1 database to another

On Thu, May 25, 2006 at 05:41:34PM -0500, Jim Nasby wrote:
> On May 25, 2006, at 1:52 PM, P.M wrote:
> >I would like to know how can i move from 1 database to another one ?
> >
> >basically i want to run a *.sql script in which i connect under a
> >particular database (for example : template1 or postgres) and my
> >*.sql script should create a new database (for example : test) and
> >after execute several SQL command under test database.

>
> CREATE DATABASE new_database TEMPLATE = database_to_copy;
> -- Insert additional SQL here...


I wonder if the OP is looking for "\c new_database".

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 10:55 AM
Ragnar
 
Posts: n/a
Default Re: move from 1 database to another

On fim, 2006-05-25 at 11:52 -0700, P.M wrote:

> I would like to know how can i move from 1 database to another one ?
>
> basically i want to run a *.sql script in which i connect under a
> particular database (for example : template1 or postgres) and my *.sql
> script should create a new database (for example : test) and after
> execute several SQL command under test database.


I guess you are asking how to connect to a new database
in the middleof a sql script

Assuming the script will be run by psql, you can use
\connect test

gnari



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 10:57 AM
P.M
 
Posts: n/a
Default Re: move from 1 database to another

Thanks.
it works well.

Ragnar <gnari@hive.is> wrote: On fim, 2006-05-25 at 11:52 -0700, P.M wrote:

> I would like to know how can i move from 1 database to another one ?
>
> basically i want to run a *.sql script in which i connect under a
> particular database (for example : template1 or postgres) and my *.sql
> script should create a new database (for example : test) and after
> execute several SQL command under test database.


I guess you are asking how to connect to a new database
in the middleof a sql script

Assuming the script will be run by psql, you can use
\connect test

gnari



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org



---------------------------------
Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:01 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com