���� ���������� ����������: ������� 30 ��� 22:24:56 EDT 2003
���������� ������� ������������: ���� ������ (Bruce Momjian) (pgman@candle.pha.pa.us)
������� �� �������: ������ ���������� (victor_v@permonline.ru)
����� ������ ���������� ������ ��������� ����� ����� �� http://www.PostgreSQL.org/docs/faqs/FAQ.html.
������ �� ������� ����������� ��� ���������� �������� ����� ����� �� http://www.PostgreSQL.org/docs/index.html.
IN
��� �������� ���������?PostgreSQL ������������ Post-Gres-Q-L (����-����-���-��).
PostgreSQL - ��� ���������� ���� POSTGRES, ����������������� �������� ������ ��������� ����. PostgreSQL ������������ ��������� ������ ������ ������ � �������� ���������� ����� POSTGRES, � �������� ���� �������� PostQuel �� ����������� ������������ SQL. PostgreSQL - ��� ��������� � ��������� �������� ����������� �����������.
���������� PostgreSQL ��������� ������� �������������, ��� ��������� ������� ��������� �� ������ �������� �������������. � ��������� �����, �� ������������� �������� ���� ������ (Marc G. Fournier) (scrappy@PostgreSQL.org). (��. ������ 1.6 � ���, ��� ������������ � ����������). ��� ������� ������ �������� �� ��� ���������� PostgreSQL.
�������� PostgreSQL 1.01 �������� ����� � (Andrew Yu) � ����� ��� (Jolly Chen). ������ ������ ������ ���� ����� � ������� �� ������ ���������, ������������, ������� � ���������� ����� ����. �������������� ��� Postgres, �� �������� �������� PostgreSQL, ��� ������ ������ ������ ������������� ���������, ��������������� ��������� � ��������� ������ �������������, ���������� ��� ������������ ���������� ������ ������������� (Michael Stonebraker) � �������������� ������������, ������.
�������������� ���, ������ � ������, ���� Postgres. ����� � 1995 ���� ���� ��������� ���������������� SQL, ��� ��� ���� �������� �� Postgres95. �� � ��� ��� ���� �������� � ����� 1996 �� PostgreSQL.
PostgreSQL �������� ��� �������� ���������� COPYRIGHT:
������� ���������� ������ ������ PostgreSQL
Portion copyright (c) 1996-2002, PostgreSQL Global Development Group Portions Copyright (c) 1994-6 Regents of the University of California
��������������� ����� �� �������������, �����������, ��������� � ��������������� ������� ������������ ����������� � ��� ������������ ��� ����� �����, ��������� � ��� ���������� ������-���� ����������, ��� ������� ��� ��� ������ ����� ����� ������������� ������ ���� ��������� �� ��������� ������, ������� �������� � ��� ��������� ���������.
�������������� ����������� �� ����� ������� ��������������� �� ����� �����������, ������� ������ ������, ���������� ������ ��� ��������, ����������� ��� ��������� �������������� ������� ������������ ����������� ��� ��� ������������, ���� ���� �������������� ����������� ��� ������� � ����������� ����� �����������.
�������������� ����������� ���������� ���������������� ������������� ����� ��������, �������, �� �� ������������� ������ ����� ����������: ������� �������� ����������� ������ ��� ����������� ��� ��������� ����. ������ ����������� ����������� ��������������� �� ������ ������� "��� ����" � �������������� ����������� �� ������ ������������� �������������, ���������, ����������, ���������� ��� ���������.
�������������� �������� BSD ���������, ������������ ��������� ������������ ����������� � �������� �����. ��� �������� �� ����������� ����������� �� ������������� ��������� ����. ��� �������� ��� �������� � �� �� ���������� ţ ������.
������, PostgreSQL ����� �������� �� ����� ����������� ��������� ����������� � Unix. � ���������� �� ���������, �� ������� ������ ��� ��������, �� ������� ���� ��������� �������� ������� PostgreSQL � ������� ������ ������ ������.
������
��� ������� �� ���������� MS Windows �������� ���������� C ���������� libpq, psql, ������ ���������� � ���������� ����������. � ���� ������, ������ ����������� �� MS Windows � ����������� �� TCP/IP � ��������, ���������� �� ����� �� �������������� Unix ��������. � ����������� ���������� ���� win32.mak ��� ����, ����� ����� ���� �������� ������ ���������� libpq � psql ��� Win32. PostgreSQL ����� �������� ����� ODBC.
������
������ �� ����� ���� ������� �� Windows NT � Win2k, ��������� ���������� Cygwin, ������������� ��������� Cygnus ��� �������� ������������ ����������� Unix � NT. �������� pgsql/doc/FAQ_MSWIN � ������������ ��� MS Windows FAQ �� http://www.PostgreSQL.org/docs/faqs/text/FAQ_MSWIN.
PostgreSQL, �������������� ���������� ��� MS Win NT/2000/XP � ��������� ������ ����� ��������. ����������� �������� ��������� PostgreSQL ��� Windows �������� �� http://techdocs.postgresql.org/guides/Windows.
����� ���������� ������ �������������� ��� Novell Netware 6 �� http://forge.novell.com.
��������, ���������������� ��������� �������� �� ftp ���� PostgreSQL ftp://ftp.PostgreSQL.org/pub. ������ ������ �� ������� �� ����� �������� �����.
�������� ������ ��������: pgsql-general@PostgreSQL.org. � ��� ����� ��������� ����� ����, ���������� PostgreSQL. ����� �����������, ��������� ������ �� ����������� �����, � ������� � ���� ������ (�� � ����) �������� ��������� ������:
subscribe end
�� ����� pgsql-general-request@PostgreSQL.org.
���������� ������� ������. ����� ����������� �� ����, ��������� ������ �� ����������� ����� �� �����: pgsql-general-digest-request@PostgreSQL.org � � ���� ������ �������� ������� �������:
subscribe end�������� ������������ �����������, ����� � �������� ������ �������� ��������� ����� 30 �������� ���������.
�������� � ������ �������� ��������� �� �������. ����� ����������� �� ���� ������, ��������� �� ����������� ����� ������ �� ����� pgsql-bugs-request@PostgreSQL.org � � ���� ������ �������� ������� �������:
subscribe end����� ������� ������ �������� � ����������� �������������. ����� ����������� �� ���� ������, ��������� �� ����������� ����� ������ �� ����� pgsql-hackers-request@PostgreSQL.org � � ���� ������ �������� ������� �������:
subscribe end
�������������� ������ �������� � ��������� � PostgreSQL ����� ����� �� �������� ��������� PostgreSQL �� ������:
http://www.PostgreSQL.org
��� ���������� IRC ����� �� EFNet � OpenProjects, � ���������
#PostgreSQL. � ��������� ��� ����������� � ����� ������ ������� Unix
irc -c '#PostgreSQL' "$USER" irc.phoenix.net.
������ ������������ ��������� �������� �������� �� http://www.ca.PostgreSQL.org/users-lounge/commercial-support.html.
��������� ������ PostgreSQL - ��� ������ 7.3.2.
�� ��������� ��������� ����� ������ ������ ������ ������.
� ����������� ���������� ��������� �����������, �������� ������������ ����������� man � ��������� ��������� �������� �������. �������� � ������� /doc. �� ����� ������ ������������� ������������ � �������� �� ������ http://www.PostgreSQL.org/docs.
���������� ��� ����� �� PostgreSQL ��������� �� ������� http://www.PostgreSQL.org/docs/awbook.html � http://www.commandprompt.com/ppbook/. ������ ���� �� PostgreSQL, ������� ����� ������ �������� �� ������ http://www.ca.PostgreSQL.org/books/. ����� ����, �� ������ http://techdocs.PostgreSQL.org/ �� ������ ����� ��������� ����������� ������ ����������� PostgreSQL.
psql ����� ��������� ���������� ������ \d ��� ����������� ���������� �� �����, ����������, ��������, ��������� � �.�.
��� ���� �������� ��� ������ ����������.
PostgreSQL ������������ ����������� �������� SQL-92. �������� ��� ������ TODO �� ������� ��������� ������, ������������� ������������ � ������� ������.
����� �� PostgreSQL �� http://www.PostgreSQL.org/docs/awbook.html ������ SQL. ���������� ������ ����� �� PostgreSQL �� http://www.commandprompt.com/ppbook. ���� ���������� ������� �� http://www.intermedia.net/support/sql/sqltut.shtm, �� http://ourworld.compuserve.com/homepages/graeme_birchall/HTM_COOK.HTM, � �� http://sqlcourse.com.
��� ���� ������� - ��� ����� "Teach Yourself SQL in 21 Days, Second Edition" (����� �������������� SQL �� 21 ����, ������ ��������) �� http://members.tripod.com/er4ebus/sql/index.htm
������ �� ����� ������������� �������� ����� The Practical SQL Handbook, Bowman, Judith S., et al., Addison-Wesley. ������ �������� The Complete Reference SQL, Groff et al., McGraw-Hill.
��, �� ����� �������� � ������ ����� 2000 ���� � ����� 2000 �����.
��� ������, �������� ��������� ������ �������� ������� � �������� ������������ ������������� PostgreSQL �� ����� ����� ��� � ������������. �����, ����������� �� ������ �������� pgsql-hackers � pgsql-patches. �����, ����������� ����������� (patches) �������� �������� � ������ pgsql-patches.
���������� ������������ ������ �����, ������� ����� ���������� ������� ��������� � CVS ����� PostgreSQL. ������ �� ���� ����� � ���� ����� �������� ��� ����� ������������������ �����������, ��� �� ���� ���������� �������� ��� �������� � ��� ���� ��������� ���������� ������� ���������, � �� �������, ��� �� �����������, ������� ��� ������ ����� �������� ��������.
���������� �������� ��������� PostgreSQL BugTool �� http://www.PostgreSQL.org/bugs/bugs.php, �� ������� ������������� ��������� ���������� � ��� ��� ��������� ��������� �� ������.
����� �� �������� ���������� �� ftp://ftp.PostgreSQL.org/pub �� ������� ����� ������ ������ PostgreSQL ��� ������.
���������� ��������� ������� ��������� ������������ �����������: �����������, ������������������, ����������, ��������� � ����.
PostgreSQL ����� ������������ �������������� � ���� ������ ������� ��� �� ������ ���������� � 1996 ����. �� ������ ����������� �� ��� ����� ����� (Marc Fournier), ������� ������ ��� �������������� � ��������� �� �� ���������� ���� ���.
������������ �������������� ����� ����� ��� �������� � �������� �������� �����. ��� ������������� �������, ������� ����� ������ ��������� �������������� �������� �������.
����������, ��� �������������� �� �������� �������. ���������� ��������� ���������� ����������� � ����������� ��������, ������� ������� �����. ���� �� ��� ���� �������� ����� ������, ������� ����� �������� � ������ ����� �������, ���������� �������� ��������� https://store.pgsql.com/shopping/ � �������� ���� �����.
���� �� ��������� ��������� � PostgreSQL, Inc, ����� "contributions" ������������ ������������� ��� ��������� ������� PostgreSQL � �� ���������� �����-���� ���������� ��������. ���� ������, �� ������ ��� ���������, ������� ������ �� ���������� �����.
���������� ��� ODBC ��������, PsqlODBC � OpenLink ODBC.
�� ������ ������� PsqlODBC � http://gborg.postgresql.org/project/psqlodbc/projdisplay.php.
OpenLink ODBC ����� ����� �� http://www.openlinksw.com. ���� ������� �������� � �� ����������� ���������� ����������� ������������, ������������ ODBC, � ����� �������, ODBC �������� ��� PostgreSQL �������� ��� ������ �� �������������� ��� �������� (Win, Mac, Unix, VMS).
�������� ��� ����� ��������� ���� ������� ��� ���� ����� ������������ ���������, �� ���������� ������ ������ ����� ��������. ����������, ����������� ������� �� ����� postgres95@openlink.co.uk.
���������� �������� �� �������������� ��� ������ � Web ����� ����� ��: http://www.webreview.com
��� ���������� � Web, ����� �� ������������ ������������ �������� PHP. �������� �������� http://www.php.net.
��� ����������� �������, ������ ���������� Perl ����������� � CGI.pm ��� mod_perl.
��, ���������� ��������� ����������� ����������� ��� PostgreSQL. ��� PgAccess (http://www.pgaccess.org, PgAdmin II (http://www.pgadmin.org, Win32-only), RHDB Admin ( http://sources.redhat.com/rhdb/) � Rekall ( http://www.thekompany.com/products/rekall/, ������������). ����� ���� PHPPgAdmin ( http://phppgadmin.sourceforge.net/) - ��������� � PostgreSQL, ���������� �� Web.
�����-���� ���������� ��� PostgreSQL ���������� ��� ����������� ���������� ������ ����������������. ���������� ������ ������� ���������� ��� ��� ������ ����������������, �������� �� �����������.
��������� ���������� ���������� � ����������� PostgreSQL:
�������������� ���������� �������� �� ������ http://gborg.PostgreSQL.org � ������ Drivers/Interfaces.
������� ����� --prefix ����� ���������� configure.
��� ����� ���� ������� ������� ����������, �� ������, ��� ����� ������� - ��� ��������� � ���, ��� � ����� ���� ����������� ���������� System V. PostgreSQL �������, ����� ���� ������������ ����������� ������ � ��������.
���� � ��� � ���� ������������ ��������� ����������� ������, ���� ������ ���� ����� ������� ���������� ��������� ����������� ������. �� ���������� ��������, ������� ��� ����� ���������� ������� �� ����������� ����� ������ � �� ���� ��� ����� ������� � backend ��������� �� ��������� ��� postmaster. ��� ����������� ������, � ����������� ������� � ��������� �� ���������, ����������� ������� - ��� ����� 1 ���������. ����������� � ����������� ������ � ��������� �������� � ����������� �������������� PostgreSQL.
���� ��� ��������� IpcSemaphoreCreate: semget failed (No space left on device) �� ��������� ������ ���� ������, ��� ��� �� ������� ���������. Postgres ������� ���� ������� �� ������������� backend �������. ��������� �������� �������� ������ postmaster � ����������� �� ������� ���������� backend ���������. ����������� -N � ��������� ������� ��� 32, ������� ������� �� ���������. ����� ���������� ������� - ��� ��������� �������� SEMMNS � SEMMNI � ��������� ����.
����������� �������� ����� ����� �������� � ������� ���� �� ����� ������� � ���� ������.
���� �� �������� �����-���� ������ ��������� �� ������, �� ������ ��������, ��� � ����� ���� ������ �� ��������� ��������� ���������. �������� ����������� � ����������� ������ � ��������� � ����������� �������������� PostgreSQL.
�� ���������, PostgreSQL ��������� ������ ���������� �� ��������� ������ ����� ������ ������ Unix. ������ ������ �� ������ ������������ � ���� ���� ��� postmaster �� ����� ����� ���� -i � ���� �� ����� ��������� host-����������� � ����� $PGDATA/pg_hba.conf. ��� �������� ������ ���������� TCP/IP ����������.
����������, ������� ����� ��������� �������� ���������� ��������. ������� EXPLAIN ��������� ��� ���������� ��� PostgreSQL �������������� ��� ������ � ����� ������� ������������.
���� �� ���������� ����� ���������� INSERT, ����������� ����������� ��������� �� � ������� �����, ��������� ������� COPY. ��� ����������� �������, ��� ��������� INSERT. ��-������, ��������� ��� ����� ���������� BEGIN WORK/COMMIT ���� ��������� ����������. ��������� ��� ����������� ���������� ���������� � ����� ����� ����������. ��� �������� ���������� ����������. �����, ����������� ��� ��������� � ������������� ��������, ����� �� ���������� ������� ��������� ������.
���������� ��������� ����� ���������. �� ������ ��������� fsync() ��� ������ postmaster � ������ -o -F. ��� ������������ ������ fsync(), ������� �������� � ������ ������ �� ���� ����� ������ ����������.
�� ������ ����� ������������ ��� postmaster ����� -B ��� ���������� ���������� ������� ����������� ������, ������� ������������ backend ����������. ���� �� �������� �������� ����� ��������� ������� �������, �� postmaster ����� �� ���������� ������ ��� �� ���������� ����������� ���� �� ����� ����������� ������. ������ ����� ����� ������ � 8 �������� � �� ��������� ���������� 64 ������.
�� ������ ����� ������������ backend ����� -S ��� ���������� ������������� ���������� ������, ������� ������������ backend ��������� ��� ��������� ����������. �������� ��� ����� -S �������� � ���������� � �� ��������� ����� 512 (�.�. 512K).
�� ����� ������ ������������ ������� CLUSTER ��� ����������� ������ � �������� �� ����������� ������. ����������� �������� �� �������� ����������� �� ������� CLUSTER.
PostgreSQL ����� ��������� ������������, ����������� �������� ���������� � ���������, ������� ����� ���� ������������ � ���������� �����.
��-������, ��� ������� configure � ������ --enable-cassert, ������ ������ assert() ��������� ����������� ������ backend �������� � ��������� ��������� ��� ������������� �����-���� ��������������.
� postmaster, � postgres ����� ��������� ���������� �����. ��-������, ��� ������� postmaster, ���������, ��� ����������� ����� � ����� ������ �������������� � ���� �������:
cd /usr/local/pgsql ./bin/postmaster >server.log 2>&1 &
��� �������� � ��������� ����� server.log � ������� �������� PostgreSQL. ���� ���� �������� �������� ���������� � ��������� ��� �������, ��������� �� �������. Postmaster ����� ����� -d, ������� ��������� �������� ��� ���������������� ����� ��������� ���������. ��� ����� -d ����������� �����, ������� ������ ������� �������. ������ ���������, ��� ��� ������� ������� ������� �������� � ��������� ������ ������� �������� �������.
���� postmaster �� �������, �� ������ ��������� postgres backend �� ��������� ������ � ������ ��� �������� SQL ��������. ��� ������������� ������ ��� ����� �������. �������, ��� � ���� ������, ������ ����������� �������� ����� ������, � �� ������ � �������. ���� �� ����������� ���������� � ����������� ����������, �� ������ ������������ ����� ��������, ����� ����������, ��� ���������. ��������� backend ����������� �� �� postmaster, �� �� ����������� � ���������� ��������� � ������ �������� �������� ����������/backend �� ����� ���� ��������������.
���� postmaster �������, ��������� psql � ����� ����, ����� ������� PID �������� postgres, ������������ psql. ����������� �������� ��� ����������� � postgres PID. �� ������ ���������� ����� ���������� � ��������� � ��������� ������ �� psql. ���� �� ����������� ������� ������� postgres, �� ������ ���������� PGOPTIONS="-W n", � ����� ��������� psql. ��� ����� �������� � �������� �������� ������� �� n ������, � ������� ������� �� ������ ���������� � �������� ��������, ���������� ����� ����� ���������� � ���������� ������.
��������� postgres ����� ����� -s, -A, � -t ������� ����� ���� ����� ��������� ��� ������� � ��������� ������������������.
�� ����� ������ �������������� PostgreSQL � ��������������� ��� ����, ����� ������� ����� ������� ������� ������� �����������. ����� �������������� backend'� ��������� � �������� pgsql/data/base/dbname. ���� �������������� ������� ����� ������� � ������� ������� �������. � Linux ��� ���������� �������������� ��������� ���������� � -DLINUX_PROFILE.
��� ����� ��������� ����������� �� ���������� ����������� backend ��������� ��� ������� postmaster.
�� ��������� ���������� ����� �� 32 ��������. �� ������ ��������� ���� ����� ������������ postmaster � ������ ��������� ���������, ������� ����������� � ����� -N ��� ������� ���� postgresql.conf.
�������, ��� ���� �� �������� � ����� -N �������� ������ 32, �� �� ����� ������ ��������� �������� � ����� -B ������� �� ��������� ����������� � 64; �������� ����� -B ������ ���� �� ������� ���� ����� ������ �������� ����� -N, � �������� �ݣ ������ ��� ������ ������������������. ��� �������� ���������� backend ���������, ��� ����� ������� ���� �� ��������� ��������� ��������� ���� Unix. ��� ����� ���������, ��� ������������ ���������� ������ ����������� ������, SHMMAX; ������������ ���������� ���������, SEMMNS � SEMMNI; ������������ ���������� ���������, NPROC; ������������ ���������� ��������� �� ������������, MAXUPRC; � ������������ ���������� �������� ������, NFILE � NINODE. ������� �������� ����������� �� ���������� backend ��������� ��� ��� � ������� � ���, ����� ����� ������� ������� ��������.
������ ������� �������� ��������� �����, ������������ ������������ �������. ��������, ���� ��� ���������� ORDER BY ����� ���������� � ��� ���������� ������� ������ ������, ��� ��������� �������� -S � backend'�, �� ��� �������� �������������� ������ ��������� ��������� �����.
��� ��������� ����� ������ ��������� �������������, �� ����� ����� �� ���������, ���� backend ������ �� ����� ����������. ������� � ������ ���������� �������� ��������� �� �������� �� ��������.
������������ PostgreSQL ������ ������ ��������� ��������� ����� ������������. ����� ������� ���������� � ������ 7.2 �� 7.2.1 �� ������� ���������� dump � restore. ������ ��� ������ ���������� ������� (�.�. ��� ���������� ��������, � 7.2 �� 7.3) ����� �������� ���������� ������ ��������� ������ � ������ ������. ��� ��������� ����� ����� ����������� ��������, ��� ��� ��� ����������� ���������� �������� ������������� ������ ������. ��������� dump ��������� �������� ������ � ����� �������, ������� ����� ����� ���� �������� ��� ������������� ������ ����������� �������.
� ��� ��������, ��� ������ ������ �� ����� �� ��������, ��� ���������� ���������� ����� ���� ����������� �������� pg_upgrade ��� ������������� dump/restore. ����������� � ������� ������� ����� ����� ������������ pg_upgrade ��� ����� �������.
�������� �������� �� ��������� ����������� ����������� DECLARE.
�������� ������� ����������� ����������� FETCH ��� ����������� SELECT ... LIMIT....
���� ���� �� ������ �������� ������ ������ ��������� �������, ����� �������� ���� ������. ���������� ������, ������� ����� ORDER BY. ���� ���� �����-���� ������, ������� ��������� � ORDER BY, PostgreSQL ����� ������ ������ ��������� ������ ����������� ������� ��� ����� ��������� ������ ���� �� ����� ������ �������� ������.
To SELECT a random row, use:
SELECT col FROM tab ORDER BY random() LIMIT 1;
�� ������ ���������� �������� ��� psql � ����� pgsql/src/bin/psql/describe.c. �� �������� ������� SQL ������� ������������ ��� ����� � psql ������, ������������ � �������� ����� �����. �� ����� ������� ��������� psql � ������ -E ���, ����� ��� ��������� �������� �������, ������� ��� ���������� ��� ���������� �������� ���� ������.
DROP COLUMN ���������������� ���� ��������� � ������ 7.3 � ���������� ALTER TABLE DROP COLUMN. � ������ �������, ����� ������� ���:
BEGIN; LOCK TABLE old_table; SELECT ... -- ������� ���� ������� �� ����������� ���, ������� ������ ������� INTO TABLE new_table FROM old_table; DROP TABLE old_table; ALTER TABLE new_table RENAME TO old_table; COMMIT;
��� ��������� ���� ������ �������, �������� ���:
BEGIN; ALTER TABLE tab ADD COLUMN new_col new_data_type; UPDATE tab SET new_col = CAST(old_col AS new_data_type); ALTER TABLE DROP COLUMN old_col; COMMIT;
���������� ��������� �����������:
������������ ������ ����? ����������� (���������� ���� �� 4 TB) ������������ ������ �������? 16 TB ������������ ������ ������? 1.6 TB ������������ ������ ����? 1 GB ������������ ���������� ������� � �������? ������������ ������������ ���������� ������� � �������? 250-1600 � ����������� �� ���� ������������ ���������� �������� � �������? ����������������������, ������� "������������" �� ����� ���� �������������� ��������� �������� �������������� � ��������� ������/���������. ����� �������� ������������� ���� ����������� �������, ����� ���������� ������������������.
������������ ������ ������� � 16 TB �� ������� ����� ������������ ������� ������������ ����� ������� ��������. ������� ������� �������� ��� ��������� ������ �������� � 1 GB, ��� ��� �����������, ������� ����������� �������� ������� �� �����.
������������ ������ ������� � ������������ ���������� ������� ����� ���� ���������, ���� ������ ����� �� ��������� ����� �������� �� 32k.
���� PostgreSQL ����� ������������� ��������� ������������ �� 5 ��� ������ ��� ���������� ������ �� �������� ���������� �����.
� �������� �������, ���������� ���� � 100,000 ����� � ������, �� ������� ����� ����� � ��������� ��������. ��� ���� ����� ������, � �������, ���������� 20 ����. ������ �������� ����� �������� 2.8 MB. ������ ���� PostgreSQL, ���������� ��� �� ������ �������� �������������� 6.4 MB �� �������:
36 ����: �� ������ ��������� ������ (��������������) + 24 �����: ���� ���� � ������������� ����� � ���� ��������� ���� + 4 �����: ��������� �� �������� ��� ���� ������ ---------------------------------------- 64 ���� �� ������ ������ �������� ������ � PostgreSQL ���������� 8192 ���� (8 KB), ��� ���: 8192 ���� �� �������� ------------------- = 128 ������� �� �������� �� (� �����������) 64 ���� �� ������ 100000 ����� ������ -------------------- = 782 �������� � �� 128 ������� �� �������� 782 �������� �� * 8192 ���� �� �������� = 6,406,144 ���� (6.4 MB)
������� �� ������� ��� �����, �� ��������� ��� ��������� ��� �������� ���������� ������, ��� ����� ����� ���� ������.
�������� NULL ����������� � ����� � ������� ��� �������� ����� ���� �����.
psql ����� ��������� ������, ������������ � �������� ����� �����, ��� ���� ����� ������������� ����� ����������. ����������� \? ��� ����, ����� ������� ��� �������. ����� ���������� ��������� �������, ��� ������� ���������� �� pg_ � � ������� ����� ���������� ��� ����������. �ݣ, psql -l ������� ������ ���� ��� ������.
����� �������� ���� pgsql/src/tutorial/syscat.source. � ��� ������������ ������ ��������� SELECT ������� ����� ��� ��������� ���������� �� ��������� ������ ���� ������.
������� �� ������������ ��� ������� ������� �������������. ��� ������������ ������ ���� ������� ������ ������������ ������� � ������ �������� ������ ��������� ������� ������� � �������. ��� ��������, ������ ��� ������ � ����� � ����������� ������������ ��� ������������ �������� ����� ���� ���������, ��� ������� ������ ������� ��� �� ���������������� ������������.
����� ���������� ������������� ������������� ������� ��� �����-���� �������, PostgreSQL ������ ����� ���������� �� ���� �������. ��� ���������� ���������� ��� ������������� VACUUM ANALYZE ��� ������ ANALYZE. ��������� ����������, ����������� ������ � ��� ��� ����� ������� � ������� � ���� �� ������ ������������ �������, �� �� ����� ��������� ������ �������. ���������� ����� ������ �� ����������� ������������ ������� ���������� � ������ ����������. ���� ���������� ������ ������������ ���������� ��� ��������� ����������� �������.
������ ������� �� ������������ ��� ORDER BY ��� ��� ���������� ����������. ���������������� ������� ��������� �� ����� ����������� ������ �������, ��� ����� �� �������� � ������� �������. ������, ORDER BY ����� ������������� � LIMIT � � ���� ������ ������ ����� ��������������, ��������� ��� ���������� ����� ������������ ��������� ����� �������. ���������� MAX() � MIN() �� ���������� �������, �� ������ ������������ ��� ���������� �������� � ORDER BY � LIMIT:
SELECT col FROM tab ORDER BY col [ DESC ] LIMIT 1;
���� ��� �������, ��� ����������� ���������� �������� ����������������
�������, ����������� SET enable_seqscan TO 'off'
�
��������� �����, ����� �������, �� �����-�� ������������ �������� �������.
����� ������������ �������� � ���������, �������� LIKE ��� ~, ������� ����� ���� ������������ � ��������� �������:
�������� �������� ����������� ����������� EXPLAIN.
R-tree ������ ������������ ��� �������������� ���������������� ������. ������ ���� �� ����� ��������� �������� ���������. B-tree ������ ��������� ������ �������� ��������� � ����� ���������. R-tree ������ ����� ��������� ��������������� �������. ��������, ���� R-tree ������ ����� ���� ������� � ������� ���� point, �� ������� ����� ����� ���������� �������� �� ������ ���� "������� ��� ����� ������ ��������� ����������������."
������������ ��������, ����������� �������������� �������� R-tree ���:
Guttman, A. "R-trees: A Dynamic Index Structure for Spatial Searching." Proceedings of the 1984 ACM SIGMOD Int'l Conf on Mgmt of Data, 45-57.
�� ������ ����� ���� �������� � ����� Stonebraker'� "Readings in Database Systems".
����������� R-tree ����� ��������� ���������� � �������. � ������, R-tree ����� ���� ��������� ��� ���������� ������� ����������� ���������. �� ��������, ���������� R-tree ������� ��������� ������ � � ���, � ������ ������, ��� �����-���� ������������ � ���, ��� ��� �������.
������ GEQO ���������� ������� ����������� �������, ����� ���������� ���������� ������ ������ ����� Genetic Algorithm (GA). ��� ��������� ��������� �������� ��������� �� ���������� ����� ������������ �����.
�������� ~ ���������� ����� ����������� ���������, � �������� ~* ���������� ����������� �� �������� ���� ����� ����������� ���������. ����������� �� �������� ������� LIKE ���������� ILIKE.
����������� �� �������� ��������� ������ ���������� ���:
SELECT * FROM tab WHERE lower(col) = 'abc';��� ����������� �� ����� ������������ ����������� ������. ������, ���� �� ��������� �������������� ������, �� ����� �����������:
CREATE INDEX tabindex ON tab (lower(col));
�� ������ ����������� �������� � IS NULL � IS NOT NULL.
��� ���������� ��� ��������� -------------------------------------------------- VARCHAR(n) varchar ������ ������ ������������ �����, ��� ���������� CHAR(n) bpchar ����������� �������� �� ������������� ����� TEXT text ��� ����������� �������� ����������� ��� ����� BYTEA bytea ������ ���� ���������� ����� (����� ������������ null-���� ��� ������) "char" char ���� ������
���������� ��� �� ������ �������, ����� �������� ��������� �������� � � ��������� ���������� �� �������.
������ ������ ���� �������� "varlena" ������ (�.�., ������ ������ ����� �� ����� �������� �������, �� ������� ������� ������). ����� �������, ���������� ������������ ������������ ������, ��� ������������ ������. ������, ��� ���� ������ ����� ��������� ������ ��� ����� ���� ��������� �� � ������� ���� ����� TOAST, ��� ��� ���������� �������� ������������ ����� ����� ���� � ������, ��� ���������.
VARCHAR(n) - ��� ������ �������, ����� ����� ������� ������ ���������� �����, �� ����������� ������������� �������. TEXT - ��� ������ ������� ��� ����� �������������� �����, � ����������� ���������� ������ � 1 ��������.CHAR(n) - ��� ������ ������� ��� �������� �����, ������� ������ ����� ���������� �����. CHAR(n) ����������� �������� �� �������� �����, � �� ����� ��� VARCHAR(n) ������ ������ �������, �� ������� ������� ������. BYTEA ������������ ��� �������� �������� ������, �������� ������� ����� �������� NULL �����. ��� ���� ��������� �����, ����� ������� �������������� ������������������.
PostgreSQL ������������ ��� ������ SERIAL. �� ������������� ������� ������������������ � ������ ��� �������. ��������:
CREATE TABLE person ( id SERIAL, name TEXT );������������� ������������� �:
CREATE SEQUENCE person_id_seq; CREATE TABLE person ( id INT4 NOT NULL DEFAULT nextval('person_id_seq'), name TEXT ); CREATE UNIQUE INDEX person_id_key ON person ( id );�������� ����������� � ������������������� �� �������� ����������� ����������� create_sequence. �� ����� ������ ������������ ������ ���� OID � ������ ��� ���������� ��������. ������, ���� ��� ����� ���� � ������������ ���� ������, ��� ���������� ������������ ������� pg_dump � ������ -o ��� ����� COPY WITH OIDS ��� ���������� �������� ���� OID.
���� �� �������� ������� � ��������� ���������� �������� SERIAL �� ������� sequence � ������� ������� nextval() ����� �������� � ����� ��������� ��� �������� ����. ����������� �������-������ � 4.15.1, ������ � ����������� ������� ��� ��� ��������:
new_id = execute("SELECT nextval('person_id_seq')"); execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");����� �� ������ ����� ��������� ����� �������� � ����������
new_id
��� ��� ������������� � ������ �������� (��������
����� ��� ������� ���� ��� ������� person
). �������,
��� ��� ������������� ���������� ������� SEQUENCE
����� <table>_<serialcolumn>_seq,
��� table � serialcolumn �������� ��������������
������� ����� ������� � ����� ������� SERIAL.
� �������� ������������, �� ������ �������� ����������� �������� SERIAL � ������� ������� currval() ����� ���������� ������� �������� �������, ��������
execute("INSERT INTO person (name) VALUES ('Blaise Pascal')"); new_id = execute("SELECT currval('person_id_seq')");� �������, �� ������ ������������ �������� OID, ����������� �� �������� INSERT ����� ������� �������� �� ���������, ��� ���������������� �������� �������� ����������� �� ������ ��������� ��������. � Perl, ��������� DBI � ������� Edmund Mergl'� DBD::Pg, �������� oid ���������� ��������� ����� $sth->{pg_oid_status} ����� $sth->execute().
���. currval() ���������� ������� ��������, ����������� ����� backend'��, � �� ������� ��������������.
��� ���������� �������������, �������� �������������������, ��� ������������� �������� �� ����� ������� ���������� � �� ����������� �� ������� ���������� ����������. ��� ����� �������� ������� � ��������� ��� ������ ����������.
���� OID ������ ����������� ��������������� ������� � PostgreSQL. ������ ������, ������� ��������� � PostgreSQL �������� ���������� OID. ��� �������� OID ������������ �� ����� initdb ����� �������� ������ 16384 (�� include/access/transam.h). ��� ��������� ������������� OID ����� ������� ��������. �� ���������, ��� ��� OID �������� ����������� �� ������ ������ �����-���� ������� ��� ���� ������, �� � ������ ���� ���� PostgreSQL.
PostgreSQL ���������� OID � ����� ���������� ��������� �������� ��� ����� ������� � ������. �������� OID ����� ���� ������������ ��� ������������� �������� ������������� �������, � ����� �������������� ��� �����������. ������������� ������������ ��� ������� OID ��� �������� �������� OID �� ������ ������� ������ �� ���� OID ��� ����� �������� �������.
�������� OID ����������� ��� ���� ����� ������� �� ����������� �������, ������� ������������ ����� ����� ������ ������. ���� �� ������ �������� OID �� �����-���� ������ �������� ��� ���� �� ������ ������� ����� ������� � �������� OID, �� ��� ����� ������� ���:
CREATE TABLE new_table(old_oid oid, mycol int); SELECT old_oid, mycol INTO new FROM old; COPY new TO '/tmp/pgtable'; DELETE FROM new; COPY new WITH OIDS FROM '/tmp/pgtable';
OID �������� ��� 4-� ������� ����� � �� ����� ��������� �������� � 4 ���������. ������, ��� ����� �� ������� � ���, ��� ����� ���������, �� �� ��������� �� ���� ��� ��� ��������� ��������� �� ����� �����������.
TID ������������ ��� ������������� ����������� ���������� ������� � �������� � offset ����������. TID ���������� ����� ���� ��� ������ ���� �������� ��� �����������.
TID ������������ ���������� �������� � �������� ��������� �� ���������� ������.
��������� �������� ��� � ������ ������������ ���������� ������������������� �������. ��� ��������� �� ���:
������ ����� �������� �� ����� ������ ����� ����� �� http://hea-www.harvard.edu/MST/simul/software/docs/pkgs/pgsql/glossary/glossary.html
���������������� � ��� ����������� ����������� ������ ��� ��� ���� ���� ����� ��������� ����� �� ������������ �������. ����������� ����� �������� postmaster ��������� ��������� �������:
ulimit -d 262144 limit datasize 256m� ����������� �� ���������� �������������� shell, ������ ���� �� ������ ������ ���������� �������, �� ��� �������� ��� ���������� ������� ������� ������ �������� � �������� ����� ��������. ��� ������� �������� ��������� �������� �������� � ���� ��� ��������, ��������� ����� ţ �������. ���� � ��� �������� �������� � SQL ��������, ������ ��� backend ���������� ������� ������� ����� ������, ����������� ��������� ��� ������� ����� �������� �������.
�� psql, �������� SELECT version();
��� ����� ��� ������������� �������� ������� ��������� � ������
BEGIN WORK
� � ����� COMMIT
, � ������
������������� ����� lo_open
... lo_close.
� ��������� ������ PostgreSQL �������, ����� ��� �������� �������� ������� ����������� ���������� ����������. ����� �������, ������ �� ������� ������� ���-���� � ������� ��������, �� �������� ������� ������� �������� � ��������� invalid large obj descriptor, ��� ��� ��� ����������� ������ ��� ������� �������� (�� ������� ���� � ��������� ������) ����� ������������ ��������� �� ������ ���� �� �� ����������� ����������.
���� �� ����������� ����� ��������� ������� ��� ODBC,
��� �������� ����������� ���������� auto-commit off.
����������� CURRENT_TIMESTAMP:
CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
IN
��� �������� ���������?� ��������� ������, �� ��������� ��������� ��� ������� ��������
����� ���������������� ������� ���������� ���������� ��� ������
������ �������� �������. ���� ��������� ���������� ������ ���������
������� � ������� ������ ���������� ����� �������,
IN
�������� �������� ������. �����
��������� �������� � ������ ��������, �������� IN
��
EXISTS
:
SELECT * FROM tab WHERE col IN (SELECT subcol FROM subtab);��:
SELECT * FROM tab WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col);����� ����� ����������� �������� ������, �������
subcol
������ ���� ����������������. ��� �������� ������������������ �����
��������� � ������ 7.4.
PostgreSQL ������������ ������� ����������, ��������� ����������� ��������� SQL. ��� ��� �������:
SELECT * FROM t1 LEFT OUTER JOIN t2 ON (t1.col = t2.col);���
SELECT * FROM t1 LEFT OUTER JOIN t2 USING (col);
��� ���������� ������� ���������� t1.col � t2.col, ����� ���������� ����� ����������� ������ � t1 (������� �� ��������� � t2). RIGHT ���������� ������ �������� ����������� ������ t2. FULL ���������� ������ ���������� ��������� ������ ���� ��� ����������� ������ �� t1 � t2. ����� OUTER �������� �������������� � ����������� � LEFT, RIGHT � FULL �����������. ������� ���������� ���������� INNER ����������.
� ���������� �������, ������� ���������� ����� ���� �����������
��������� UNION � NOT IN. ��������,
����� ���������� ���������� tab1 � tab2, ���������
������ ��������� ������� ���������� ���� ������:
SELECT tab1.col1, tab2.col2 FROM tab1, tab2 WHERE tab1.col1 = tab2.col1 UNION ALL SELECT tab1.col1, NULL FROM tab1 WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2) ORDER BY col1
�� ���������� ������� ������� ������ � ����� ������ �������� �� �������. ��������� PostgreSQL ��������� ��������� �������� ����������� ��� ���� ������, ��������� ����, ��� ������ ���� ����� ����� ���������� ������.
contrib/dblink ��������� ������� ����� ������, ��������� ������ �������. ����������, ������ ����� ������������ ������������� ����������� � ���������� ������ ������ � ����� ������� ���������� ���������� �� ���.
� ������ 7.3, �� ������ ����� ������� ��������� ������� ��� ������� ��
�����-���� �������,
PL/PgSQL �������� ���������� ������� � ���� �� ���������� �������� ����� ������� � ���, ��� ���� ������� PL/PgSQL ���������� � ��������� ������� � ��� ������� ������� ��������� � �������������, � ������� ����� ���������� �����, �� �� ����� �������� � ������, ������ ��� ������������� ���������� ������� �������� ��������� �� ������ ��������� �������. ����� ������ ��� ��������, ����������� EXECUTE ��� ������� � ��������� �������� � PL/PgSQL. ������������� ����� ��������� �������� ������ ������������������ ������ ���.
���� ��������� ����� ��� ���������� ���� master/slave. ��� ��������� ������������� ������ master ������� ��� �������� ��������� � ���� ������, � slave ������� ������ ��������� ������ ������ �� ����. �� ���� ������� �����: http://gborg.PostgreSQL.org/genpage?replication_research. � ���������� � ����������� master ��������� ������� �����: http://gborg.PostgreSQL.org/project/pgreplication/projdisplay.php.
�������� ����� ����������� � ���������� �����. ����������� ������ �������������� ���� ������� � ��������� ��������������� ���������.
��������� ���� ���������� � ������ �������� pgsql-hackers � ��� �� ����������� ����� �������� � ���������� contrib/.
� ������� PostgreSQL, ������� � 7.3, �������, ������������ ������� ��������� �������������� � C, PL/PgSQL � SQL. ����������� �������� � ����������� ������������. ������ ������������ ������� �������, ���������� �� C, ����� ����� � contrib/tablefunc.
����� Makefile �� ����� ���������� ������������ ��� include ������. �� ������ ��������� make clean � ����� make. ���� �� ����������� GCC �� ������ ������������ ����� --enable-depend � configure ����� �������� ����������� ������������� ����������� �����������.