PostgreSQL Tutorial
PostgreSQL is a free object-relational database server (ORDBMS), released under the flexible BSD license.
PostgreSQL developers pronounce it post-gress-Q-L.
PostgreSQL's slogan is "the world's most advanced open-source relational database".
References:PostgreSQL 10.1 Manual
What is a database?
A database is a repository that organizes, stores, and manages data according to a data structure.
Every database has one or more different APIs for creating, accessing, managing, searching, and replicating the stored data.
We can also store data in files, but reading and writing data in files is relatively slow.
Therefore, we now use a relational database management system (RDBMS) to store and manage large amounts of data. A so-called relational database is a database based on the relational model, which uses mathematical concepts and methods such as set algebra to process the data in the database.
ORDBMS (object-relational database system) is the product of combining object-oriented technology with traditional relational databases. Query processing is an important part of ORDBMS, and its performance directly affects the performance of the DBMS.
ORDBMS adds some new features on the basis of the original relational database.
RDBMS is a relational database management system that establishes relationships between entities, ultimately resulting in relational tables.
OODBMS (object-oriented database management system) treats all entities as objects and encapsulates these object classes; communication between objects is through messages. OODBMS object-relational databases are essentially still relational databases.
ORDBMS terminology
Before we start learning the PostgreSQL database, let's first understand some ORDBMS terminology:
- Database: A database is a collection of related tables.
- Table: A table is a matrix of data. A table in a database looks like a simple spreadsheet.
- Column: A column (data element) contains the same kind of data, for example, postal code data.
- **Row:** A row (= tuple, or record) is a set of related data, for example, a user subscription record.
- Redundancy: Storing data twice. Redundancy reduces performance but improves data security.
- Primary key: A primary key is unique. A data table can contain only one primary key. You can use the primary key to query data.
- **Foreign key:** A foreign key is used to relate two tables.
- Composite key: A composite key (combination key) uses multiple columns as an index key, generally used for composite indexes.
- **Index:** Using an index provides fast access to specific information in a database table. An index is a structure that sorts the values of one or more columns in a database table, similar to the table of contents of a book.
- Referential integrity: Referential integrity requires that a relation must not reference non-existent entities. Together with entity integrity, it is an integrity constraint that the relational model must satisfy, aiming to ensure data consistency.
PostgreSQL features
-
function: Through functions, instruction programs can be executed on the database server side.
-
Index: Users can define their own index methods, or use the built-in B-tree, hash table, and GiST indexes.
-
Triggers: A trigger is an event triggered by an SQL statement query. For example, an INSERT statement may trigger a trigger that checks data integrity. Triggers are usually triggered by INSERT or UPDATE statements.
-
Multiversion Concurrency Control:PostgreSQL uses a Multiversion Concurrency Control (MVCC, Multiversion Concurrency Control) system for concurrency control. This system provides each user with a "snapshot" of the database; every modification a user makes within a transaction is invisible to other users until the transaction is successfully committed.
-
Rule: A rule (RULE) allows a query to be rewritten, usually used to implement operations on views (VIEW), such as INSERT, UPDATE, and DELETE.
-
Data Type: Includes text, arbitrary-precision numeric arrays, JSON data, enumerated types, and XML data.
, etc. -
Full-Text Search: Via Tsearch2 or OpenFTS; Tsearch2 has been built in since version 8.3.
-
NoSQL: Native support for JSON, JSONB, XML, and HStore, as well as foreign data wrappers to NoSQL databases.
-
Data Warehouse: Can be smoothly migrated to GreenPlum, DeepGreen, HAWK, etc., which also belong to the PostgreSQL ecosystem, using FDW for ETL.
Related Resources
PostgreSQL 10.1 Manual Online Manual:http://www.runoob.com/manual/PostgreSQL/
Offline Manual - PDF Version: https://pan.baidu.com/s/1h1J14i8tzJUY3p9yyeW0mA, extraction code: xs7r。
Offline Manual - CHM Version: https://pan.baidu.com/s/1h1J14i8tzJUY3p9yyeW0mA, extraction code: tq4z。
View the latest version:https://github.com/postgres-cn/pgdoc-cn/releases