Post GRE

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 59

Dela Cruz, Kelvin Santos, John Paulo Maulion, Veronica Alfaro, Maricris

What is Database?

Database
A database is an organized collection of data,

today typically in digital form. The database concept has evolved since the 1960s to ease increasing difficulties in designing, building, and maintaining complex information systems. The term database is correctly applied to the data and their supporting data structures, and not to the database management system (DBMS). The database data collection with DBMS is called a database system.

PostgreSQL
The world's most advanced open source database

PostsgreSQL
Is an open source object relational database

management system (ORDBMS) which supports server side-scripting languages and data warehousing. available for many platforms including
Linux
FreeBSD Solaris Microsoft Windows Mac OS X

PostgreSQL
It is fully ACID compliant, has full support for

foreign keys, joins, views, triggers, and stored procedures (in multiple languages). It also supports storage of binary large objects, including pictures, sounds, or video. It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others,

Limit
Maximum Database Size Maximum Table Size Unlimited 32 TB

Value

Maximum Row Size


Maximum Field Size Maximum Rows per Table Maximum Columns per Table Maximum Indexes per Table

1.6 TB
1 GB Unlimited 250 - 1600 depending on column types Unlimited

History of PostgreSQL

PostgreSQL, originally called Postgres, was

created at UCB by a computer science professor named Michael Stonebraker, who went on to become the CTO of Informix Corporation. Stonebraker started Postgres in 1986 as a followup project to its predecessor, Ingres, now owned by Computer Associates. The name Postgres thus plays off of its predecessor (as in "after Ingres"). Ingres, developed from 1977 to 1985, had been an exercise in creating a database system according to classic RDBMS theory.

Postgres, developed between 1986-1994, was a

project meant to break new ground in database concepts such as exploration of "object relational" technologies. In 1995, two Ph.D. students from Stonebraker's lab, Andrew Yu and Jolly Chen, replaced Postgres' POSTQUEL query language with an extended subset of SQL. They renamed the system to Postgres95. In 1996, Postgres95 departed from academia and started a new life in the open source world when a group of dedicated developers outside of Berkeley saw the promise of the system, and devoted themselves to its continued

PostgreSQL began at version 6.0, giving credit to

its many years of prior development.


Multiversion Concurrency Control (MVCC) Important SQL features. Improved built-in types. Speed.

Features of PostgreSQL

Procedural languages

Inheritance

Indexes
Triggers Schemas Multiversion

Replication
Asynchronous

Concurrency Control (MVCC) Rules Data types User-defined objects

notifications Security Contrib modules Foreign data wrappers Other features Add-ons Upcoming features

Procedural languages
Procedural languages (often called stored

procedures) allow blocks of code to be executed by the database server, and can be written in programming languages other than SQL and C.

Indexes
PostgreSQL includes built-in support for B+-

tree, hash, generalized search trees (GiST) and generalized inverted indexes (GIN).

Triggers
Triggers are events triggered by the action of

SQL DML statements.

Schemas
In PostgreSQL, all objects (with the exception of

roles and tablespaces) are held within a schema. Schemas effectively act like namespaces, allowing objects of the same name to co-exist in the same database.

Multiversion Concurrency Control (MVCC)


PostgreSQL manages concurrency through a

system called MVCC, which gives each transaction a "snapshot" of the database, allowing changes to be made without being visible to other transactions until the changes are committed.

Rules
Rules allow the "query tree" of an incoming query

to be rewritten. One common usage is to implement views, including updatable views. Rules, or more properly, "Query Re-Write Rules", are attached to a table/class and "Re-Write" the incoming DML (select, insert, update, and/or delete) into one or more queries that either replace the original DML statement or execute in addition to it.

Data types

A wide variety of native data types are supported, including: Boolean Arbitrary precision numerics Character (text, varchar, char) Binary Date/time (timestamp/time with/without timezone, date, interval) Money Enum Bit strings

Text search type Composite Arrays (variable length

and can be of any data type, including text and composite types) up to 1 GB in total storage size. Geometric primitives IPv4 and IPv6 addresses CIDR blocks and MAC addresses XML supporting XPath qu eries (as of 8.3) UUID (as of 8.3)

User-defined objects
New types of almost all objects inside the

database can be created, including:


Casts Conversions Data types

Domains
Functions, including aggregate functions and

window functions Indexes including custom indexes for custom types Operators (existing ones can be overloaded) Procedural languages

Inheritance
Tables can be set to inherit their characteristics

from a "parent" table.

Security
Internal
Security within the

External
PostgreSQL natively supports a broad number of authentication mechanisms including:

database is managed on a per-role-basis. A role is generally regarded to be a user (a role that can log in), or a group (a role which other roles are members of). Permissions can be granted or revoked on any object down to the column level, and can also allow/prevent the creation of new objects at the database, schema or table levels.

trust (no enforcement) password (either MD5 or plain-text) GSSAPI SSPI Kerberos ident (maps O/S user name as provided by an ident server to database user name) peer (maps local user name to database user name) LDAP RADIUS Certificate

Foreign Data Wrappers


These can take the form of any data source,

such as a file system, another RDBMS, or a web service.

Add-ons
ST-Links SpatialKit Postgres PostGIS pgRouting Performance Wizard

MySQL migration wizard


MADlib

Installation

Requirement
(for building visual studio 2005 beyond) ActiveState Perl

ActiveState TCL Bison and Flex Diff Gettext Microsoft Platform SDK MIT Kerberos libxml2 and libxslt openssl ossp-uuid Python zlib

Building
To build all of PostgreSQL in release

configuration (the default), run the command:


Build

To build all of PostgreSQL in debug configuration,

run the command:


build DEBUG

To build just a single project, for example psql,

