postgresql/contrib
Tom Lane 3d475515a1 Account explicitly for long-lived FDs that are allocated outside fd.c.
The comments in fd.c have long claimed that all file allocations should
go through that module, but in reality that's not always practical.
fd.c doesn't supply APIs for invoking some FD-producing syscalls like
pipe() or epoll_create(); and the APIs it does supply for non-virtual
FDs are mostly insistent on releasing those FDs at transaction end;
and in some cases the actual open() call is in code that can't be made
to use fd.c, such as libpq.

This has led to a situation where, in a modern server, there are likely
to be seven or so long-lived FDs per backend process that are not known
to fd.c.  Since NUM_RESERVED_FDS is only 10, that meant we had *very*
few spare FDs if max_files_per_process is >= the system ulimit and
fd.c had opened all the files it thought it safely could.  The
contrib/postgres_fdw regression test, in particular, could easily be
made to fall over by running it under a restrictive ulimit.

To improve matters, invent functions Acquire/Reserve/ReleaseExternalFD
that allow outside callers to tell fd.c that they have or want to allocate
a FD that's not directly managed by fd.c.  Add calls to track all the
fixed FDs in a standard backend session, so that we are honestly
guaranteeing that NUM_RESERVED_FDS FDs remain unused below the EMFILE
limit in a backend's idle state.  The coding rules for these functions say
that there's no need to call them in code that just allocates one FD over
a fairly short interval; we can dip into NUM_RESERVED_FDS for such cases.
That means that there aren't all that many places where we need to worry.
But postgres_fdw and dblink must use this facility to account for
long-lived FDs consumed by libpq connections.  There may be other places
where it's worth doing such accounting, too, but this seems like enough
to solve the immediate problem.

Internally to fd.c, "external" FDs are limited to max_safe_fds/3 FDs.
(Callers can choose to ignore this limit, but of course it's unwise
to do so except for fixed file allocations.)  I also reduced the limit
on "allocated" files to max_safe_fds/3 FDs (it had been max_safe_fds/2).
Conceivably a smarter rule could be used here --- but in practice,
on reasonable systems, max_safe_fds should be large enough that this
isn't much of an issue, so KISS for now.  To avoid possible regression
in the number of external or allocated files that can be opened,
increase FD_MINFREE and the lower limit on max_files_per_process a
little bit; we now insist that the effective "ulimit -n" be at least 64.

This seems like pretty clearly a bug fix, but in view of the lack of
field complaints, I'll refrain from risking a back-patch.

Discussion: https://postgr.es/m/E1izCmM-0005pV-Co@gemulon.postgresql.org
2020-02-24 17:28:33 -05:00
..
adminpack Remove some dead code in contrib/adminpack/ 2020-02-14 12:38:44 +09:00
amcheck Update copyrights for 2020 2020-01-01 12:21:45 -05:00
auth_delay Update copyrights for 2020 2020-01-01 12:21:45 -05:00
auto_explain Update copyrights for 2020 2020-01-01 12:21:45 -05:00
bloom Introduce IndexAM fields for parallel vacuum. 2020-01-15 07:24:14 +05:30
btree_gin Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
btree_gist Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
citext Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
cube Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
dblink Account explicitly for long-lived FDs that are allocated outside fd.c. 2020-02-24 17:28:33 -05:00
dict_int Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
dict_xsyn Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
earthdistance Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
file_fdw Update copyrights for 2020 2020-01-01 12:21:45 -05:00
fuzzystrmatch Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
hstore Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
hstore_plperl Mark some contrib modules as "trusted". 2020-02-13 15:02:35 -05:00
hstore_plpython Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
intagg Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
intarray Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
isn Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
jsonb_plperl Mark some contrib modules as "trusted". 2020-02-13 15:02:35 -05:00
jsonb_plpython In jsonb_plpython.c, suppress warning message from gcc 10. 2020-01-30 18:26:12 -05:00
lo Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
ltree Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
ltree_plpython Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
oid2name Clean up newlines following left parentheses 2020-01-30 13:42:14 -03:00
pageinspect Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
passwordcheck Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pg_buffercache Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
pg_freespacemap Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
pg_prewarm Remove excess parens in ereport() calls 2020-01-30 13:32:04 -03:00
pg_standby Remove useless "return;" lines 2019-11-28 16:48:37 -03:00
pg_stat_statements Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
pg_trgm Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
pg_visibility Update copyrights for 2020 2020-01-01 12:21:45 -05:00
pgcrypto Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
pgrowlocks Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
pgstattuple Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
postgres_fdw Account explicitly for long-lived FDs that are allocated outside fd.c. 2020-02-24 17:28:33 -05:00
seg Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
sepgsql Update copyrights for 2020 2020-01-01 12:21:45 -05:00
spi Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
sslinfo Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
start-scripts Remove contrib/start-scripts/osx/. 2017-11-17 12:53:20 -05:00
tablefunc Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
tcn Mark some contrib modules as "trusted". 2020-02-13 15:02:35 -05:00
test_decoding Stop demanding that top xact must be seen before subxact in decoding. 2020-02-19 08:15:49 +05:30
tsm_system_rows Mark some contrib modules as "trusted". 2020-02-13 15:02:35 -05:00
tsm_system_time Mark some contrib modules as "trusted". 2020-02-13 15:02:35 -05:00
unaccent Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
uuid-ossp Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
vacuumlo Update copyrights for 2020 2020-01-01 12:21:45 -05:00
xml2 Remove support for upgrading extensions from "unpackaged" state. 2020-02-19 16:59:14 -05:00
Makefile Transforms for jsonb to PL/Perl 2018-04-03 09:47:18 -04:00
README Rename 'gmake' to 'make' in docs and recommended commands 2014-02-12 17:29:19 -05:00
contrib-global.mk Respect TEMP_CONFIG when pg_regress_check and friends are called 2016-02-27 12:28:21 -05:00

README

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.