File pgpool-II.spec of Package pgpool-II

#
# spec file for package pgpool-II
#
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

%if ! %{defined _fillupdir}
%define _fillupdir %{_localstatedir}/adm/fillup-templates/
%endif
%define pg_name      @BUILD_FLAVOR@%{nil}
%define ext_name    pgpool-II
%{pg_version_from_name}

%define defaultpg   postgresql14
%define pkg_home   %{_var}/run/pgpool
%define pkg_logdir %{_var}/log/pgpool
%define pkg_user   pgpool
%define pkg_group  pgpool
%define pgpool_sysconfdir   %{_sysconfdir}/pgpool-II
%define SuSeFirewall_services_dir %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services
%define pgpool_version 4.6.0
%define pgpooladmin_version 4.2.0
%if "%{?pg_name}" == ""
Name:           pgpool-II
%global mainpackage 1
%global pg_name %{defaultpg}
%else
Name:           %{?pg_name:%{pg_name}-}pgpool-II
%global mainpackage 0
%endif

Version:        4.6.0
Release:        0
#
Summary:        A Connection Pooling/Replication Server for PostgreSQL
#
License:        PostgreSQL
Group:          Productivity/Databases/Tools
#
Url:            https://www.pgpool.net/
Source:         https://www.pgpool.net/mediawiki/images/%{ext_name}-%{pgpool_version}.tar.gz
Source1:        pgpool-II.init
Source2:        pgpool-II.sysconfig
Source3:        https://www.pgpool.net/mediawiki/images/pgpoolAdmin-%{pgpooladmin_version}.tar.gz
Source4:        pgpool-II.service
Source5:        pgpool-II.tmpfiles.d
Source6:        series
Patch0:         pgpool-II_conf.patch
Patch1:         pgpool-II-3.6.1_implicit.patch
BuildRequires:  libmemcached-devel
BuildRequires:  libopenssl-devel
BuildRequires:  pam-devel
# mainpackage
BuildRequires:  postgresql-server-devel-noarch
%if 0%{?mainpackage}
BuildRequires:  %{defaultpg}-server-devel
BuildRequires:  %{defaultpg}-server
BuildRequires:  pkgconfig(systemd)
%{?systemd_ordering}
PreReq:         %fillup_prereq
PreReq:         pwdutils
#/ mainpackage
%else
# subpackages
BuildRequires:  %{ext_name}-devel
BuildRequires:  %{pg_name}-llvmjit-devel
#/ subpackages
Provides:       user(pgpool)
Provides:       group(pgpool)
%endif
#

%description
pgpool-II is a middleware that works between PostgreSQL servers and a PostgreSQL
database client. It provides the following features.

    * Connection Pooling

      pgpool-II saves connections to the PostgreSQL servers, and reuse them
      whenever a new connection with the same properties (i.e. username, database,
      protocol version) comes in. It reduces connection overhead, and improves
      system's overall throughput.

    * Replication

      pgpool-II can manage multiple PostgreSQL servers. Using the replication
      function enables creating a realtime backup on 2 or more physical disks,
      so that the service can continue without stopping servers in case of a disk
      failure.

    * Load Balance

      If a database is replicated, executing a SELECT query on any server will
      return the same result. pgpool-II takes an advantage of the replication
      feature to reduce the load on each PostgreSQL server by distributing SELECT
      queries among multiple servers, improving system's overall throughput. At
      best, performance improves proportionally to the number of PostgreSQL servers.
      Load balance works best in a situation where there are a lot of users executing
      many queries at the same time.

    * Limiting Exceeding Connections

      There is a limit on the maximum number of concurrent connections with PostgreSQL,
      and connections are rejected after this many connections. Setting the maximum
      number of connections, however, increases resource consumption and affect system
      performance. pgpool-II also has a limit on the maximum number of connections, but
      extra connections will be queued instead of returning an error immediately.

    * Parallel Query

      Using the parallel query function, data can be divided among the multiple servers,
      so that a query can be executed on all the servers concurrently to reduce the
      overall execution time. Parallel query works the best when searching large-scale
      data.