run the commands:


build psql build DEBUG psql

To change the default build configuration to

debug, put the following in the buildenv.pl file:

$ENV{CONFIG}="Debug";

It is also possible to build from inside the Visual

Studio GUI. In this case, you need to run:

perl mkvcbuild.pl

Cleaning and installing


By default, all files are written into a subdirectory

of the debug or release directories. To install these files using the standard layout, and also generate the files required to initialize and use the database, run the command:

perl install.pl c:\destination\directory

Running the regression tests


To run the regression tests, make sure you have

completed the build of all required parts first. To run the tests, run one of the following commands from thesrc\tools\msvc directory: vcregress check vcregress installcheck vcregress plcheck vcregress contribcheck

To change the schedule used (default is the

parallel), append it to the command line like:

vcregress check serial

PostgresSQL Commands

ABORT -- abort the current transaction ALTER DATABASE -- change a database ALTER GROUP -- add users to a group or remove users from a group ALTER TABLE -- change the definition of a table ALTER TRIGGER -- change the definition of a trigger ALTER USER -- change a database user account ANALYZE -- collect statistics about a database BEGIN -- start a transaction block CHECKPOINT -- force a transaction log checkpoint CLOSE -- close a cursor CLUSTER -- cluster a table according to an index COMMENT -- define or change the comment of an object COMMIT -- commit the current transaction COPY -- copy data between files and tables CREATE AGGREGATE -- define a new aggregate function CREATE CAST -- define a user-defined cast CREATE CONSTRAINT TRIGGER -- define a new constraint trigger CREATE CONVERSION -- define a user-defined encoding conversion

CREATE DATABASE -- create a new database CREATE DOMAIN -- define a new domain CREATE FUNCTION -- define a new function CREATE GROUP -- define a new user group CREATE INDEX -- define a new index CREATE LANGUAGE -- define a new procedural language CREATE OPERATOR -- define a new operator CREATE OPERATOR CLASS -- define a new operator class for indexes CREATE RULE -- define a new rewrite rule CREATE SCHEMA -- define a new schema CREATE SEQUENCE -- define a new sequence generator CREATE TABLE -- define a new table CREATE TABLE AS -- create a new table from the results of a query CREATE TRIGGER -- define a new trigger CREATE TYPE -- define a new data type CREATE USER -- define a new database user account CREATE VIEW -- define a new view

DEALLOCATE -- remove a prepared query DECLARE -- define a cursor

DELETE -- delete rows of a table


DROP AGGREGATE -- remove a user-defined aggregate function DROP CAST -- remove a user-defined cast DROP CONVERSION -- remove a user-defined conversion DROP DATABASE -- remove a database

DROP DOMAIN -- remove a user-defined domain


DROP FUNCTION -- remove a user-defined function DROP GROUP -- remove a user group DROP INDEX -- remove an index DROP LANGUAGE -- remove a user-defined procedural language

DROP OPERATOR -- remove a user-defined operator


DROP OPERATOR CLASS -- remove a user-defined operator class DROP RULE -- remove a rewrite rule

DROP SCHEMA -- remove a schema DROP SEQUENCE -- remove a sequence DROP TABLE -- remove a table DROP TRIGGER -- remove a trigger DROP TYPE -- remove a user-defined data type DROP USER -- remove a database user account DROP VIEW -- remove a view END -- commit the current transaction EXECUTE -- execute a prepared query EXPLAIN -- show the execution plan of a statement FETCH -- retrieve rows from a table using a cursor GRANT -- define access privileges INSERT -- create new rows in a table

LISTEN -- listen for a notification LOAD -- load or reload a shared library file LOCK -- explicitly lock a table MOVE -- position a cursor on a specified row of a table NOTIFY -- generate a notification PREPARE -- create a prepared query REINDEX -- rebuild corrupted indexes RESET -- restore the value of a run-time parameter to a

default value REVOKE -- remove access privileges ROLLBACK -- abort the current transaction SELECT -- retrieve rows from a table or view SELECT INTO -- create a new table from the results of a query

SET -- change a run-time parameter SET CONSTRAINTS -- set the constraint mode of the

current transaction SET SESSION AUTHORIZATION -- set the session user identifier and the current user identifier of the current session SET TRANSACTION -- set the characteristics of the current transaction SHOW -- show the value of a run-time parameter START TRANSACTION -- start a transaction block TRUNCATE -- empty a table UNLISTEN -- stop listening for a notification UPDATE -- update rows of a table VACUUM -- garbage-collect and optionally analyze a database

Advanced PostgreSQL Commands

How to find the largest table in the postgreSQL database?

If you want only the first biggest table in the postgres

database then append the above query with limit as:

relname name of the relation/table. relpages - relation pages ( number of pages, by

default a page is 8kb ) pg_class system table, which maintains the details of relations limit 1 limits the output to display only one row.

How to calculate postgreSQL database size in disk ?


pg_database_size is the function which gives

the size of mentioned database. It shows the size in bytes.

Note: If you want it to be shown pretty, then use pg_size_pretty function which converts the size in bytes to human understandable format.

How to calculate postgreSQL table size in disk ?

How to find size of the postgreSQL table ( not including index )

How to view the indexes of an existing postgreSQL table ?

Use pg_attribute command to view two or three indexes

How to count total number of rows in a postgreSQL table ?

How to view the basic available datatypes in postgreSQL ?

Storing the password after encryption.

Practical PostgreSQL Database Administration Commands

How to change PostgreSQL root user password ?

How to setup PostgreSQL SysV startup script?

How to check whether PostgreSQL server is up and running?

How to start, stop and restart PostgreSQL database?

How do I find out what version of PostgreSQL I am running?

How to create a PostgreSQL Database?

You might also like