PostgreSQL

Скачать в pdf «PostgreSQL»


$ createdb demodbl


create database


$ psql test


Welcome to psql, the PostgreSQL Interactive terminal.


Type:    copyright for distribution terms


h for help with SQL commands ? for help on internal slash commands g or terminate with semicolon to execute query q to quit


test=> CREATE DATABASE demodb2;


CREATE DATABASE


test=> DROP DATABASE demodbl;


DROP DATABASE


test=> connect demodb2


You are now connected to database demodb2.


demodb2=> q


Figure 20.2: Examples of database creation and removal

20.3    Creating Databases


To create new databases, you run createdb from an operating system prompt. Initially, only the PostgreSQL superuser can create new databases. Other users can be given permission to create new databases.


The createdb program creates a new database by making a copy of the templatel database. This database is created when PostgreSQL is first initialized. Any modifications to templatel will appear in subsequently created databases.


Databases are removed with dropdb. The create database and drop database commands are also available in SQL.


Figure 20.2 shows one database created from the command line and another one created through psql. A database is then destroyed, and a connection made to a new database. Additional information about each command can be found in the manual pages.

20.4    Access Configuration


PostgreSQL allows administrators to control database access. Access can be granted based on the database, user, or tcp/ip network address. By default, PostgreSQL allows database access only to users logged into the computer running the database server. To enable network access, the postmaster must be started with the -i flag.

Скачать в pdf «PostgreSQL»