11
22 Frequently Asked Questions (FAQ) for PostgreSQL
33
4- Last updated: Mon Jan 3120:41:21 EST 2005
4+ Last updated: Mon Jan 3121:31:39 EST 2005
55
66 Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
77
6868 4.11.3) Why aren't my sequence numbers reused on transaction abort?
6969 Why are there gaps in the numbering of my sequence/SERIAL column?
7070 4.12) What is an OID? What is a TID?
71- 4.13) What is the meaning of some of the terms used in PostgreSQL?
72- 4.14) Why do I get the error "ERROR: Memory exhausted in
71+ 4.13) Why do I get the error "ERROR: Memory exhausted in
7372 AllocSetAlloc()"?
74- 4.15 ) How do I tell what PostgreSQL version I am running?
75- 4.16 ) Why does my large-object operations get "invalid large obj
73+ 4.14 ) How do I tell what PostgreSQL version I am running?
74+ 4.15 ) Why does my large-object operations get "invalid large obj
7675 descriptor"?
77- 4.17 ) How do I create a column that will default to the current time?
78- 4.18 ) How do I perform an outer join?
79- 4.19 ) How do I perform queries using multiple databases?
80- 4.20 ) How do I return multiple rows or columns from a function?
81- 4.21 ) Why can't I reliably create/drop temporary tables in PL/PgSQL
76+ 4.16 ) How do I create a column that will default to the current time?
77+ 4.17 ) How do I perform an outer join?
78+ 4.18 ) How do I perform queries using multiple databases?
79+ 4.19 ) How do I return multiple rows or columns from a function?
80+ 4.20 ) Why can't I reliably create/drop temporary tables in PL/PgSQL
8281 functions?
83- 4.22 ) What encryption options are available?
82+ 4.21 ) What encryption options are available?
8483
8584 Extending PostgreSQL
8685
394393 properly. First, by running configure with the --enable-cassert
395394 option, many assert()s monitor the progress of the backend and halt
396395 the program when something unexpected occurs.
396+
397397 The postmaster has a -d option that allows even more detailed
398398 information to be reported. The -d option takes a number that
399399 specifies the debug level. Be warned that high debug level values
517517 4.4) What is the maximum size for a row, a table, and a database?
518518
519519 These are the limits:
520- Maximum size for a database? unlimited (32 TB databases exist)
521- Maximum size for a table? 32 TB
522- Maximum size for a row? 1.6TB
523- Maximum size for a field? 1 GB
524- Maximum number of rows in a table? unlimited
525- Maximum number of columns in a table? 250-1600 depending on column types
526- Maximum number of indexes on a table? unlimited
527-
520+
521+ Maximum size for a database? unlimited (32 TB databases exist)
522+ Maximum size for a table? 32 TB
523+ Maximum size for a row? 1.6TB
524+ Maximum size for a field? 1 GB
525+ Maximum number of rows in a table? unlimited
526+ Maximum number of columns in a table? 250-1600 depending on column
527+ types
528+ Maximum number of indexes on a table? unlimited
529+
528530 Of course, these are not actually unlimited, but limited to available
529531 disk space and memory/swap space. Performance may suffer when these
530532 values get unusually large.
611613 * The search string can not start with a character class, e.g.
612614 [a-e].
613615 * Case-insensitive searches such as ILIKE and ~* do not utilize
614- indexes. Instead, usefunctional indexes, which are described in
615- section 4.10 .
616+ indexes. Instead, useexpression indexes, which are described in
617+ section 4.8 .
616618 * The default C locale must be used during initdb because it is not
617- possible to know the next-greater character in a non-C locale. You
618- can create a special text_pattern_ops index for such cases that
619- work only for LIKE indexing.
619+ possible to know the next-greatest character in a non-C locale.
620+ You can create a special text_pattern_ops index for such cases
621+ that work only for LIKE indexing.
620622
621623 In pre-8.0 releases, indexes often can not be used unless the data
622- types exactly match the index's column types. Thisis particularly
624+ types exactly match the index's column types. Thiswas particularly
623625 true of int2, int8, and numeric column indexes.
624626
625627 4.7) How do I see how the query optimizer is evaluating my query?
640642 WHERE lower(col) = 'abc';
641643
642644 This will not use an standard index. However, if you create a
643- functional index, it will be used:
645+ expresssion index, it will be used:
644646 CREATE INDEX tabindex ON tab (lower(col));
645647
646648 4.9) In a query, how do I detect if a field is NULL?
649651
650652 4.10) What is the difference between the various character types?
651653
652- Type Internal Name Notes
653- --------------------------------------------------
654- VARCHAR(n) varchar size specifies maximum length, no padding
655- CHAR(n) bpchar blank padded to the specified fixed length
656- TEXT text no specific upper limit on length
657- BYTEA bytea variable-length byte array (null-byte safe)
658- "char" char one character
659-
654+ Type Internal Name Notes
655+ VARCHAR(n) varchar size specifies maximum length, no padding
656+ CHAR(n) bpchar blank padded to the specified fixed length
657+ TEXT text no specific upper limit on length
658+ BYTEA bytea variable-length byte array (null-byte safe)
659+ "char" char one character
660+
660661 You will see the internal name when examining system catalogs and in
661662 some error messages.
662663
@@ -692,9 +693,7 @@ BYTEA bytea variable-length byte array (null-byte safe)
692693 );
693694
694695 See the create_sequence manual page for more information about
695- sequences. You can also use each row's OID field as a unique value.
696- However, if you need to dump and reload the database, you need to use
697- pg_dump's -o option or COPY WITH OIDS option to preserve the OIDs.
696+ sequences.
698697
699698 4.11.2) How do I get the value of a SERIAL insert?
700699
@@ -716,16 +715,10 @@ BYTEA bytea variable-length byte array (null-byte safe)
716715 execute("INSERT INTO person (name) VALUES ('Blaise Pascal')");
717716 new_id = execute("SELECT currval('person_id_seq')");
718717
719- Finally, you could use the OID returned from the INSERT statement to
720- look up the default value, though this is probably the least portable
721- approach, and the oid value will wrap around when it reaches 4
722- billion. In Perl, using DBI with the DBD::Pg module, the oid value is
723- made available via $sth->{pg_oid_status} after $sth->execute().
724-
725718 4.11.3) Doesn't currval() lead to a race condition with other users?
726719
727- No. currval() returns the current value assigned by yourbackend , not
728- by allusers .
720+ No. currval() returns the current value assigned by yoursession , not
721+ by allsessions .
729722
730723 4.11.4) Why aren't my sequence numbers reused on transaction abort? Why are
731724 there gaps in the numbering of my sequence/SERIAL column?
@@ -751,25 +744,7 @@ BYTEA bytea variable-length byte array (null-byte safe)
751744 values. TIDs change after rows are modified or reloaded. They are used
752745 by index entries to point to physical rows.
753746
754- 4.13) What is the meaning of some of the terms used in PostgreSQL?
755-
756- Some of the source code and older documentation use terms that have
757- more common usage. Here are some:
758- * table, relation, class
759- * row, record, tuple
760- * column, field, attribute
761- * retrieve, select
762- * replace, update
763- * append, insert
764- * OID, serial value
765- * portal, cursor
766- * range variable, table name, table alias
767-
768- A list of general database terms can be found at:
769- http://hea-www.harvard.edu/MST/simul/software/docs/pkgs/pgsql/glossary
770- /glossary.html
771-
772- 4.14) Why do I get the error "ERROR: Memory exhausted in AllocSetAlloc()"?
747+ 4.13) Why do I get the error "ERROR: Memory exhausted in AllocSetAlloc()"?
773748
774749 You probably have run out of virtual memory on your system, or your
775750 kernel has a low limit for certain resources. Try this before starting
@@ -784,11 +759,11 @@ BYTEA bytea variable-length byte array (null-byte safe)
784759 problem with the SQL client because the backend is returning too much
785760 data, try it before starting the client.
786761
787- 4.15 ) How do I tell what PostgreSQL version I am running?
762+ 4.14 ) How do I tell what PostgreSQL version I am running?
788763
789764 From psql, type SELECT version();
790765
791- 4.16 ) Why does my large-object operations get "invalid large obj
766+ 4.15 ) Why does my large-object operations get "invalid large obj
792767 descriptor"?
793768
794769 You need to put BEGIN WORK and COMMIT around any use of a large object
@@ -803,12 +778,12 @@ BYTEA bytea variable-length byte array (null-byte safe)
803778 If you are using a client interface like ODBC you may need to set
804779 auto-commit off.
805780
806- 4.17 ) How do I create a column that will default to the current time?
781+ 4.16 ) How do I create a column that will default to the current time?
807782
808783 Use CURRENT_TIMESTAMP:
809784 CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
810785
811- 4.18 ) How do I perform an outer join?
786+ 4.17 ) How do I perform an outer join?
812787
813788 PostgreSQL supports outer joins using the SQL standard syntax. Here
814789 are two examples:
@@ -838,7 +813,7 @@ BYTEA bytea variable-length byte array (null-byte safe)
838813 WHERE tab1.col1 NOT IN (SELECT tab2.col1 FROM tab2)
839814 ORDER BY col1
840815
841- 4.19 ) How do I perform queries using multiple databases?
816+ 4.18 ) How do I perform queries using multiple databases?
842817
843818 There is no way to query a database other than the current one.
844819 Because PostgreSQL loads database-specific system catalogs, it is
@@ -848,12 +823,12 @@ BYTEA bytea variable-length byte array (null-byte safe)
848823 course, a client can make simultaneous connections to different
849824 databases and merge the results on the client side.
850825
851- 4.20 ) How do I return multiple rows or columns from a function?
826+ 4.19 ) How do I return multiple rows or columns from a function?
852827
853828 In 7.3, you can easily return multiple rows or columns from a
854829 function, http://techdocs.postgresql.org/guides/SetReturningFunctions.
855830
856- 4.21 ) Why can't I reliably create/drop temporary tables in PL/PgSQL
831+ 4.20 ) Why can't I reliably create/drop temporary tables in PL/PgSQL
857832 functions?
858833
859834 PL/PgSQL caches function contents, and an unfortunate side effect is
@@ -864,7 +839,7 @@ BYTEA bytea variable-length byte array (null-byte safe)
864839 table access in PL/PgSQL. This will cause the query to be reparsed
865840 every time.
866841
867- 4.22 ) What encryption options are available?
842+ 4.21 ) What encryption options are available?
868843
869844 * contrib/pgcrypto contains many encryption functions for use in SQL
870845 queries.