Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b72ebd

Browse files
committed
Merge query of system objects FAQ items.
1 parent 7a6a7d5 commit 0b72ebd

File tree

2 files changed

+125
-134
lines changed

2 files changed

+125
-134
lines changed

doc/FAQ

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Frequently Asked Questions (FAQ) for PostgreSQL
33

4-
Last updated: Sun Jan 9 14:44:04 EST 2005
4+
Last updated: Sat Jan 15 00:18:38 EST 2005
55

66
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
77

@@ -60,43 +60,42 @@
6060

6161
4.1) What is the difference between binary cursors and normal cursors?
6262
4.2) How do I SELECT only the first few rows of a query? A random row?
63-
4.3) How do I get a list of tables or other things I can see in psql?
63+
4.3) How do I find out what tables, indexes, databases, and users are
64+
defined? How do I see the queries used by psql to display them?
6465
4.4) How do you remove a column from a table, or change it's data
6566
type?
6667
4.5) What is the maximum size for a row, a table, and a database?
6768
4.6) How much database disk space is required to store data from a
6869
typical text file?
69-
4.7) How do I find out what tables, indexes, databases, and users are
70-
defined?
71-
4.8) My queries are slow or don't make use of the indexes. Why?
72-
4.9) How do I see how the query optimizer is evaluating my query?
73-
4.10) What is an R-tree index?
74-
4.11) What is the Genetic Query Optimizer?
75-
4.12) How do I perform regular expression searches and
70+
4.7) My queries are slow or don't make use of the indexes. Why?
71+
4.8) How do I see how the query optimizer is evaluating my query?
72+
4.9) What is an R-tree index?
73+
4.10) What is the Genetic Query Optimizer?
74+
4.11) How do I perform regular expression searches and
7675
case-insensitive regular expression searches? How do I use an index
7776
for case-insensitive searches?
78-
4.13) In a query, how do I detect if a field is NULL?
79-
4.14) What is the difference between the various character types?
80-
4.15.1) How do I create a serial/auto-incrementing field?
81-
4.15.2) How do I get the value of a SERIAL insert?
82-
4.15.3) Doesn't currval() lead to a race condition with other users?
83-
4.15.4) Why aren't my sequence numbers reused on transaction abort?
77+
4.12) In a query, how do I detect if a field is NULL?
78+
4.13) What is the difference between the various character types?
79+
4.14.0) How do I create a serial/auto-incrementing field?
80+
4.14.1) How do I get the value of a SERIAL insert?
81+
4.14.2) Doesn't currval() lead to a race condition with other users?
82+
4.14.3) Why aren't my sequence numbers reused on transaction abort?
8483
Why are there gaps in the numbering of my sequence/SERIAL column?
85-
4.16) What is an OID? What is a TID?
86-
4.17) What is the meaning of some of the terms used in PostgreSQL?
87-
4.18) Why do I get the error "ERROR: Memory exhausted in
84+
4.15) What is an OID? What is a TID?
85+
4.16) What is the meaning of some of the terms used in PostgreSQL?
86+
4.17) Why do I get the error "ERROR: Memory exhausted in
8887
AllocSetAlloc()"?
89-
4.19) How do I tell what PostgreSQL version I am running?
90-
4.20) Why does my large-object operations get "invalid large obj
88+
4.18) How do I tell what PostgreSQL version I am running?
89+
4.19) Why does my large-object operations get "invalid large obj
9190
descriptor"?
92-
4.21) How do I create a column that will default to the current time?
93-
4.22) Why are my subqueries using IN so slow?
94-
4.23) How do I perform an outer join?
95-
4.24) How do I perform queries using multiple databases?
96-
4.25) How do I return multiple rows or columns from a function?
97-
4.26) Why can't I reliably create/drop temporary tables in PL/PgSQL
91+
4.20) How do I create a column that will default to the current time?
92+
4.21) Why are my subqueries using IN so slow?
93+
4.22) How do I perform an outer join?
94+
4.23) How do I perform queries using multiple databases?
95+
4.24) How do I return multiple rows or columns from a function?
96+
4.25) Why can't I reliably create/drop temporary tables in PL/PgSQL
9897
functions?
99-
4.27) What encryption options are available?
98+
4.26) What encryption options are available?
10099

101100
Extending PostgreSQL
102101

@@ -659,17 +658,25 @@ log_*
659658
ORDER BY random()
660659
LIMIT 1;
661660

662-
4.3) How do I get a list of tables or other things I can see in psql?
661+
4.3) How do I find out what tables, indexes, databases, and users are
662+
defined? How do I see the queries used by psql to display them?
663663

664664
Use the \dt command to see tables in psql. For a complete list of
665665
commands inside psql you can use \?. Alternatively you can read the
666666
source code for psql in file pgsql/src/bin/psql/describe.c, it
667667
contains SQL commands that generate the output for psql's backslash
668668
commands. You can also start psql with the -E option so it will print
669669
out the queries it uses to execute the commands you give. PostgreSQL
670-
also provides an SQLi compliant INFORMATION SCHEMA interface you can
670+
also provides an SQL compliant INFORMATION SCHEMA interface you can
671671
query to get information about the database.
672672

