Re: Automating databse creation

From: "Shoaib Mir" <shoaibmir(at)gmail(dot)com>
To: "Ashish Karalkar" <ashish(dot)karalkar(at)info-spectrum(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Automating databse creation
Date: 2007-02-09 08:32:33
Message-ID: bf54be870702090032u4eae8b9fr593457bdee45bc95@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Yes, you can pass values to the scripts. Here is an example....

Suppose the script file 'test.sql' is like this:

insert into test values (:chk1 , :chk2);

Now you can pass the variables using psql as:

psql -d test -U postgres -v chk1=5 -v chk2='abc' -f test.sql

Hope that helps...

--
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)

On 2/9/07, Ashish Karalkar <ashish(dot)karalkar(at)info-spectrum(dot)com> wrote:
>
> Hello list,
> I want to automate database creation, user creation,table creation via
> script. this script will be run by an external programme to postgresql
> server.
> is there any way?
>
> what i want to do is as follows:
>
>
>
> #!/bin/sh
>
> su - postgres
>
> TIMEDUMP=`date +%Y%m%d"_"%H%M`
>
> PG_PATH=/usr/local/pgsql/bin
>
> ${PG_PATH}/pg_dump -d qsweb -U postgres -p 5432 -Ft -f
> /usr/local/pgsql/data/backup/BACKUP_QSWEB_${TIMEDUMP}.tar
>
> echo ' Backup of Database for Quick School kept at path
> /usr/local/pgsql/data/backup/BACKUP_QSWEB_${TIMEDUMP}.tar'
>
> ${PG_PATH}/dropdb -U qsweb qsweb
>
> echo ' Old Database for Quick School Dropped'
>
> ${PG_PATH}/dropuser qsweb
>
> echo ' Old user qsweb for Quick School Dropped'
>
> ${PG_PATH}/createuser -s qsweb
>
> echo ' New user qsweb for Quick School created'
>
> ${PG_PATH}/createdb -O qsweb qsweb
>
> echo ' New Database qsweb for Quick School created'
>
> ${PG_PATH}/createlang -U qsweb -d qsweb plpgsql
>
> echo ' Database language plpgqslfor Quick School created'
>
> echo ' Database for Quick School created. Please run the Create_Tables.sql
> script'
>
> ${PG_PATH}/psql -U qsweb qsweb
>
> and then Run Create_Tables.sql
>
> _EOF_
>
>
>
>
>
> is there any way??
>
> right now the scripts stop after switching over to postgres user.
>
>
>
> With regards
>
> Ashish...
>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A. Kretschmer 2007-02-09 12:43:19 Re: does anyone have a tool to convert SP'sT-SQL to Postgres
Previous Message Ashish Karalkar 2007-02-09 07:53:33 Automating databse creation