1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_{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 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~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 kerberos kernel_linux ldap libressl nls pam perl
28 -pg_legacytimestamp python +readline selinux +server systemd ssl
29 static-libs tcl threads uuid xml zlib"
31 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
34 >=app-eselect/eselect-postgresql-2.0
37 kerberos? ( virtual/krb5 )
38 ldap? ( net-nds/openldap )
40 perl? ( >=dev-lang/perl-5.8:= )
41 python? ( ${PYTHON_DEPS} )
42 readline? ( sys-libs/readline:0= )
44 !libressl? ( >=dev-libs/openssl-0.9.6-r1:0= )
45 libressl? ( dev-libs/libressl:= )
47 server? ( systemd? ( sys-apps/systemd ) )
48 tcl? ( >=dev-lang/tcl-8:0= )
49 xml? ( dev-libs/libxml2 dev-libs/libxslt )
50 zlib? ( sys-libs/zlib )
53 # uuid flags -- depend on sys-apps/util-linux for Linux libcs, or if no
54 # supported libc in use depend on dev-libs/ossp-uuid. For BSD systems,
55 # the libc includes UUID functions.
56 UTIL_LINUX_LIBC=( elibc_{glibc,uclibc,musl} )
57 BSD_LIBC=( elibc_{Free,Net,Open}BSD )
61 while [[ ${#} -gt 1 ]]; do
66 echo "${front}${1}${back}"
69 IUSE+=" ${UTIL_LINUX_LIBC[@]} ${BSD_LIBC[@]}"
72 ${UTIL_LINUX_LIBC[@]/%/? ( sys-apps/util-linux )}
73 $(nest_usedep ${UTIL_LINUX_LIBC[@]/#/!} ${BSD_LIBC[@]/#/!} dev-libs/ossp-uuid)
77 !!<sys-apps/sandbox-2.0
80 nls? ( sys-devel/gettext )
81 xml? ( virtual/pkgconfig )
85 !dev-db/postgresql-docs:${SLOT}
86 !dev-db/postgresql-base:${SLOT}
87 !dev-db/postgresql-server:${SLOT}
88 selinux? ( sec-policy/selinux-postgresql )
92 use server && CONFIG_CHECK="~SYSVIPC" linux-info_pkg_setup
95 enewuser postgres 70 /bin/sh /var/lib/postgresql postgres
97 use python && python-single-r1_pkg_setup
101 # Work around PPC{,64} compilation bug where bool is already defined
102 sed '/#ifndef __cplusplus/a #undef bool' -i src/include/c.h || die
104 # Set proper run directory
105 sed "s|\(PGSOCKET_DIR\s\+\)\"/tmp\"|\1\"${EPREFIX}/run/postgresql\"|" \
106 -i src/include/pg_config_manual.h || die
108 # Rely on $PATH being in the proper order so that the correct
109 # install program is used for modules utilizing PGXS in both
110 # hardened and non-hardened environments. (Bug #528786)
111 sed 's/@install_bin@/install -c/' -i src/Makefile.global.in || die
113 use server || eapply "${FILESDIR}/${PN}-${SLOT}.3-no-server.patch"
116 sed -e "s/\(#define PGSQL_PAM_SERVICE \"postgresql\)/\1-${SLOT}/" \
117 -i src/backend/libpq/auth.c || \
118 die 'PGSQL_PAM_SERVICE rename failed.'
126 *-darwin*|*-solaris*)
127 use nls && append-libs intl
131 export LDFLAGS_SL="${LDFLAGS}"
132 export LDFLAGS_EX="${LDFLAGS}"
134 local PO="${EPREFIX}"
136 local i uuid_config=""
138 for i in ${UTIL_LINUX_LIBC[@]}; do
139 use ${i} && uuid_config="--with-uuid=e2fs"
141 for i in ${BSD_LIBC[@]}; do
142 use ${i} && uuid_config="--with-uuid=bsd"
144 [[ -z $uuid_config ]] && uuid_config="--with-uuid=ossp"
148 --prefix="${PO}/usr/$(get_libdir)/postgresql-${SLOT}" \
149 --datadir="${PO}/usr/share/postgresql-${SLOT}" \
150 --docdir="${PO}/usr/share/doc/${PF}" \
151 --includedir="${PO}/usr/include/postgresql-${SLOT}" \
152 --mandir="${PO}/usr/share/postgresql-${SLOT}/man" \
153 --sysconfdir="${PO}/etc/postgresql-${SLOT}" \
154 --with-system-tzdata="${PO}/usr/share/zoneinfo" \
155 $(use_enable !alpha spinlocks) \
156 $(use_enable !pg_legacytimestamp integer-datetimes) \
157 $(use_enable debug) \
158 $(use_enable threads thread-safety) \
159 $(use_with kerberos gssapi) \
164 $(use_with readline) \
165 $(use_with ssl openssl) \
166 $(usex server "$(use_with systemd)" '--without-systemd') \
169 $(use_with xml libxml) \
170 $(use_with xml libxslt) \
172 $(use_enable nls nls "'$(l10n_get_locales)'")
181 emake DESTDIR="${D}" install
182 emake DESTDIR="${D}" install -C contrib
184 dodoc README HISTORY doc/{TODO,bug.template}
186 # man pages are already built, but if we have the target make them,
187 # they'll be generated from source before being installed so we
188 # manually install man pages.
189 # We use ${SLOT} instead of doman for postgresql.eselect
190 insinto /usr/share/postgresql-${SLOT}/man/
191 doins -r doc/src/sgml/man{1,3,7}
192 if ! use server; then
193 # Remove man pages for non-existent binaries
194 for m in {initdb,pg_{controldata,ctl,resetxlog},post{gres,master}}; do
195 rm "${ED}/usr/share/postgresql-${SLOT}/man/man1/${m}.1"
198 docompress /usr/share/postgresql-${SLOT}/man/man{1,3,7}
200 # Create slot specific man pages
201 local bn f mansec slotted_name
202 for mansec in 1 3 7 ; do
203 local rel_manpath="../../postgresql-${SLOT}/man/man${mansec}"
205 mkdir -p "${ED}"/usr/share/man/man${mansec} || die "making man dir"
206 pushd "${ED}"/usr/share/man/man${mansec} > /dev/null || die "pushd failed"
208 for f in "${ED}/usr/share/postgresql-${SLOT}/man/man${mansec}"/* ; do
209 bn=$(basename "${f}")
210 slotted_name=${bn%.${mansec}}${SLOT/.}.${mansec}
213 echo ".so ${rel_manpath}/SELECT.7" > ${slotted_name}
216 echo ".so ${rel_manpath}/${bn}" > ${slotted_name}
224 insinto /etc/postgresql-${SLOT}
225 newins src/bin/psql/psqlrc.sample psqlrc
227 # Don't delete libpg{port,common}.a (Bug #571046). They're always
228 # needed by extensions utilizing PGXS.
230 find "${ED}" -name '*.a' ! -name libpgport.a ! -name libpgcommon.a \
234 for f in $(find "${ED}/usr/$(get_libdir)/postgresql-${SLOT}/bin" \
235 -mindepth 1 -maxdepth 1)
237 bn=$(basename "${f}")
238 # Temporarily tack on tmp to workaround a file collision
239 # issue. This is only necessary for 9.7 and earlier. 10 never
241 dosym "../$(get_libdir)/postgresql-${SLOT}/bin/${bn}" \
242 "/usr/bin/${bn}${SLOT/.}tmp"
247 dodoc doc/src/sgml/html/*
250 dodoc doc/src/sgml/*.{sgml,dsl}
254 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
255 "${FILESDIR}/${PN}.confd-9.3" | newconfd - ${PN}-${SLOT}
257 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
258 "${FILESDIR}/${PN}.init-9.3-r1" | newinitd - ${PN}-${SLOT}
261 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
262 "${FILESDIR}/${PN}.service-9.6-r1" | \
263 systemd_newunit - ${PN}-${SLOT}.service
264 systemd_newtmpfilesd "${FILESDIR}"/${PN}.tmpfiles ${PN}-${SLOT}.conf
267 newbin "${FILESDIR}"/${PN}-check-db-dir ${PN}-${SLOT}-check-db-dir
269 use pam && pamd_mimic system-auth ${PN}-${SLOT} auth account session
272 keepdir /run/postgresql
273 fperms 1775 /run/postgresql
279 # Find all of the slot-specific symlinks, if any, in /usr/bin (e.g.,
280 # /usr/bin/psql96). They may have been created by the
281 # postgresql.eselect module, but they're handled within this ebuild
282 # now. It's alright if we momentarily delete /usr/bin/psql as it
283 # will be recreated by the eselect module in pkg_ppostinst(). This
284 # is only necessary for 9.7 and earlier. 10 and later were never
285 # handled in this manner.
287 if type -p realpath > /dev/null; then
288 canonicalise=realpath
289 elif type -p readlink > /dev/null; then
290 canonicalise='readlink -f'
292 # can't die, subshell
293 die "No readlink nor realpath found, cannot canonicalise"
297 # First remove any symlinks in /usr/bin that may have been created
299 for l in $(find "${ROOT}/usr/bin" -mindepth 1 -maxdepth 1 -type l) ; do
300 if [[ $(${canonicalise} "${l}") == *postgresql-${SLOT}* ]] ; then
301 rm "${l}" || ewarn "Couldn't remove ${l}"
305 # Then move the symlinks created by the ebuild to their proper place.
306 for l in "${ED}"/usr/bin/*tmp ; do
307 mv "${l}" "${l%tmp}" \
308 || ewarn "Couldn't rename $(basename ${l}) to $(basename ${l%tmp})"
313 use server && use systemd && systemd_tmpfiles_create ${PN}-${SLOT}.conf
314 postgresql-config update
316 elog "If you need a global psqlrc-file, you can place it in:"
317 elog " ${EROOT}/etc/postgresql-${SLOT}/"
321 elog "Gentoo specific documentation:"
322 elog "https://wiki.gentoo.org/wiki/PostgreSQL"
324 elog "Official documentation:"
325 elog "https://www.postgresql.org/docs/${SLOT}/static/index.html"
327 elog "The default location of the Unix-domain socket is:"
328 elog " ${EROOT}/run/postgresql/"
330 elog "Before initializing the database, you may want to edit PG_INITDB_OPTS"
331 elog "so that it contains your preferred locale in:"
332 elog " ${EROOT}/etc/conf.d/postgresql-${SLOT}"
334 elog "Then, execute the following command to setup the initial database"
336 elog " emerge --config =${CATEGORY}/${PF}"
341 if use server && [[ -z ${REPLACED_BY_VERSION} ]] ; then
342 ewarn "Have you dumped and/or migrated the ${SLOT} database cluster?"
343 ewarn "\thttps://wiki.gentoo.org/wiki/PostgreSQL/QuickStart#Migrating_PostgreSQL"
345 ebegin "Resuming removal in 10 seconds (Control-C to cancel)"
352 postgresql-config update
356 use server || die "USE flag 'server' not enabled. Nothing to configure."
358 [[ -f "${EROOT}/etc/conf.d/postgresql-${SLOT}" ]] \
359 && source "${EROOT}/etc/conf.d/postgresql-${SLOT}"
360 [[ -z "${PGDATA}" ]] && PGDATA="${EROOT}/etc/postgresql-${SLOT}/"
361 [[ -z "${DATA_DIR}" ]] \
362 && DATA_DIR="${EROOT}/var/lib/postgresql/${SLOT}/data"
364 # environment.bz2 may not contain the same locale as the current system
365 # locale. Unset and source from the current system locale.
366 if [ -f "${EROOT}/etc/env.d/02locale" ]; then
375 source "${EROOT}/etc/env.d/02locale"
376 [ -n "${LANG}" ] && export LANG
377 [ -n "${LC_CTYPE}" ] && export LC_CTYPE
378 [ -n "${LC_NUMERIC}" ] && export LC_NUMERIC
379 [ -n "${LC_TIME}" ] && export LC_TIME
380 [ -n "${LC_COLLATE}" ] && export LC_COLLATE
381 [ -n "${LC_MONETARY}" ] && export LC_MONETARY
382 [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES
383 [ -n "${LC_ALL}" ] && export LC_ALL
386 einfo "You can modify the paths and options passed to initdb by editing:"
387 einfo " ${EROOT}/etc/conf.d/postgresql-${SLOT}"
389 einfo "Information on options that can be passed to initdb are found at:"
390 einfo " https://www.postgresql.org/docs/${SLOT}/static/creating-cluster.html"
391 einfo " https://www.postgresql.org/docs/${SLOT}/static/app-initdb.html"
393 einfo "PG_INITDB_OPTS is currently set to:"
394 if [[ -z "${PG_INITDB_OPTS}" ]] ; then
397 einfo " ${PG_INITDB_OPTS}"
400 einfo "Configuration files will be installed to:"
403 einfo "The database cluster will be created in:"
407 ebegin "Continuing initialization in 5 seconds (Control-C to cancel)"
411 if [ -n "$(ls -A ${DATA_DIR} 2> /dev/null)" ] ; then
412 eerror "The given directory, '${DATA_DIR}', is not empty."
413 eerror "Modify DATA_DIR to point to an empty directory."
414 die "${DATA_DIR} is not empty."
417 einfo "Creating the data directory ..."
418 if [[ ${EUID} == 0 ]] ; then
419 mkdir -p "${DATA_DIR}"
420 chown -Rf postgres:postgres "${DATA_DIR}"
421 chmod 0700 "${DATA_DIR}"
424 einfo "Initializing the database ..."
426 if [[ ${EUID} == 0 ]] ; then
427 su postgres -c "${EROOT}/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -D \"${DATA_DIR}\" ${PG_INITDB_OPTS}"
429 "${EROOT}"/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -U postgres -D "${DATA_DIR}" ${PG_INITDB_OPTS}
432 if [[ "${DATA_DIR%/}" != "${PGDATA%/}" ]] ; then
433 mv "${DATA_DIR%/}"/{pg_{hba,ident},postgresql}.conf "${PGDATA}"
434 ln -s "${PGDATA%/}"/{pg_{hba,ident},postgresql}.conf "${DATA_DIR%/}"
437 # unix_socket_directory has no effect in postgresql.conf as it's
438 # overridden in the initscript
439 sed '/^#unix_socket_directories/,+1d' -i "${PGDATA%/}"/postgresql.conf
441 cat <<- EOF >> "${PGDATA%/}"/postgresql.conf
442 # This is here because of https://bugs.gentoo.org/show_bug.cgi?id=518522
443 # On the off-chance that you might need to work with UTF-8 encoded
444 # characters in PL/Perl
445 plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'
448 einfo "The autovacuum function, which was in contrib, has been moved to the main"
449 einfo "PostgreSQL functions starting with 8.1, and starting with 8.4 is now enabled"
450 einfo "by default. You can disable it in the cluster's:"
451 einfo " ${PGDATA%/}/postgresql.conf"
453 if ! use systemd; then
454 einfo "The PostgreSQL server, by default, will log events to:"
455 einfo " ${DATA_DIR%/}/postmaster.log"
459 einfo "The location of the configuration files have moved to:"
461 einfo "To start the server:"
462 einfo " pg_ctl start -D ${DATA_DIR} -o '-D ${PGDATA} --data-directory=${DATA_DIR}'"
464 einfo " pg_ctl stop -D ${DATA_DIR}"
466 einfo "Or move the configuration files back:"
467 einfo "mv ${PGDATA}*.conf ${DATA_DIR}"
468 elif use systemd; then
469 einfo "You should use the 'postgresql-${SLOT}.service' unit to run PostgreSQL"
470 einfo "instead of 'pg_ctl'."
472 einfo "You should use the '${EROOT}/etc/init.d/postgresql-${SLOT}' script to run PostgreSQL"
473 einfo "instead of 'pg_ctl'."
478 if use server && [[ ${UID} -ne 0 ]] ; then
481 einfo "If you think other tests besides the regression tests are necessary, please"
482 einfo "submit a bug including a patch for this ebuild to enable them."
485 ewarn 'Tests cannot be run without the "server" use flag enabled.'
486 [[ ${UID} -eq 0 ]] || \
487 ewarn 'Tests cannot be run as root. Enable "userpriv" in FEATURES.'