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="http://www.postgresql.org/"
27 IUSE="debug doc icu kerberos kernel_linux ldap libressl llvm nls pam
28 perl 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 )
45 perl? ( >=dev-lang/perl-5.8:= )
46 python? ( ${PYTHON_DEPS} )
47 readline? ( sys-libs/readline:0= )
48 server? ( systemd? ( sys-apps/systemd ) )
50 !libressl? ( >=dev-libs/openssl-0.9.6-r1:0= )
51 libressl? ( dev-libs/libressl:= )
53 tcl? ( >=dev-lang/tcl-8:0= )
54 xml? ( dev-libs/libxml2 dev-libs/libxslt )
55 zlib? ( sys-libs/zlib )
58 # uuid flags -- depend on sys-apps/util-linux for Linux libcs, or if no
59 # supported libc in use depend on dev-libs/ossp-uuid. For BSD systems,
60 # the libc includes UUID functions.
61 UTIL_LINUX_LIBC=( elibc_{glibc,uclibc,musl} )
62 BSD_LIBC=( elibc_{Free,Net,Open}BSD )
66 while [[ ${#} -gt 1 ]]; do
71 echo "${front}${1}${back}"
74 IUSE+=" ${UTIL_LINUX_LIBC[@]} ${BSD_LIBC[@]}"
77 ${UTIL_LINUX_LIBC[@]/%/? ( sys-apps/util-linux )}
78 $(nest_usedep ${UTIL_LINUX_LIBC[@]/#/!} ${BSD_LIBC[@]/#/!} dev-libs/ossp-uuid)
82 !!<sys-apps/sandbox-2.0
85 nls? ( sys-devel/gettext )
86 xml? ( virtual/pkgconfig )
90 !dev-db/postgresql-docs:${SLOT}
91 !dev-db/postgresql-base:${SLOT}
92 !dev-db/postgresql-server:${SLOT}
93 selinux? ( sec-policy/selinux-postgresql )
97 use server && CONFIG_CHECK="~SYSVIPC" linux-info_pkg_setup
100 enewuser postgres 70 /bin/sh /var/lib/postgresql postgres
102 use python && python-single-r1_pkg_setup
106 # Set proper run directory
107 sed "s|\(PGSOCKET_DIR\s\+\)\"/tmp\"|\1\"${EPREFIX}/run/postgresql\"|" \
108 -i src/include/pg_config_manual.h || die
110 # Rely on $PATH being in the proper order so that the correct
111 # install program is used for modules utilizing PGXS in both
112 # hardened and non-hardened environments. (Bug #528786)
113 sed 's/@install_bin@/install -c/' -i src/Makefile.global.in || die
115 use server || eapply "${FILESDIR}/${PN}-12.1-no-server.patch"
118 sed "s/\(#define PGSQL_PAM_SERVICE \"postgresql\)/\1-${SLOT}/" \
119 -i src/backend/libpq/auth.c || \
120 die 'PGSQL_PAM_SERVICE rename failed.'
128 *-darwin*|*-solaris*)
129 use nls && append-libs intl
133 export LDFLAGS_SL="${LDFLAGS}"
134 export LDFLAGS_EX="${LDFLAGS}"
136 local PO="${EPREFIX}"
138 local i uuid_config=""
140 for i in ${UTIL_LINUX_LIBC[@]}; do
141 use ${i} && uuid_config="--with-uuid=e2fs"
143 for i in ${BSD_LIBC[@]}; do
144 use ${i} && uuid_config="--with-uuid=bsd"
146 [[ -z $uuid_config ]] && uuid_config="--with-uuid=ossp"
150 --prefix="${PO}/usr/$(get_libdir)/postgresql-${SLOT}" \
151 --datadir="${PO}/usr/share/postgresql-${SLOT}" \
152 --docdir="${PO}/usr/share/doc/${PF}" \
153 --includedir="${PO}/usr/include/postgresql-${SLOT}" \
154 --mandir="${PO}/usr/share/postgresql-${SLOT}/man" \
155 --sysconfdir="${PO}/etc/postgresql-${SLOT}" \
156 --with-system-tzdata="${PO}/usr/share/zoneinfo" \
157 $(use_enable !alpha spinlocks) \
158 $(use_enable debug) \
159 $(use_enable threads thread-safety) \
161 $(use_with kerberos gssapi) \
167 $(use_with readline) \
168 $(use_with ssl openssl) \
169 $(usex server "$(use_with systemd)" '--without-systemd') \
172 $(use_with xml libxml) \
173 $(use_with xml libxslt) \
175 $(use_enable nls nls "'$(l10n_get_locales)'")
184 emake DESTDIR="${D}" install
185 emake DESTDIR="${D}" install -C contrib
189 # man pages are already built, but if we have the target make them,
190 # they'll be generated from source before being installed so we
191 # manually install man pages.
192 # We use ${SLOT} instead of doman for postgresql.eselect
193 insinto /usr/share/postgresql-${SLOT}/man/
194 doins -r doc/src/sgml/man{1,3,7}
195 if ! use server; then
196 # Remove man pages for non-existent binaries
199 pg_{archivecleanup,controldata,ctl,resetwal,rewind,standby}
200 pg_{test_{fsync,timing},upgrade,waldump}
203 for m in ${serverman[@]} ; do
204 rm "${ED}/usr/share/postgresql-${SLOT}/man/man1/${m}.1"
207 docompress /usr/share/postgresql-${SLOT}/man/man{1,3,7}
209 # Create slot specific man pages
210 local bn f mansec slotted_name
211 for mansec in 1 3 7 ; do
212 local rel_manpath="../../postgresql-${SLOT}/man/man${mansec}"
214 mkdir -p "${ED}"/usr/share/man/man${mansec} || die "making man dir"
215 pushd "${ED}"/usr/share/man/man${mansec} > /dev/null || die "pushd failed"
217 for f in "${ED}/usr/share/postgresql-${SLOT}/man/man${mansec}"/* ; do
218 bn=$(basename "${f}")
219 slotted_name=${bn%.${mansec}}${SLOT}.${mansec}
222 echo ".so ${rel_manpath}/SELECT.7" > ${slotted_name}
225 echo ".so ${rel_manpath}/${bn}" > ${slotted_name}
233 insinto /etc/postgresql-${SLOT}
234 newins src/bin/psql/psqlrc.sample psqlrc
236 # Don't delete libpg{port,common}.a (Bug #571046). They're always
237 # needed by extensions utilizing PGXS.
239 find "${ED}" -name '*.a' ! -name libpgport.a ! -name libpgcommon.a \
242 # Make slot specific links to programs
244 for f in $(find "${ED}/usr/$(get_libdir)/postgresql-${SLOT}/bin" \
245 -mindepth 1 -maxdepth 1)
247 bn=$(basename "${f}")
248 dosym "../$(get_libdir)/postgresql-${SLOT}/bin/${bn}" \
249 "/usr/bin/${bn}${SLOT/.}"
254 dodoc doc/src/sgml/html/*
258 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
259 "${FILESDIR}/${PN}.confd-9.3" | newconfd - ${PN}-${SLOT}
261 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
262 "${FILESDIR}/${PN}.init-9.3-r1" | newinitd - ${PN}-${SLOT}
265 sed -e "s|@SLOT@|${SLOT}|g" -e "s|@LIBDIR@|$(get_libdir)|g" \
266 "${FILESDIR}/${PN}.service-9.6-r1" | \
267 systemd_newunit - ${PN}-${SLOT}.service
268 newbin "${FILESDIR}"/${PN}-check-db-dir ${PN}-${SLOT}-check-db-dir
269 systemd_newtmpfilesd "${FILESDIR}"/${PN}.tmpfiles ${PN}-${SLOT}.conf
272 use pam && pamd_mimic system-auth ${PN}-${SLOT} auth account session
275 keepdir /run/postgresql
276 fperms 1775 /run/postgresql
282 use server && use systemd && systemd_tmpfiles_create ${PN}-${SLOT}.conf
283 postgresql-config update
285 elog "If you need a global psqlrc-file, you can place it in:"
286 elog " ${EROOT}/etc/postgresql-${SLOT}/"
290 elog "Gentoo specific documentation:"
291 elog "https://wiki.gentoo.org/wiki/PostgreSQL"
293 elog "Official documentation:"
294 elog "http://www.postgresql.org/docs/${SLOT}/static/index.html"
296 elog "The default location of the Unix-domain socket is:"
297 elog " ${EROOT}/run/postgresql/"
299 elog "Before initializing the database, you may want to edit PG_INITDB_OPTS"
300 elog "so that it contains your preferred locale in:"
301 elog " ${EROOT}/etc/conf.d/postgresql-${SLOT}"
303 elog "Then, execute the following command to setup the initial database"
305 elog " emerge --config =${CATEGORY}/${PF}"
307 if [[ -n ${REPLACING_VERSIONS} ]] ; then
308 ewarn "If your system is using 'pg_stat_statements' and you are running a"
309 ewarn "version of PostgreSQL ${SLOT}, we advise that you execute"
310 ewarn "the following command after upgrading:"
312 ewarn "ALTER EXTENSION pg_stat_statements UPDATE;"
318 if use server && [[ -z ${REPLACED_BY_VERSION} ]] ; then
319 ewarn "Have you dumped and/or migrated the ${SLOT} database cluster?"
320 ewarn "\thttps://wiki.gentoo.org/wiki/PostgreSQL/QuickStart#Migrating_PostgreSQL"
322 ebegin "Resuming removal in 10 seconds (Control-C to cancel)"
329 postgresql-config update
333 use server || die "USE flag 'server' not enabled. Nothing to configure."
335 [[ -f "${EROOT}/etc/conf.d/postgresql-${SLOT}" ]] \
336 && source "${EROOT}/etc/conf.d/postgresql-${SLOT}"
337 [[ -z "${PGDATA}" ]] && PGDATA="${EROOT}/etc/postgresql-${SLOT}/"
338 [[ -z "${DATA_DIR}" ]] \
339 && DATA_DIR="${EROOT}/var/lib/postgresql/${SLOT}/data"
341 # environment.bz2 may not contain the same locale as the current system
342 # locale. Unset and source from the current system locale.
343 if [ -f "${EROOT}/etc/env.d/02locale" ]; then
352 source "${EROOT}/etc/env.d/02locale"
353 [ -n "${LANG}" ] && export LANG
354 [ -n "${LC_CTYPE}" ] && export LC_CTYPE
355 [ -n "${LC_NUMERIC}" ] && export LC_NUMERIC
356 [ -n "${LC_TIME}" ] && export LC_TIME
357 [ -n "${LC_COLLATE}" ] && export LC_COLLATE
358 [ -n "${LC_MONETARY}" ] && export LC_MONETARY
359 [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES
360 [ -n "${LC_ALL}" ] && export LC_ALL
363 einfo "You can modify the paths and options passed to initdb by editing:"
364 einfo " ${EROOT}/etc/conf.d/postgresql-${SLOT}"
366 einfo "Information on options that can be passed to initdb are found at:"
367 einfo " http://www.postgresql.org/docs/${SLOT}/static/creating-cluster.html"
368 einfo " http://www.postgresql.org/docs/${SLOT}/static/app-initdb.html"
370 einfo "PG_INITDB_OPTS is currently set to:"
371 if [[ -z "${PG_INITDB_OPTS}" ]] ; then
374 einfo " ${PG_INITDB_OPTS}"
377 einfo "Configuration files will be installed to:"
380 einfo "The database cluster will be created in:"
384 ebegin "Continuing initialization in 5 seconds (Control-C to cancel)"
388 if [ -n "$(ls -A ${DATA_DIR} 2> /dev/null)" ] ; then
389 eerror "The given directory, '${DATA_DIR}', is not empty."
390 eerror "Modify DATA_DIR to point to an empty directory."
391 die "${DATA_DIR} is not empty."
394 einfo "Creating the data directory ..."
395 if [[ ${EUID} == 0 ]] ; then
396 mkdir -p "$(dirname ${DATA_DIR%/})" || die "Couldn't parent dirs"
397 mkdir -m 0700 "${DATA_DIR%/}" || die "Couldn't make DATA_DIR"
398 chown -h postgres:postgres "${DATA_DIR%/}" || die "Couldn't chown"
401 einfo "Initializing the database ..."
403 if [[ ${EUID} == 0 ]] ; then
404 su postgres -c "${EROOT}/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -D \"${DATA_DIR}\" ${PG_INITDB_OPTS}"
406 "${EROOT}"/usr/$(get_libdir)/postgresql-${SLOT}/bin/initdb -U postgres -D "${DATA_DIR}" ${PG_INITDB_OPTS}
409 if [[ "${DATA_DIR%/}" != "${PGDATA%/}" ]] ; then
410 mv "${DATA_DIR%/}"/{pg_{hba,ident},postgresql}.conf "${PGDATA}"
411 ln -s "${PGDATA%/}"/{pg_{hba,ident},postgresql}.conf "${DATA_DIR%/}"
414 # unix_socket_directory has no effect in postgresql.conf as it's
415 # overridden in the initscript
416 sed '/^#unix_socket_directories/,+1d' -i "${PGDATA%/}"/postgresql.conf
418 cat <<- EOF >> "${PGDATA%/}"/postgresql.conf
419 # This is here because of https://bugs.gentoo.org/show_bug.cgi?id=518522
420 # On the off-chance that you might need to work with UTF-8 encoded
421 # characters in PL/Perl
422 plperl.on_init = 'use utf8; use re; package utf8; require "utf8_heavy.pl";'
425 einfo "The autovacuum function, which was in contrib, has been moved to the main"
426 einfo "PostgreSQL functions starting with 8.1, and starting with 8.4 is now enabled"
427 einfo "by default. You can disable it in the cluster's:"
428 einfo " ${PGDATA%/}/postgresql.conf"
430 if ! use systemd; then
431 einfo "The PostgreSQL server, by default, will log events to:"
432 einfo " ${DATA_DIR%/}/postmaster.log"
436 einfo "The location of the configuration files have moved to:"
438 einfo "To start the server:"
439 einfo " pg_ctl start -D ${DATA_DIR} -o '-D ${PGDATA} --data-directory=${DATA_DIR}'"
441 einfo " pg_ctl stop -D ${DATA_DIR}"
443 einfo "Or move the configuration files back:"
444 einfo "mv ${PGDATA}*.conf ${DATA_DIR}"
445 elif use systemd; then
446 einfo "You should use the 'postgresql-${SLOT}.service' unit to run PostgreSQL"
447 einfo "instead of 'pg_ctl'."
449 einfo "You should use the '${EROOT}/etc/init.d/postgresql-${SLOT}' script to run PostgreSQL"
450 einfo "instead of 'pg_ctl'."
455 if use server && [[ ${UID} -ne 0 ]] ; then
458 einfo "If you think other tests besides the regression tests are necessary, please"
459 einfo "submit a bug including a patch for this ebuild to enable them."
462 ewarn 'Tests cannot be run without the "server" use flag enabled.'
463 [[ ${UID} -eq 0 ]] || \
464 ewarn 'Tests cannot be run as root. Enable "userpriv" in FEATURES.'