Re: postgresql create db script

2008-01-18 Thread Anton P. Linevich

Greeting, Carl!  Fri, Jan 18, 2008 at 02:26:33AM -0600, carl wrote: 

> I am trying to write a shell script that do whatever needs to be done between
> sudo apt-get install postgresql python-psycopg
> and
> manage.py syncdb
> 
> for MySql, I use this to generate somehting I can pipe into the CLI:
> 
> print  """
> DROP DATABASE IF EXISTS %(db)s;
> CREATE DATABASE %(db)s;
> GRANT ALL
>  ON %(db)s.*
>  TO %(user)s
>  IDENTIFIED BY '%(pw)s'
>  with grant option;
> """ % {
>  'db':settings.DATABASE_NAME,
>  'user':settings.DATABASE_USER,
>  'pw':settings.DATABASE_PASSWORD }
> 
> pipe that into the MySql CLI.
> 
> I can't figure out how to do it with psql without it prompting me for input.
> 
> I don't need it that fancy, just a script with everything hard coded would be 
> fine.

PG_USER="_postgresql"
PG_PASS="password"
DB_HOST="127.0.0.1"
PREFIX="/backups/pgsql/`date "+%d"`"
DB="db_name"

echo $YOURSQL | PGUSER="$PG_USER" PGPASSWORD="$PG_PASS" psql -h 
$DB_HOST $DB
or:
PGUSER="$PG_USER" PGPASSWORD="$PG_PASS" psql -h $DB_HOST $DB -C 
"$YOURSQL"

-- 
 Anton P. Linevich

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: postgresql create db script

2008-01-18 Thread Brett Parker

On 18 Jan 02:26, Carl Karsten wrote:
> 
> I am trying to write a shell script that do whatever needs to be done between
> sudo apt-get install postgresql python-psycopg
> and
> manage.py syncdb
> 
> for MySql, I use this to generate somehting I can pipe into the CLI:
> 
> print  """
> DROP DATABASE IF EXISTS %(db)s;
> CREATE DATABASE %(db)s;
> GRANT ALL
>  ON %(db)s.*
>  TO %(user)s
>  IDENTIFIED BY '%(pw)s'
>  with grant option;
> """ % {
>  'db':settings.DATABASE_NAME,
>  'user':settings.DATABASE_USER,
>  'pw':settings.DATABASE_PASSWORD }
> 
> pipe that into the MySql CLI.
> 
> I can't figure out how to do it with psql without it prompting me for input.

psql will happily take piped input - you might need to edit
/etc/postgres/pg_hba.conf (or similar location) and you might need to
add your user - if it's prompting for a password then the only way I
know of getting round the password issue is to specify it as the
environmental variable PGPASSWD.

Hope that helps,
-- 
Brett Parker

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



postgresql create db script

2008-01-18 Thread Carl Karsten

I am trying to write a shell script that do whatever needs to be done between
sudo apt-get install postgresql python-psycopg
and
manage.py syncdb

for MySql, I use this to generate somehting I can pipe into the CLI:

print  """
DROP DATABASE IF EXISTS %(db)s;
CREATE DATABASE %(db)s;
GRANT ALL
 ON %(db)s.*
 TO %(user)s
 IDENTIFIED BY '%(pw)s'
 with grant option;
""" % {
 'db':settings.DATABASE_NAME,
 'user':settings.DATABASE_USER,
 'pw':settings.DATABASE_PASSWORD }

pipe that into the MySql CLI.

I can't figure out how to do it with psql without it prompting me for input.

I don't need it that fancy, just a script with everything hard coded would be 
fine.

Carl K



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---