pgpool-II talks PostgreSQL's backend and frontend protocol, and relays a connection
between them. Therefore, a database application (frontend) thinks that pgpool-II is
the actual PostgreSQL server, and the server (backend) sees pgpool-II as one of its
clients. Because pgpool-II is transparent to both the server and the client, an
existing database application can be used with pgpool-II almost without a change to
its sources.

%if ! 0%{?mainpackage}
This package holds the %{pg_name} extensions for pgpool-II support.
%else
%define _library_name libpcp2

%package -n %{_library_name}
Summary:        The shared library from pgpool-II
Group:          Development/Libraries/C and C++

%description -n %{_library_name}
The shared library from pgpool-II.

%package devel
Summary:        Development Files for pgpool-II
Group:          Development/Libraries/C and C++
Requires:       %{_library_name} = %{pgpool_version}

%description devel
The development files for pgpool-II.

%package -n pgpoolAdmin
Version:        %{pgpooladmin_version}
#
Summary:        Administration web frontend for pgpool-II
Group:          Productivity/Databases/Tools

%description -n pgpoolAdmin
pgpool-II is a middleware that works between PostgreSQL servers and a PostgreSQL
database client. It provides the following features.

This package holds a webfrontend for the administration of pgpool-II.
%endif

%prep
%autosetup -p1 -a 3 -n %{ext_name}-%{pgpool_version}

%if 0%{?mainpackage}
%build
export PATH="$PATH:/usr/lib/%{pg_name}/bin"
%configure \
  --with-openssl \
  --with-pam \
  --enable-shared=yes \
  --enable-static=no  \
  --with-gnu-ld \
  --with-pic \
  --bindir=%{_sbindir} \
  --sysconfdir=%{pgpool_sysconfdir} \
  --with-memcached=/usr/include

make %{?_smp_mflags}

%check
make check %{?_smp_mflags}

