Managing Postgresql On Windows
Managing Postgresql On Windows
Outline
1. The pgAdmin III 2. Parts of the PostgreSQL system 3. Practices Creat a new application
PostgreSQL system you can do from within the pgAdmin III graphical interface Location: ~bin\pgadmin3.exe Default:
localhost
port: 5432
Add new connect: FileAdd server Connect server: right click Connect
5
10
Database Server
Database server A computer program that provides database services to other programs (client applications) that access the server via a network A database server divides a client application onto: A front end that runs on a users computer and typically performs simple tasks as displaying results and A back end that runs on the server computer and performs:
User authentication, Transaction control, Query optimization, Database access
11
Database Cluster
A database cluster is a directory on disk where all
database data will be stored (data area) Data in a cluster is stored as a collection of databases Cluster databases are managed by a single database server After initialization, a database cluster contains:
A database named postgres, A database named template1 A database named template0,
12
5 basic components
Tablespaces Databases Schemas (listed under each individual database) Group Roles Login Roles
13
Tablespaces (1/2)
Table spaces allow a DBA to define locations in
the file system where the files representing database objects can be stored Advantages of using table spaces:
If the partition or volume on which the cluster was
14
initialized runs out of space and cannot be extended, a table space can be created on a different partition and used until the system has been reconfigured Table spaces allow a DBA to optimize performance by placing mission critical database objects (like indexes) on highly reliable and fast devices
Tablespaces (2/2)
After initialization, two default tablespaces created: pg_default: the default location for all database objects pg_global: hold PostgreSQL system catalogs, containing internal Data Dictionary information When new database objects are created, you must
specify which tablespace area they are stored in Creating a new tablespace:
15
directory first postgres must have permission to write to the directory default: postgres is a normal account grand permission to directories
Databases (1/2)
The core objects in PostgreSQL Each client connection to the server can access the
data in only one database To access data in more than one database a client must make more connections The default database created during the PostgreSQL installation is postgres:
contains the default system tables for handling the internal
16
Databases (2/2)
Each database object contains 4 types of objects: Casts: control how Postgres casts from one datatype to another (NOT view in pgAmin III) Languages: these are the languages you can define stored functions, aggregates and triggers in (NOT view in pgAmin III) Schemas: the most important objects within the database, containing the tables, triggers, functions, views, and other objects for handling data Replications: define copies (or replicas) of the PostgreSQL database in a fault-tolerantboperation.
17
18
Template
CREATE DATABASE actually works by copying an
existing database Default, it copies the standard system database template1 There is a second standard system database named template0
the same data as the initial contents of template1 never be changed
19
Schemas (1/2)
The most important objects within the database A database contains one or more schemas, which
contain database object (table, data type, domain, function, trigger) definitions While users can only access objects within one database at a time, they can access all of the schemas within that database, if it has permissions Unlike databases, schemas are not rigidly separated
20
Schemas (2/2)
21
Catalogs
A PgAdmin catalog is a schema Hold meta data information and built-in Postgres
objects 2 types:
system catalog: pg_catalog
22
24
Schemas (pg_namespace) Tables, indexes, sequences, and views (pg_class), Data types (pg_type), Functions and procedures (pg_proc), Table columns (pg_attribute), Check, unique, primary key, and foreign key constraints (pg_constraint), Aggregate functions (pg_aggregate), Triggers (pg_trigger), Planner (optimizer) statistics (pg_statistics), and Many others
meta data and core schema. The information_schema is part of the ANSI standard, but is not quite so standard. Oracle and DB2 evidentally still don't support A lot of this information overlaps with information found in the information_schema and pg_catalog, but the information_schema is much easier to query Although not named explicitly in the search_path, pg_catalog is the first schema to be searched
25
Group Roles
Create access permissions for groups of users
directly to a database object, the preferred method is to use Group Roles pgAdmin III only allows you to grant Group Roles access to database objects Default, public group role:
applies to all users on the PostgreSQL system
Group Role does not appear in the pgAdmin III Group Roles listing
server Each database user should have an individual account for logging into the PostgreSQL system That account is then assigned as a member of the appropriate Group Roles that grant privileges to the database objects required Allows you to easily change access for database objects without having to touch hundreds (or even 27 thousands) of individual user Login Roles
28
Create two Group Roles Salesman Group Role: write permission on the Customer and Order, only read permission on the Product Accountant Group Role: write permission on the Product and Order, read permission on the Customer Create two Login Roles salesman - Barney 29 accountant - Fred
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Testing
log in using the test database and the fred Login Role psql test fred test=>INSERT into store."Product" VALUES
45
DATABASE MAINTENANCE
46
47
48
49
50