Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4028
  • Last Modified:

what is the difference between schemas and catalogs?

hello experts,
i'm using pgAdmin to interface postgresql,

i've create databases, my databases contains: schemas and catalogs,
but inside a schema there's the same elements than in a catalog:
Aggregates,  Domains, Functions, Sequences, Tables, Trigger Functions, Types, Views.  

what is the  difference between the two?
0
toshi_
Asked:
toshi_
  • 3
  • 3
4 Solutions
 
Hugh FraserConsultantCommented:
Catalogs are simply tables (like any other) that contain information about the database, like tables, indices, operators, functions. data types, etc.. Since Postgres is extensible, this information (like new data types) is cntabined in tables you can add too, rather than coded into the engine directly.

Schemas is a namespace. It contains catalogs and tables, but is separate from other schemas, allowing multiple definitions for a new data type or function to be used within the same database. You might, for instance, have development environments for two groups hosted on the same database, but kept in different schemas to prevent naming conflicts.
0
 
toshi_Author Commented:
as i see it in pgAdmin,
there's just the icon that is different,



catalog-vs-schema.png
0
 
toshi_Author Commented:
what could i do in schemas that i can not do in catalogs and vice-versa?


0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Hugh FraserConsultantCommented:
Remember that Postgres is extensible, meaning that you can define new datatypes, operators, functions, etc.. These extensions are not like an attribute of a table; they are completely new types of data (like the standard int, text, float, etc.) and the operators that work on them (like +,-,/,*).that apply to any queries, tables, etc.. So if you've created a new datatype called widget, you're free to create a table with an attribute in it called widget, re-define the "+" function to do something meaningful when you add two widgets.

But maybe someone else has another project that defines their own datatype called widget. Schemas allow you to have multiple sets of these extensions within Postgres. Depending upon which schema you choose to use, you will inherit the extensions defined in that schema. By creating separate schemas for each of these environments, you can support both definitions.

My example's a bit lame, but hopefully it gets the idea across. Most uses of Postgres I've seen never delve into extensions, and don't use schemas.
0
 
toshi_Author Commented:

Most uses of Postgres I've seen never delve into extensions, and don't use schemas.?


so what do they do?

0
 
Hugh FraserConsultantCommented:
Use it as a standard database out of the box The extensions and schema support are only necessary if the standard offerings don't meet your requirements.
0
 
brycenCommented:
With schemas, you can create separate namespaces:
bnesbitt=> create table foo (foo_key integer, foo_text varchar(1024));
bnesbitt=> create schema api2;
bnesbitt=> create table api2.foo (foo_key integer, foo_int integer);
Here "select * from api2.foo;" returns different results from "select * from foo" (which is really "select * from public.foo".  The default schema is called "public".
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now