673+
There are also system tables beginning with pg_ that describe these
674+
too. Use psql -l will list all databases.
675+
676+
Also try the file pgsql/src/tutorial/syscat.source. It illustrates
677+
many of the SELECTs needed to get information from the database system
678+
tables.
679+
673680
4.4) How do you remove a column from a table, or change its data type?
674681

675682
DROP COLUMN functionality was added in release 7.3 with ALTER TABLE
@@ -749,18 +756,7 @@ log_*
749756

750757
NULLs are stored as bitmaps, so they use very little space.
751758

752-
4.7) How do I find out what tables, indexes, databases, and users are
753-
defined?
754-
755-
psql has a variety of backslash commands to show such information. Use
756-
\? to see them. There are also system tables beginning with pg_ that
757-
describe these too. Also, psql -l will list all databases.
758-
759-
Also try the file pgsql/src/tutorial/syscat.source. It illustrates
760-
many of the SELECTs needed to get information from the database system
761-
tables.
762-
763-
4.8) My queries are slow or don't make use of the indexes. Why?
759+
4.7) My queries are slow or don't make use of the indexes. Why?
764760

765761
Indexes are not automatically used by every query. Indexes are only
766762
used if the table is larger than a minimum size, and the query selects
@@ -802,7 +798,7 @@ log_*
802798
[a-e].
803799
* Case-insensitive searches such as ILIKE and ~* do not utilise
804800
indexes. Instead, use functional indexes, which are described in
805-
section 4.12.
801+
section 4.11.
806802
* The default C locale must be used during initdb because it is not
807803
possible to know the next-greater character in a non-C locale. You
808804
can create a special
@@ -815,11 +811,11 @@ LIKE
815811
types exactly match the index's column types. This is particularly
816812
true of int2, int8, and numeric column indexes.
817813

818-
4.9) How do I see how the query optimizer is evaluating my query?
814+
4.8) How do I see how the query optimizer is evaluating my query?
819815

820816
See the EXPLAIN manual page.
821817

822-
4.10) What is an R-tree index?
818+
4.9) What is an R-tree index?
823819

824820
An R-tree index is used for indexing spatial data. A hash index can't
825821
handle range searches. A B-tree index only handles range searches in a
@@ -842,13 +838,13 @@ LIKE
842838
extending R-trees requires a bit of work and we don't currently have
843839
any documentation on how to do it.
844840

845-
4.11) What is the Genetic Query Optimizer?
841+
4.10) What is the Genetic Query Optimizer?
846842

847843
The GEQO module speeds query optimization when joining many tables by
848844
means of a Genetic Algorithm (GA). It allows the handling of large
849845
join queries through nonexhaustive search.
850846

851-
4.12) How do I perform regular expression searches and case-insensitive
847+
4.11) How do I perform regular expression searches and case-insensitive
852848
regular expression searches? How do I use an index for case-insensitive
853849
searches?
854850

@@ -865,11 +861,11 @@ LIKE
865861
functional index, it will be used:
866862
CREATE INDEX tabindex ON tab (lower(col));
867863

868-
4.13) In a query, how do I detect if a field is NULL?
864+
4.12) In a query, how do I detect if a field is NULL?
869865

870866
You test the column with IS NULL and IS NOT NULL.
871867

872-
4.14) What is the difference between the various character types?
868+
4.13) What is the difference between the various character types?
873869

874870
Type Internal Name Notes
875871
--------------------------------------------------
@@ -897,7 +893,7 @@ BYTEA bytea variable-length byte array (null-byte safe)
897893
particularly values that include NULL bytes. All the types described
898894
here have similar performance characteristics.
899895

900-
4.15.1) How do I create a serial/auto-incrementing field?
896+
4.14.1) How do I create a serial/auto-incrementing field?
901897

902898
PostgreSQL supports a SERIAL data type. It auto-creates a sequence.
903899
For example, this:
@@ -918,11 +914,11 @@ BYTEA bytea variable-length byte array (null-byte safe)
918914
However, if you need to dump and reload the database, you need to use
919915
pg_dump's -o option or COPY WITH OIDS option to preserve the OIDs.
920916

921-
4.15.2) How do I get the value of a SERIAL insert?
917+
4.14.2) How do I get the value of a SERIAL insert?
922918

923919
One approach is to retrieve the next SERIAL value from the sequence
924920
object with the nextval() function before inserting and then insert it
925-
explicitly. Using the example table in 4.15.1, an example in a
921+
explicitly. Using the example table in 4.14.1, an example in a
926922
pseudo-language would look like this:
927923
new_id = execute("SELECT nextval('person_id_seq')");
928924
execute("INSERT INTO person (id, name) VALUES (new_id, 'Blaise Pascal')");
@@ -944,19 +940,19 @@ BYTEA bytea variable-length byte array (null-byte safe)
944940
billion. In Perl, using DBI with the DBD::Pg module, the oid value is
945941
made available via $sth->{pg_oid_status} after $sth->execute().
946942

