473,605 Members | 2,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Naive schema questions

I have a number of web applications which have a large amount of their
logic written in plpgsql. For each particular application I have a
separate instance of a database. If I need to update functions I have to
connect to each database and then run \i fn_function_upd ate.sql.

I imagined schemas might allow me to globally update functions across a
database hosting many schemas with the same structure. In this scenario
my webapp would always connect to the same database, but address
different schemas, so that

mysolution.sche ma_A.people would be addressed for site 'A'
and
mysolution.sche ma_B.people would be addressed for site 'B'

(I'm assuming here that I can set the context of the schema at
connection by a plpgsql line that sets the current search path.)

However

Schemas also contain other kinds of named objects, including data
types, functions, and operators.
(html reference: ddl-schemas.html)

seems to suggest that the functions are schema specific.

I suppose I'm trying to think of how I might implement the second point
in this list (also from dd-schemas.html):

There are several reasons why one might want to use schemas:
- To allow many users to use one database without interfering with
each other.
- To organize database objects into logical groups to make them more
manageable.
- Third-party applications can be put into separate schemas so they
cannot collide with the names of other objects.

Thanks for any observations
Rory

--
Rory Campbell-Lange
<ro**@campbel l-lange.net>
<www.campbell-lange.net>

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
7 1412
Am Donnerstag, 27. Mai 2004 13:15 schrieb Rory Campbell-Lange:
I imagined schemas might allow me to globally update functions across a
database hosting many schemas with the same structure.


Put your data tables in separate schemas, put the functions in yet another
schema, and then when you connect set the schema search path to "dataschema ,
functionschema" (or maybe vice versa).

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #2
On 5/27/2004 7:15 AM, Rory Campbell-Lange wrote:
I have a number of web applications which have a large amount of their
logic written in plpgsql. For each particular application I have a
separate instance of a database. If I need to update functions I have to
connect to each database and then run \i fn_function_upd ate.sql.

I imagined schemas might allow me to globally update functions across a
database hosting many schemas with the same structure. In this scenario
my webapp would always connect to the same database, but address
different schemas, so that

mysolution.sche ma_A.people would be addressed for site 'A'
and
mysolution.sche ma_B.people would be addressed for site 'B'

(I'm assuming here that I can set the context of the schema at
connection by a plpgsql line that sets the current search path.)
That is so.

However

Schemas also contain other kinds of named objects, including data
types, functions, and operators.
(html reference: ddl-schemas.html)

seems to suggest that the functions are schema specific.
It is even better. The property that set's your "schema context" is
called search_path. This contains a list of schema names. For an
unqualified (schema name not explicitly given) object, be that a table,
sequence, view, function or whatever, the system looks in all those
schemas in that particular order and uses the first found.

With that, you can have your common or shared objects in a central
schema "schema_common" , and everything that's application specific in
"schema_A", "schema_B". The connection just has to set the search_path
at the beginning with

set search_path = schema_A, schema_common;

and done.

I suppose I'm trying to think of how I might implement the second point
in this list (also from dd-schemas.html):

There are several reasons why one might want to use schemas:
- To allow many users to use one database without interfering with
each other.
- To organize database objects into logical groups to make them more
manageable.
- Third-party applications can be put into separate schemas so they
cannot collide with the names of other objects.


Yes, yes and yes. Plus the ability for you to do cross database joins
for global analyzing for example.
Jan

--
#============== =============== =============== =============== ===========#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#============== =============== =============== ====== Ja******@Yahoo. com #
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #3
----- Original Message -----
From: "Peter Eisentraut" <pe*****@gmx.ne t>
To: "Rory Campbell-Lange" <ro**@campbel l-lange.net>
Cc: "Postgresql General List" <pg***********@ postgresql.org>
Sent: Thursday, May 27, 2004 1:10 PM
Subject: Re: [GENERAL] Naive schema questions

Am Donnerstag, 27. Mai 2004 13:15 schrieb Rory Campbell-Lange:
I imagined schemas might allow me to globally update functions across a
database hosting many schemas with the same structure.
Put your data tables in separate schemas, put the functions in yet another
schema, and then when you connect set the schema search path to

"dataschema , functionschema" (or maybe vice versa).


Or when you make the calls in the web app use the following:

SELECT function_schema .function1(arg1 , arg2);

