2. Object-relational database management system (ORDBMS)
Developed at the University of California at Berkeley Computer Science
Department.
Open-source descendant of the original Berkeley code.
It supports a large part of the SQL standard and offers many modern
features:
• Complex queries
• Foreign keys
• Triggers
• Views
• Transactional integrity
• Multi-version concurrency control
Free of charge for any purpose, be it private, commercial, or academic.
Overview
3. Comparison with other Databases
Features Not
in Others
• User-defined
types,
• Inheritance,
rules,
• Multi-
version
concurrency
control to
reduce lock
contention
Performance
• Faster for
some things,
slower for
others
• Usually +/-
10%
compared to
other
databases
Reliability
• Stable code
that has a
minimum of
bugs
• Release has
at least one
month of
beta testing
Support
• Mailing lists
• Direct access
to
developers,
the user
community,
manuals, and
the source
code
• Commercial
per-incident
support
Price
• Free for all
use, both
proprietary
and open
source
4. PostgreSQL uses a client/server model.
A PostgreSQL session consists of the following cooperating processes
(programs):
• A server process, which manages the database files, accepts connections to the
database from client applications, and performs database actions on behalf of the
clients. The database server program is called postgres.
• The user's client (frontend) application that wants to perform database
operations. Client applications can be very diverse in nature: a client could be a
text-oriented tool, a graphical application, a web server that accesses the
database to display web pages, or a specialized database maintenance tool.
The client and the server can be on different hosts. In that case they
communicate over a TCP/IP network connection.
The PostgreSQL server can handle multiple concurrent connections from
clients. To achieve this it starts ("forks") a new process for each connection.
Architecture
5. PostgreSQL is a relational database management
system (RDBMS). That means it is a system for
managing data stored in relations.
Each table is a named collection of rows. Each row of
a given table has the same set of named columns, and
each column is of a specific data type.
Tables are grouped into databases, and a collection of
databases managed by a single PostgreSQL server
instance constitutes a database cluster.
Concepts
9. Command for Creating a database
• $ createdb mydb
Command for deleting a database
• $ dropdb mydb
Creating a Database
10. Bundles multiple steps into a single, all-or-nothing operation.
A transaction is said to be atomic
Once a transaction is completed and acknowledged by the database system, it has indeed
been permanently recorded and won't be lost even if a crash ensues shortly thereafter.
When multiple transactions are running concurrently, each one should not be able to see
the incomplete changes made by others.
If, partway through the transaction, we decide we do not want to commit , we can issue the
command ROLLBACK instead of COMMIT, and all our updates so far will be canceled.
PostgreSQL actually treats every SQL statement as being executed within a transaction
Savepoints allow you to selectively discard parts of the transaction, while committing the
rest.
After defining a savepoint with SAVEPOINT, you can if needed roll back to the savepoint
with ROLLBACK TO.
All the transaction's database changes between defining the savepoint and rolling back to it
are discarded, but changes earlier than the savepoint are kept.
Transactions
13. PostgreSQL can be extended to support new data types
Creating a new base type requires implementing functions to operate on the type in a low-level language, usually
C.
A user-defined type must always have input and output functions.
These functions determine how the type appears in strings (for input by the user and output to the user) and how
the type is organized in memory.
Make the input and output functions inverses of each other
User-defined Types
14. PostgreSQL implements table inheritance
A table can inherit from zero or more other tables
A query can reference either all rows of a table or all rows of a table plus all of its descendant tables
Not all SQL commands are able to work on inheritance hierarchies
Inheritance
15. This is done with the EXPLAIN command
Figuring out why a statement is taking so long to execute is done with
the EXPLAIN command.
You can run this two ways; if you use EXPLAIN ANALYZE, it will actually
run the statement and let you compare what the planner thought was
going to happen with what actually did.
Note that if the statement changes data, that will also happen when
you run with EXPLAIN ANALYZE
If you just use EXPLAIN the statement doesn't do anything to the
database.
pgadmin includes a visual EXPLAIN tool that helps map out what's
actually happening.
Query Optimizer