947-
4.15.3) Doesn't currval() lead to a race condition with other users?
943+
4.14.3) Doesn't currval() lead to a race condition with other users?
948944

949945
No. currval() returns the current value assigned by your backend, not
950946
by all users.
951947

952-
4.15.4) Why aren't my sequence numbers reused on transaction abort? Why are
948+
4.14.4) Why aren't my sequence numbers reused on transaction abort? Why are
953949
there gaps in the numbering of my sequence/SERIAL column?
954950

955951
To improve concurrency, sequence values are given out to running
956952
transactions as needed and are not locked until the transaction
957953
completes. This causes gaps in numbering from aborted transactions.
958954

959-
4.16) What is an OID? What is a TID?
955+
4.15) What is an OID? What is a TID?
960956

961957
OIDs are PostgreSQL's answer to unique row ids. Every row that is
962958
created in PostgreSQL gets a unique OID. All OIDs generated during
@@ -989,7 +985,7 @@ BYTEA bytea variable-length byte array (null-byte safe)
989985
values. TIDs change after rows are modified or reloaded. They are used
990986
by index entries to point to physical rows.
991987

992-
4.17) What is the meaning of some of the terms used in PostgreSQL?
988+
4.16) What is the meaning of some of the terms used in PostgreSQL?
993989

994990
Some of the source code and older documentation use terms that have
995991
more common usage. Here are some:
@@ -1007,7 +1003,7 @@ BYTEA bytea variable-length byte array (null-byte safe)
10071003
http://hea-www.harvard.edu/MST/simul/software/docs/pkgs/pgsql/glossary
10081004
/glossary.html
10091005

1010-
4.18) Why do I get the error "ERROR: Memory exhausted in AllocSetAlloc()"?
1006+
4.17) Why do I get the error "ERROR: Memory exhausted in AllocSetAlloc()"?
10111007

10121008
You probably have run out of virtual memory on your system, or your
10131009
kernel has a low limit for certain resources. Try this before starting
@@ -1022,11 +1018,11 @@ BYTEA bytea variable-length byte array (null-byte safe)
10221018
problem with the SQL client because the backend is returning too much
10231019
data, try it before starting the client.
10241020

1025-
4.19) How do I tell what PostgreSQL version I am running?
1021+
4.18) How do I tell what PostgreSQL version I am running?
10261022

10271023
From psql, type SELECT version();
10281024

1029-
4.20) Why does my large-object operations get "invalid large obj
1025+
4.19) Why does my large-object operations get "invalid large obj
10301026
descriptor"?
10311027

10321028
You need to put BEGIN WORK and COMMIT around any use of a large object
@@ -1041,12 +1037,12 @@ BYTEA bytea variable-length byte array (null-byte safe)
10411037
If you are using a client interface like ODBC you may need to set
10421038
auto-commit off.
10431039

1044-
4.21) How do I create a column that will default to the current time?
1040+
4.20) How do I create a column that will default to the current time?
10451041

10461042
Use CURRENT_TIMESTAMP:
10471043
CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
10481044

1049-
4.22) Why are my subqueries using IN so slow?
1045+
4.21) Why are my subqueries using IN so slow?
10501046

10511047
In versions prior to 7.4, subqueries were joined to outer queries by
10521048
sequentially scanning the result of the subquery for each row of the
@@ -1067,7 +1063,7 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
10671063
In version 7.4 and later, IN actually uses the same sophisticated join
10681064
techniques as normal queries, and is prefered to using EXISTS.
10691065

1070-
4.23) How do I perform an outer join?
1066+
4.22) How do I perform an outer join?
10711067

10721068
PostgreSQL supports outer joins using the SQL standard syntax. Here
10731069
are two examples:
@@ -1097,7 +1093,7 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
10971093
WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
10981094
ORDER BY col1
10991095

1100-
4.24) How do I perform queries using multiple databases?
1096+
4.23) How do I perform queries using multiple databases?
11011097

11021098
There is no way to query a database other than the current one.
11031099
Because PostgreSQL loads database-specific system catalogs, it is
@@ -1107,12 +1103,12 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
11071103
course, a client can make simultaneous connections to different
11081104
databases and merge the results on the client side.
11091105

1110-
4.25) How do I return multiple rows or columns from a function?
1106+
4.24) How do I return multiple rows or columns from a function?
11111107

11121108
In 7.3, you can easily return multiple rows or columns from a
11131109
function, http://techdocs.postgresql.org/guides/SetReturningFunctions.
11141110

1115-
4.26) Why can't I reliably create/drop temporary tables in PL/PgSQL
1111+
4.25) Why can't I reliably create/drop temporary tables in PL/PgSQL
11161112
functions?
11171113

11181114
PL/PgSQL caches function contents, and an unfortunate side effect is
@@ -1123,7 +1119,7 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
11231119
table access in PL/PgSQL. This will cause the query to be reparsed
11241120
every time.
11251121

1126-
4.27) What encryption options are available?
1122+
4.26) What encryption options are available?
11271123

11281124
* contrib/pgcrypto contains many encryption functions for use in SQL
11291125
queries.

0 commit comments

Comments
 (0)