instead of just:

SELECT function1(arg1, arg2);

But like Peter said have a schema per client/"instance" of your database.

Nick

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #4
On 5/27/2004 7:15 AM, Rory Campbell-Lange wrote:
seems to suggest that the functions are schema specific.


It is even better. The property that set's your "schema context" is
called search_path. This contains a list of schema names. For an
unqualified (schema name not explicitly given) object, be that a table,
sequence, view, function or whatever, the system looks in all those
schemas in that particular order and uses the first found.


And where do tables created with "CREATE LOCAL TEMPORARY TABLE..." fit
into this, like if say a local temp table where created that has the same
name as an existing normal (i.e., not a local temp) table? And what if I
do an explicit DROP of the local temp table rather than relying on the
automatic, end-of-session clean-up? Is there any risk of losing the
normal table?

--Berend Tober


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

Nov 23 '05 #5
Fabulous stuff! I am so delighted I chose Postgresql a couple of year
ago. Thank you for the valuable insights. A comment or two below:

On 27/05/04, Peter Eisentraut (pe*****@gmx.ne t) wrote:
Am Donnerstag, 27. Mai 2004 13:15 schrieb Rory Campbell-Lange:
I imagined schemas might allow me to globally update functions across a
database hosting many schemas with the same structure.
Put your data tables in separate schemas, put the functions in yet
another schema, and then when you connect set the schema search path
to "dataschema , functionschema" (or maybe vice versa).
On 27/05/04, Nick Barr (ni***@chuckie. co.uk) wrote: Put your data tables in separate schemas, put the functions in yet
another schema, and then when you connect set the schema search path
to "dataschema , functionschema" (or maybe vice versa). Or when you make the calls in the web app use the following:

SELECT function_schema .function1(arg1 , arg2);
instead of just:
SELECT function1(arg1, arg2);
But like Peter said have a schema per client/"instance" of your database.
Is it ok to use the public schema for the functions? It means it is that
much easier to reload the functions as one wouldn't need to specify the
search_path.

On 27/05/04, Jan Wieck (Ja******@Yahoo .com) wrote:
.... It is even better. The property that set's your "schema context" is
called search_path. This contains a list of schema names. For an
unqualified (schema name not explicitly given) object, be that a table,
sequence, view, function or whatever, the system looks in all those
schemas in that particular order and uses the first found.

With that, you can have your common or shared objects in a central
schema "schema_common" , and everything that's application specific in
"schema_A", "schema_B". The connection just has to set the search_path
at the beginning with

set search_path = schema_A, schema_common;
This is brillliant. I didn't note this in the documentation.
I suppose I'm trying to think of how I might implement the second point
in this list (also from dd-schemas.html): .... - To organize database objects into logical groups to make them more
manageable.

.... Yes, yes and yes. Plus the ability for you to do cross database joins
for global analyzing for example.


Just a question on this, Jan. Would one expect UNIONS for this sort of
work?

I just did this which is useful anyway:
schematest=> SELECT
(select count(id) from b.messages)
+
(select count(id) from a.messages);
?column?
----------
5
(1 row)

I see the horizons expanding! Common data (I often have an 'info' table)
can be shared between schemas. I think my search_patch might go:

this_schema, info_schema, public_schema

Thanks very much for the information.

Kind regards,
Rory
--
Rory Campbell-Lange
<ro**@campbel l-lange.net>
<www.campbell-lange.net>

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

Nov 23 '05 #6
On 5/27/2004 6:03 PM, Rory Campbell-Lange wrote:
Just a question on this, Jan. Would one expect UNIONS for this sort of
work?

I just did this which is useful anyway:
schematest=> SELECT
(select count(id) from b.messages)
+
(select count(id) from a.messages);
?column?
----------
5
(1 row)

I see the horizons expanding! Common data (I often have an 'info' table)
can be shared between schemas. I think my search_patch might go:
You can mix those in queries however you want. They are just namespaces
with some additional security (even if you grant public access to an
object inside a schema, one still needs access to the schema itself).
The search path let's you hide one schemas objects behind another ones
by chosing the order. You can use qualified or unqualified names and
different search path's where one or the other makes sense in your
application- and data-design. After all, all the objects reside in the
same database and all access is covered by the same transaction.

