Thread: Database schema

Database schema

From
Dhiraj Gupta
Date:
 Hi All,
I have  created a database name '"ofbiz". then the default  schema name "public " created automatically. I want to create schema name ofbiz in the database "ofbiz"
 when I create database name "ofbiz" then the schema name "ofbiz" will create automatically.
how it is possible if yes,

Thanks
Dhiraj Gupta

Re: Database schema

From
"Karsten Hilbert"
Date:
> I have created a database name '"ofbiz". then the default schema name
> "public " created automatically. I want to create schema name ofbiz in the
> database "ofbiz"
>  when I create database name "ofbiz" then the schema name "ofbiz" will
> create automatically.
> how it is possible if yes,

Pre-create the schema in the database that's used as a template when
creating database ofbiz.

It's all in the docs.

Karsten


Re: Database schema

From
Albe Laurenz
Date:
Dhiraj Gupta wrote:
> I have  created a database name '"ofbiz". then the default  schema name "public "
> created automatically. I want to create schema name ofbiz in the database "ofbiz"
> when I create database name "ofbiz" then the schema name "ofbiz" will create automatically.
> how it is possible if yes, 

There is no way to automatically create a schema when you create a database.
Connect to the newly created database and create it with CREATE SCHEMA.
You can DROP SCHEMA public if you don't need it.

Yours,
Laurenz Albe

Re: Database schema

From
Greg Williamson
Date:

Dhiraj --

>________________________________
> From: Dhiraj Gupta <dhiraj.g@nic.in>
>To: pgsql-general@postgresql.org
>Sent: Sunday, December 2, 2012 9:35 PM
>Subject: [GENERAL] Database schema
>
>
> Hi All,
>I have  created a database name '"ofbiz". then the default  schema name "public " created automatically. I want to
createschema name ofbiz in the database "ofbiz" 
> when I create database name "ofbiz" then the schema name "ofbiz" will create automatically.
>how it is possible if yes,
>
>Thanks
>Dhiraj Gupta
>


When a new database is created, the template is the builtin database called "template1".

If you create the schema in that database, that schema will be made part of any new database you make. You could also
makea new template database, create the schema in that one, and then create your new databases using the "WITH TEMPLATE
=" option in CREATE DATABASE. So if you have need of different schemas with different databases, that would be more
extensibleby making new templates, onjhe3 for each type./. 

HTH,

Greg Williamson


Re: Database schema

From
Andreas Kretschmer
Date:
Albe Laurenz <laurenz.albe@wien.gv.at> wrote:

> Dhiraj Gupta wrote:
> > I have  created a database name '"ofbiz". then the default  schema name "public "
> > created automatically. I want to create schema name ofbiz in the database "ofbiz"
> > when I create database name "ofbiz" then the schema name "ofbiz" will create automatically.
> > how it is possible if yes,
>
> There is no way to automatically create a schema when you create a database.
> Connect to the newly created database and create it with CREATE SCHEMA.
> You can DROP SCHEMA public if you don't need it.

There is a way to create a so called schema in every new created
database: create that schema in the template1, or create a new template
database and use this template to create a new database.


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


Re: Database schema

From
Albe Laurenz
Date:
Andreas Kretschmer wrote:
> Albe Laurenz <laurenz.albe@wien.gv.at> wrote:
>> Dhiraj Gupta wrote:
>>> I have  created a database name '"ofbiz". then the default  schema name "public "
>>> created automatically. I want to create schema name ofbiz in the database "ofbiz"
>>> when I create database name "ofbiz" then the schema name "ofbiz" will create automatically.
>>> how it is possible if yes,
>>
>> There is no way to automatically create a schema when you create a database.
>> Connect to the newly created database and create it with CREATE SCHEMA.
>> You can DROP SCHEMA public if you don't need it.
>
> There is a way to create a so called schema in every new created
> database: create that schema in the template1, or create a new template
> database and use this template to create a new database.

Technically you are right, but from the original question I assumed
that the schema should have the same name as the database.

Yours,
Laurenz Albe