1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 python3_{5,6,7} )
8 PLOCALES="af cs de en es fa fr hr hu it ko nb pl pt_BR ro ru sk sl sv tr zh_CN
11 inherit flag-o-matic l10n linux-info multilib pam prefix python-single-r1 \
14 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-macos ~x86-solaris"
19 S="${WORKDIR}/${PN}-${MY_PV}"
21 SRC_URI="https://ftp.postgresql.org/pub/source/v${MY_PV}/postgresql-${MY_PV}.tar.bz2"
23 LICENSE="POSTGRESQL GPL-2"
24 DESCRIPTION="PostgreSQL RDBMS"
25 HOMEPAGE="https://www.postgresql.org/"
27 IUSE="debug doc icu kerberos kernel_linux ldap libressl nls pam perl
28 python +readline selinux +server systemd ssl static-libs tcl
29 threads uuid xml zlib"
31 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
34 >=app-eselect/eselect-postgresql-2.0
37 icu? ( dev-libs/icu:= )
38 kerberos? ( virtual/krb5 )
39 ldap? ( net-nds/openldap )
41 perl? ( >=dev-lang/perl-5.8:= )
42 python? ( ${PYTHON_DEPS} )
43 readline? ( sys-libs/readline:0= )
44 server? ( systemd? ( sys-apps/systemd ) )
46 !libressl? ( >=dev-libs/openssl-0.9.6-r1:0= )
47 libressl? ( dev-libs/libressl:= )
49 tcl? ( >=dev-lang/tcl-8:0= )
50 xml? ( dev-libs/libxml2 dev-libs/libxslt )
51 zlib? ( sys-libs/zlib )
54 # uuid flags -- depend on sys-apps/util-linux for Linux libcs, or if no
55 # supported libc in use depend on dev-libs/ossp-uuid. For BSD systems,
56 # the libc includes UUID functions.
57 UTIL_LINUX_LIBC=( elibc_{glibc,uclibc,musl} )
58 BSD_LIBC=( elibc_{Free,Net,Open}BSD )
62 while [[ ${#} -gt 1 ]]; do
67 echo "${front}${1}${back}"
70 IUSE+=" ${UTIL_LINUX_LIBC[@]} ${BSD_LIBC[@]}"
73 ${UTIL_LINUX_LIBC[@]/%/? ( sys-apps/util-linux )}
74 $(nest_usedep ${UTIL_LINUX_LIBC[@]/#/!} ${BSD_LIBC[@]/#/!} dev-libs/ossp-uuid)
78 !!<sys-apps/sandbox-2.0
81 nls? ( sys-devel/gettext )
82 xml? ( virtual/pkgconfig )
86 !dev-db/postgresql-docs:${SLOT}
87 !dev-db/postgresql-base:${SLOT}
88 !dev-db/postgresql-server:${SLOT}
89 selinux? ( sec-policy/selinux-postgresql )
93 use server && CONFIG_CHECK="~SYSVIPC" linux-info_pkg_setup
96 enewuser postgres 70 /bin/sh /var/lib/postgresql postgres
98 use python && python-single-r1_pkg_setup
102 # Work around PPC{,64} compilation bug where bool is already defined
103 sed '/#ifndef __cplusplus/a #undef bool' -i src/include/c.h || die
105 # Set proper run directory
106 sed "s|\(PGSOCKET_DIR\s\+\)\"/tmp\"|\1\"${EPREFIX}/run/postgresql\"|" \
107 -i src/include/pg_config_manual.h || die
109 # Rely on $PATH being in the proper order so that the correct
110 # install program is used for modules utilizing PGXS in both
111 # hardened and non-hardened environments. (Bug #528786)
112 sed 's/@install_bin@/install -c/' -i src/Makefile.global.in || die
114 use server || eapply "${FILESDIR}/${PN}-10.2-no-server.patch"
117 sed -e "s/\(#define PGSQL_PAM_SERVICE \"postgresql\)/\1-${SLOT}/" \
118 -i src/backend/libpq/auth.c || \
119 die 'PGSQL_PAM_SERVICE rename failed.'
127 *-darwin*|*-solaris*)
128 use nls && append-libs intl
132 export LDFLAGS_SL="${LDFLAGS}"
133 export LDFLAGS_EX="${LDFLAGS}"
135 local PO="${EPREFIX%/}"
137 local i uuid_config=""
139 for i in ${UTIL_LINUX_LIBC[@]}; do
140 use ${i} && uuid_config="--with-uuid=e2fs"
142 for i in ${BSD_LIBC[@]}; do
143 use ${i} && uuid_config="--with-uuid=bsd"
145 [[ -z $uuid_config ]] && uuid_config="--with-uuid=ossp"
149 --prefix="${PO}/usr/$(get_libdir)/postgresql-${SLOT}" \
150 --datadir="${PO}/usr/share/postgresql-${SLOT}" \
151 --docdir="${PO}/usr/share/doc/${PF}" \
152 --includedir="${PO}/usr/include/postgresql-${SLOT}" \
153 --mandir="${PO}/usr/share/postgresql-${SLOT}/man" \
154 --sysconfdir="${PO}/etc/postgresql-${SLOT}" \
155 --with-system-tzdata="${PO}/usr/share/zoneinfo" \
156 $(use_enable !alpha spinlocks) \
157 $(use_enable debug) \
158 $(use_enable threads thread-safety) \
160 $(use_with kerberos gssapi) \
165 $(use_with readline) \
166 $(use_with ssl openssl) \
167 $(usex server "$(use_with systemd)" '--without-systemd') \
170 $(use_with xml libxml) \
171 $(use_with xml libxslt) \
173 $(use_enable nls nls "'$(l10n_get_locales)'")
182 emake DESTDIR="${D}" install
183 emake DESTDIR="${D}" install -C contrib
185 dodoc README HISTORY doc/{TODO,bug.template}
187 # man pages are already built, but if we have the target make them,
188 # they'll be generated from source before being installed so we
189 # manually install man pages.
190 # We use ${SLOT} instead of doman for postgresql.eselect
191 insinto /usr/share/postgresql-${SLOT}/man/
192 doins -r doc/src/sgml/man{1,3,7}
193 if ! use server; then
194 # Remove man pages for non-existent binaries
197 pg_{archivecleanup,controldata,ctl,resetwal,rewind,standby}
198 pg_{test_{fsync,timing},upgrade,waldump}
201 for m in ${serverman[@]} ; do
202 rm "${ED}/usr/share/postgresql-${SLOT}/man/man1/${m}.1"
205 docompress /usr/share/postgresql-${SLOT}/man/man{1,3,7}
207 # Create slot specific man pages
208 local bn f mansec slotted_name
209 for mansec in 1 3 7 ; do
210 local rel_manpath="../../postgresql-${SLOT}/man/man${mansec}"
212 mkdir -p "${ED}"/usr/share/man/man${mansec} || die "making man dir"
213 pushd "${ED}"/usr/share/man/man${mansec} > /dev/null || die "pushd failed"
215 for f in "${ED}/usr/share/postgresql-${SLOT}/man/man${mansec}"/* ; do
216 bn=$(basename "${f}")
217 slotted_name=${bn%.${mansec}}${SLOT}.${mansec}
220 echo ".so ${rel_manpath}/SELECT.7" > ${slotted_name}
223 echo ".so ${rel_manpath}/${bn}" > ${slotted_name}
231 insinto /etc/postgresql-${SLOT}
232 newins src/bin/psql/psqlrc.sample psqlrc
234 # Don't delete libpg{port,common}.a (Bug #571046). They're always
235 # needed by extensions utilizing PGXS.
237 find "${ED}" -name '*.a' ! -name libpgport.a ! -name libpgcommon.a \
240 # Make slot specific links to programs
242 for f in $(find "${ED}/usr/$(get_libdir)/postgresql-${SLOT}/bin" \
243 -mindepth 1 -maxdepth 1)
245 bn=$(basename "${f}")
246 dosym "../$(get_libdir)/postgresql-${SLOT}/bin/${bn}" \
247 "/usr/bin/${bn}${SLOT/.}"
252 dodoc doc/src/sgml/html/*
256 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
257 "${FILESDIR}/${PN}.confd-9.3" | newconfd - ${PN}-${SLOT}
259 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
260 "${FILESDIR}/${PN}.init-9.3-r1" | newinitd - ${PN}-${SLOT}
263 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
264 "${FILESDIR}/${PN}.service-9.6-r1" | \
265 systemd_newunit - ${PN}-${SLOT}.service
266 newbin "${FILESDIR}"/${PN}-check-db-dir ${PN}-${SLOT}-check-db-dir
267 systemd_newtmpfilesd "${FILESDIR}"/${PN}.tmpfiles ${PN}-${SLOT}.conf
270 use pam && pamd_mimic system-auth ${PN}-${SLOT} auth account session
273 keepdir /run/postgresql
274 fperms 1775 /run/postgresql
280 use server && use systemd && systemd_tmpfiles_create ${PN}-${SLOT}.conf
281 postgresql-config update
283 elog "If you need a global psqlrc-file, you can place it in:"
284 elog " ${EROOT%/}/etc/postgresql-${SLOT}/"
288 elog "Gentoo specific documentation:"
289 elog "https://wiki.gentoo.org/wiki/PostgreSQL"
291 elog "Official documentation:"
292 elog "https://www.postgresql.org/docs/${SLOT}/static/index.html"
294 elog "The default location of the Unix-domain socket is:"
295 elog " ${EROOT%/}/run/postgresql/"
297 elog "Before initializing the database, you may want to edit PG_INITDB_OPTS"
298 elog "so that it contains your preferred locale in:"
299 elog " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
301 elog "Then, execute the following command to setup the initial database"
303 elog " emerge --config =${CATEGORY}/${PF}"
305 if [[ -n ${REPLACING_VERSIONS} ]] ; then
306 ewarn "If your system is using 'pg_stat_statements' and you are running a"
307 ewarn "version of PostgreSQL ${SLOT}, we advise that you execute"
308 ewarn "the following command after upgrading:"
310 ewarn "ALTER EXTENSION pg_stat_statements UPDATE;"
316 if use server && [[ -z ${REPLACED_BY_VERSION} ]] ; then
317 ewarn "Have you dumped and/or migrated the ${SLOT} database cluster?"
318 ewarn "\thttps://wiki.gentoo.org/wiki/PostgreSQL/QuickStart#Migrating_PostgreSQL"
320 ebegin "Resuming removal in 10 seconds (Control-C to cancel)"
327 postgresql-config update
331 use server || die "USE flag 'server' not enabled. Nothing to configure."
333 [[ -f "${EROOT%/}/etc/conf.d/postgresql-${SLOT}" ]] \
334 && source "${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
335 [[ -z "${PGDATA}" ]] && PGDATA="${EROOT%/}/etc/postgresql-${SLOT}/"
336 [[ -z "${DATA_DIR}" ]] \
337 && DATA_DIR="${EROOT%/}/var/lib/postgresql/${SLOT}/data"
339 # environment.bz2 may not contain the same locale as the current system
340 # locale. Unset and source from the current system locale.
341 if [ -f "${EROOT%/}/etc/env.d/02locale" ]; then
350 source "${EROOT%/}/etc/env.d/02locale"
351 [ -n "${LANG}" ] && export LANG
352 [ -n "${LC_CTYPE}" ] && export LC_CTYPE
353 [ -n "${LC_NUMERIC}" ] && export LC_NUMERIC
354 [ -n "${LC_TIME}" ] && export LC_TIME
355 [ -n "${LC_COLLATE}" ] && export LC_COLLATE
356 [ -n "${LC_MONETARY}" ] && export LC_MONETARY
357 [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES
358 [ -n "${LC_ALL}" ] && export LC_ALL
361 einfo "You can modify the paths and options passed to initdb by editing:"
362 einfo " ${EROOT%/}/etc/conf.d/postgresql-${SLOT}"
364 einfo "Information on options that can be passed to initdb are found at:"
365 einfo " https://www.postgresql.org/docs/${SLOT}/static/creating-cluster.html"
366 einfo " https://www.postgresql.org/docs/${SLOT}/static/app-initdb.html"
368 einfo "PG_INITDB_OPTS is currently set to:"
369 if [[ -z "${PG_INITDB_OPTS}" ]] ; then
372 einfo " ${PG_INITDB_OPTS}"
375 einfo "Configuration files will be installed to:"
378 einfo "The database cluster will be created in:"
382 ebegin "Continuing initialization in 5 seconds (Control-C to cancel)"
386 if [ -n "$(ls -A ${DATA_DIR} 2> /dev/null)" ] ; then
387 eerror "The given directory, '${DATA_DIR}', is not empty."
388 eerror "Modify DATA_DIR to point to an empty directory."
389 die "${DATA_DIR} is not empty."
392 einfo "Creating the data directory ..."
393 if [[ ${EUID} == 0 ]] ; then
394 mkdir -p "${DATA_DIR}"
395 chown -Rf postgres:postgres "${DATA_DIR}"
396 chmod 0700 "${DATA_DIR}"
399 einfo "Initializing the database ..."
401 if [[ ${EUID} == 0 ]] ; then
402 su postgres -c "${EROOT%/}/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -D \"${DATA_DIR}\" ${PG_INITDB_OPTS}"
404 "${EROOT%/}"/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -U postgres -D "${DATA_DIR}" ${PG_INITDB_OPTS}
407 if [[ "${DATA_DIR%/}" != "${PGDATA%/}" ]] ; then
408 mv "${DATA_DIR%/}"/{pg_{hba,ident},postgresql}.conf "${PGDATA}"
409 ln -s "${PGDATA%/}"/{pg_{hba,ident},postgresql}.conf "${DATA_DIR%/}"
412 # unix_socket_directory has no effect in postgresql.conf as it's
413 # overridden in the initscript
414 sed '/^#unix_socket_directories/,+1d' -i "${PGDATA%/}"/postgresql.conf
416 cat <<- EOF >> "${PGDATA%/}"/postgresql.conf
417 # This is here because of https://bugs.gentoo.org/show_bug.cgi?id=518522
418 # On the off-chance that you might need to work with UTF-8 encoded
419 # characters in PL/Perl
420 plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'
423 einfo "The autovacuum function, which was in contrib, has been moved to the main"
424 einfo "PostgreSQL functions starting with 8.1, and starting with 8.4 is now enabled"
425 einfo "by default. You can disable it in the cluster's:"
426 einfo " ${PGDATA%/}/postgresql.conf"
428 if ! use systemd; then
429 einfo "The PostgreSQL server, by default, will log events to:"
430 einfo " ${DATA_DIR%/}/postmaster.log"
434 einfo "The location of the configuration files have moved to:"
436 einfo "To start the server:"
437 einfo " pg_ctl start -D ${DATA_DIR} -o '-D ${PGDATA} --data-directory=${DATA_DIR}'"
439 einfo " pg_ctl stop -D ${DATA_DIR}"
441 einfo "Or move the configuration files back:"
442 einfo "mv ${PGDATA}*.conf ${DATA_DIR}"
443 elif use systemd; then
444 einfo "You should use the 'postgresql-${SLOT}.service' unit to run PostgreSQL"
445 einfo "instead of 'pg_ctl'."
447 einfo "You should use the '${EROOT%/}/etc/init.d/postgresql-${SLOT}' script to run PostgreSQL"
448 einfo "instead of 'pg_ctl'."
453 if use server && [[ ${UID} -ne 0 ]] ; then
456 einfo "If you think other tests besides the regression tests are necessary, please"
457 einfo "submit a bug including a patch for this ebuild to enable them."
460 ewarn 'Tests cannot be run without the "server" use flag enabled.'
461 [[ ${UID} -eq 0 ]] || \
462 ewarn 'Tests cannot be run as root. Enable "userpriv" in FEATURES.'