The problem with expanded horizons is that one has more possibilities to
screw it up at the same time he get's more flexibility. Well used, this
is a powerfull feature. Poorly applied and inconsistently used it can
become a maintenance nightmare.
Jan

this_schema, info_schema, public_schema

Thanks very much for the information.

Kind regards,
Rory

--
#============== =============== =============== =============== ===========#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#============== =============== =============== ====== Ja******@Yahoo. com #
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #7
<bt****@compute r.org> writes:
And where do tables created with "CREATE LOCAL TEMPORARY TABLE..." fit
into this, like if say a local temp table where created that has the same
name as an existing normal (i.e., not a local temp) table?
Temp tables live in a schema that is effectively inserted into your
search path ahead of whatever schema(s) are explicitly listed there.
For instance, suppose

CREATE SCHEMA a;
SET search_path = a, public;
CREATE TABLE t1 (...);
-- t1 is created in schema a
SELECT * FROM t1;
-- same as SELECT * FROM a.t1;

Now if I do

CREATE TEMP TABLE t1 (...);

then SELECT * FROM t1 will reference the temp table ... but I can still
get to the permanent table by explicitly qualifying it as "a.t1".
And what if I
do an explicit DROP of the local temp table rather than relying on the
automatic, end-of-session clean-up?
You drop the temp table.
Is there any risk of losing the normal table?


Only if you do it twice --- after the initial DROP, the permanent table
would come back "into view".

regards, tom lane

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

Nov 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2990
by: Fred Smith | last post by:
Any suggestions or tips to the questions below I have been wrestling with would be most welcome: I have an example XSD file I have been experimenting with. Suppose a user can select from 1 to 4 checkboxes on a web form: Select your favorite sport(s): (checkbox) baseball (checkbox) football
3
1914
by: william_hulse | last post by:
The general process i am currently working on is this: STEP 1 xml doc1 is transformed using stylesheet1 to produce xml doc2 - xml doc1 has a namespace declaration as follows... <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="G:\Working\User\Will_Hulse\NEW\xmldb\code\Bank_Statements_Schema\EXBAEUFRED01.xsl"?>
1
1793
by: Porthos | last post by:
Hello all, Is there a facet pattern that will allow for the inclusion of a newline or carriage return to occur within a tag? From the W3C schema document and from previous posts I've read that should take care of this situation, however when I include that pattern (and a newline\carriage return) I still recieve an error telling me that my data is an invalid value according to its data type. When I remove the returns and new lines the...
0
1162
by: Steve Jorgensen | last post by:
In a schema I've been working on recently, a convention I evolved was to use a consistent naming pattern such that, for instance, a Resident could appear in a ResidentSet, and could be referred to by a ResidentRef, and the same pattern would apply to other types of entities. That amounts to a lot of duplication in the schema, though, and results in a need to enforce consistency in how the naming convention is applied. A solution I've...
4
2613
by: cmc | last post by:
I need some clarification to help me understand the DB2 strucure more. The questions are about "implicit schema" 1. This is a very interest concpet that DB2 let every user to create new schema (as this is part of the PUBLIC group privilege - if I am not wrong). From a practical stand point, what is the application of such concept. 2. Suprisingly, if the schema is an implicitly created, everyone else can create objects in it too. What...
9
1564
by: JohnSouth104 | last post by:
Hi I've an asp.net, c#, sql server website and the volumes are starting to rise quickly. I've been asked to look at improving the memory usage of the application. I've not looked at this before so these are probably naive questions: 1. If I close the sql connection every time do I need to close or dispose of the dataset, command or any other objects? 2. Should I use data adaptor instaed of dataset?
16
4292
by: Bob Stearns | last post by:
The syntax diagram of DROP SCHEMA requires RESTRICT. Is there an easy way to drop an old, unnecessary, but populated schema?
3
9919
by: Eric Lilja | last post by:
Sorry for asking so many questions, but I've just started and need to get some things working so I can do the task that is before me. Consider this (validating) schema: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="myns" xmlns="myns" elementFormDefault="qualified"> <xs:element name="books"> <xs:complexType> <xs:sequence>
3
4881
by: pragy | last post by:
Hey, can any one help me for writing a program of naive gauss elimintaion technique? It's a technique to solve system of simultaneous linear equations using matrix. thanks
0
7934
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.