%install
make DESTDIR=%{buildroot} install %{?_smp_mflags}
#
for i in %{buildroot}%{pgpool_sysconfdir}/*sample ; do
  mv -v $i ${i%.sample}
done
touch %{buildroot}%{pgpool_sysconfdir}/pool_passwd
#
chmod -Rv o= %{buildroot}%{pgpool_sysconfdir}
#
install -d -m 0755 %{buildroot}/etc/pam.d/
mv %{buildroot}%{_datadir}/%{name}/*.pam %{buildroot}/etc/pam.d/%{name}
#
install -D -m 0644 %{S:4} %{buildroot}%{_unitdir}/%{name}.service
%{__ln_s} -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%{__install} -D -m 644 %{S:5} %{buildroot}/usr/lib/tmpfiles.d/%{name}.conf

install -D -m 0644 %{S:2} \
    %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -d -m 0750 %{buildroot}%{pkg_logdir}
#
# Admin app
install -dD %{buildroot}/srv/www/
cp -av pgpoolAdmin-%{pgpooladmin_version} %{buildroot}/srv/www/pgpoolAdmin/
chmod -R u=rwX,g=rX,o= %{buildroot}/srv/www/pgpoolAdmin/
#
# sles9 doesnt understand -delete
find %{buildroot} -type f -name "*.la" -delete -print
#
install -D -d -m 0755 %{buildroot}%{_mandir}/man{1,8}/
install -m 0644 doc/src/sgml/man1/*.1 %{buildroot}%{_mandir}/man1/
install -m 0644 doc/src/sgml/man8/*.8 %{buildroot}%{_mandir}/man8/

%post   -n %{_library_name} -p /sbin/ldconfig
%postun -n %{_library_name} -p /sbin/ldconfig

%pre
%{_sbindir}/groupadd -r %{pkg_group} &>/dev/null || :
%{_sbindir}/useradd -g %{pkg_group} -s /bin/false -r -c "pgpool-II User" -d %{pkg_home} %{pkg_user} &>/dev/null || :
%service_add_pre %{name}.service

%preun
%service_del_preun %{name}.service


%post
systemd-tmpfiles --create /usr/lib/tmpfiles.d/%{name}.conf || true
%service_add_post %{name}.service

%postun
%service_del_postun %{name}.service

%files
%defattr(-,root,root)
%dir               %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/aws*
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/pcp.conf
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/pgpool.conf
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/pool_hba.conf
%if 0%{?mainpackage}
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/escalation.sh
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/failover.sh
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/follow_primary.sh
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/pgpool_remote_start
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/*recovery_1st_stage
%config(noreplace) %attr(-,root,%{pkg_group}) %{pgpool_sysconfdir}/*recovery_2nd_stage
%endif
%config(noreplace) %attr(0640,%{pkg_user},%{pkg_group}) %{pgpool_sysconfdir}/pool_passwd
%config(noreplace) /etc/pam.d/%{name}
%{_sbindir}/pcp_invalidate_query_cache
%{_sbindir}/pcp_log_rotate
%{_sbindir}/pcp_attach_node
%{_sbindir}/pcp_detach_node
%{_sbindir}/pcp_node_count
%{_sbindir}/pcp_node_info
%{_sbindir}/pcp_pool_status
%{_sbindir}/pcp_proc_count
%{_sbindir}/pcp_proc_info
%{_sbindir}/pcp_promote_node
%{_sbindir}/pcp_recovery_node
%{_sbindir}/pcp_stop_pgpool
%{_sbindir}/pcp_watchdog_info
%{_sbindir}/pcp_health_check_stats
%{_sbindir}/pcp_reload_config
%{_sbindir}/pg_md5
%{_sbindir}/pg_enc
%{_sbindir}/pgproto
%{_sbindir}/pgpool
%{_sbindir}/pgpool_setup
%{_sbindir}/watchdog_setup
%{_sbindir}/wd_cli
%{_mandir}/man1/*.1*
%{_mandir}/man8/pgpool.8*
%{_datadir}/%{name}/
#
%doc AUTHORS COPYING ChangeLog NEWS README* TODO
%doc src/sample/
%doc doc/src/sgml/html/*
#
%{_tmpfilesdir}/%{name}.conf
%{_unitdir}/%{name}.service
%dir %attr(0750,%{pkg_user},%{pkg_group}) %{pkg_logdir}
#
%{_sbindir}/rc%{name}
%{_fillupdir}/sysconfig.%{name}

%files -n %{_library_name}
%defattr(-,root,root)
%{_libdir}/libpcp.so.*

%files devel
%defattr(-,root,root)
%{_includedir}/pcp.h
%{_includedir}/libpcp_ext.h
%{_includedir}/pool_type.h
%{_includedir}/pool_process_reporting.h
%{_libdir}/libpcp.so

%files -n pgpoolAdmin
%defattr(-,root,root)
%dir /srv/www/
/srv/www/pgpoolAdmin
%config(noreplace) /srv/www/pgpoolAdmin/config.php

%else
%build
for i in src/sql/pgpool*/ ; do make -C $i CUSTOM_COPT="-g" ; done

%install
for i in src/sql/pgpool*/ ; do make DESTDIR=%{buildroot} install %{?_smp_mflags} -C $i ; done

%files
%defattr(-,root,root)
%doc COPYING
# extensions
%{pg_config_pkglibdir}/pgpool-regclass.so
%{pg_config_sharedir}/extension/pgpool-regclass.sql
%{pg_config_sharedir}/extension/pgpool_regclass.control
%{pg_config_sharedir}/extension/pgpool_regclass--*.sql
#
%{pg_config_pkglibdir}/pgpool-recovery.so
%{pg_config_sharedir}/extension/pgpool-recovery.sql
%{pg_config_sharedir}/extension/pgpool_recovery.control
%{pg_config_sharedir}/extension/pgpool_recovery--*.sql
#
%{pg_config_pkglibdir}/pgpool_adm.so
%{pg_config_sharedir}/extension/pgpool_adm*.sql
%{pg_config_sharedir}/extension/pgpool_adm.control
%if %{postgresql_has_llvm}
%{pg_config_pkglibdir}/bitcode/*
%endif
#
%endif

%changelog
openSUSE Build Service is sponsored by