Thread: BUG #13612: postgresql94-setup initdb in kickstart fails

BUG #13612: postgresql94-setup initdb in kickstart fails

From
allan.kristsensen@schneider-electric.com
Date:
The following bug has been logged on the website:

Bug reference:      13612
Logged by:          Allan Kristensen
Email address:      allan.kristsensen@schneider-electric.com
PostgreSQL version: 9.4.4
Operating system:   Centos 7
Description:

Running "/usr/pgsql-9.4/bin/postgresql94-setup initdb" during Kickstart
install of a Centos/RHEL 7 will through the following error.

failed to find PGDATA setting in postgresql-9.4.service
Running in chroot, ignoring request.

In bin/postgresql94-setup the problematic lines are:
PGDATA=`systemctl show -p Environment "${SERVICE_NAME}.service" |
                sed 's/^Environment=//' | tr ' ' '\n' |
                sed -n 's/^PGDATA=//p' | tail -n 1`
if [ x"$PGDATA" = x ]; then
    echo "failed to find PGDATA setting in ${SERVICE_NAME}.service"
    exit 1
fi

systemctl returns an empty result as it won't run in a chroot.

Besides the above. What puzzles me is that PGDATA is overwritten further
down in the script.

# Get data directory from the service file
PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`

I have put things together to the following:

# this parsing technique fails for PGDATA pathnames containing spaces,
# but there's not much I can do about it given systemctl's output format...
PGDATA=`systemctl show -p Environment "${SERVICE_NAME}.service" |
                sed 's/^Environment=//' | tr ' ' '\n' |
                sed -n 's/^PGDATAA=//p' | tail -n 1`
if [ x"$PGDATA" = x ]; then
    # Find the unit file for new version.
    if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]
    then
        SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
    elif [ -f "/lib/systemd/system/${SERVICE_NAME}.service" ]
    then
        SERVICE_FILE="/lib/systemd/system/${SERVICE_NAME}.service"
    else
        echo "Could not find systemd unit file ${SERVICE_NAME}.service"
        exit 1
    fi

    # Get data directory from the service file
    PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`

    if [ x"$PGDATA" = x ]; then
        echo "Failed to find PGDATA setting in ${SERVICE_NAME}.service"
        exit 1
    fi
fi

export PGDATA


If systemctl does not find a path then try the searching in files and exit
if none of the methods provides a valid path.

Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Bruce Momjian
Date:
On Thu, Sep 10, 2015 at 08:13:12AM +0000, allan.kristsensen@schneider-electric.com wrote:
> The following bug has been logged on the website:
>
> Bug reference:      13612
> Logged by:          Allan Kristensen
> Email address:      allan.kristsensen@schneider-electric.com
> PostgreSQL version: 9.4.4
> Operating system:   Centos 7
> Description:
>
> Running "/usr/pgsql-9.4/bin/postgresql94-setup initdb" during Kickstart
> install of a Centos/RHEL 7 will through the following error.

Uh, we didn't write or maintain that file.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Devrim GÜNDÜZ
Date:
Hi,

On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> Uh, we didn't write or maintain that file.

It comes with the RPMs.

Allan, I'll take a look soon.

Regards,
--
Devrim GÜNDÜZ
Principal Systems Engineer @ EnterpriseDB: http://www.enterprisedb.com
PostgreSQL Danışmanı/Consultant, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR






Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Bruce Momjian
Date:
On Thu, Sep 10, 2015 at 04:20:17PM +0300, Devrim Gunduz wrote:
>
> Hi,
>
> On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> > Uh, we didn't write or maintain that file.
>
> It comes with the RPMs.
>
> Allan, I'll take a look soon.

Oh, OK.  I wasn't sure if it was something from the RPMs, or something
Red Hat wrote.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Bruce Momjian
Date:
On Thu, Sep 10, 2015 at 09:23:45AM -0400, Bruce Momjian wrote:
> On Thu, Sep 10, 2015 at 04:20:17PM +0300, Devrim Gunduz wrote:
> >
> > Hi,
> >
> > On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> > > Uh, we didn't write or maintain that file.
> >
> > It comes with the RPMs.
> >
> > Allan, I'll take a look soon.
>
> Oh, OK.  I wasn't sure if it was something from the RPMs, or something
> Red Hat wrote.

FYI, I am getting an email failure from the original poster, so there
might not be much point in replying to him:

  User allan.kristsensen (allan.kristsensen@schneider-electric.com) not
  listed in Domino Directory

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Alvaro Herrera
Date:
Bruce Momjian wrote:
> On Thu, Sep 10, 2015 at 09:23:45AM -0400, Bruce Momjian wrote:
> > On Thu, Sep 10, 2015 at 04:20:17PM +0300, Devrim Gunduz wrote:
> > >
> > > Hi,
> > >
> > > On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> > > > Uh, we didn't write or maintain that file.
> > >
> > > It comes with the RPMs.
> > >
> > > Allan, I'll take a look soon.
> >
> > Oh, OK.  I wasn't sure if it was something from the RPMs, or something
> > Red Hat wrote.
>
> FYI, I am getting an email failure from the original poster, so there
> might not be much point in replying to him:
>
>   User allan.kristsensen (allan.kristsensen@schneider-electric.com) not
>   listed in Domino Directory

He mistyped his address in the bug report form.  I corrected it here.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Allan.Kristensen@schneider-electric.com
Date:
=C1lvaro Herrera wrote:
> Bruce Momjian wrote:
> > On Thu, Sep 10, 2015 at 09:23:45AM -0400, Bruce Momjian wrote:
> > > On Thu, Sep 10, 2015 at 04:20:17PM +0300, Devrim Gunduz wrote:
> > > >=20
> > > > Hi,
> > > >=20
> > > > On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> > > > > Uh, we didn't write or maintain that file.
> > > >=20
> > > > It comes with the RPMs.
> > > >=20
> > > > Allan, I'll take a look soon.
> > >=20
> > > Oh, OK.  I wasn't sure if it was something from the RPMs, or=20
something
> > > Red Hat wrote.
> >=20
> > FYI, I am getting an email failure from the original poster, so there
> > might not be much point in replying to him:
> >=20
> >   User allan.kristsensen (allan.kristsensen@schneider-electric.com)=20
not
> >   listed in Domino Directory
>=20
> He mistyped his address in the bug report form.  I corrected it here.

Thanks =C1lvaro and sorry about the email address.

The rpm in question postgresql94-server-9.4.4-1PGDG.rhel7.x86=5F64.rpm=20
downloaded from the http://yum.postgresql.org/9.4/redhat/rhel-7-x86=5F64/=20
repo.


Best regards
Allan Kristensen
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=20


Allan Kristensen  |   APC by Schneider Electric   |  IT Business  |  =20
Denmark  |   Configuration Management Administrator=20
Phone: +45 72190143  |   Mobile: +45 20752220=20
Email: allan.kristensen@schneider-electric.com  |   Site:=20
www.schneider-electric.dk  |   Address: Silcon Alle, 6000 Kolding, Denmark =



*** Please consider the environment before printing this e-mail ***=20




From:   Alvaro Herrera <alvherre@2ndquadrant.com>
To:     Bruce Momjian <bruce@momjian.us>
Cc:     Devrim G=DCND=DCZ <devrim@gunduz.org>, Allan=20
Kristensen/DK/Schneider@Europe, pgsql-bugs@postgresql.org
Date:   09/10/2015 18:10
Subject:        Re: [BUGS] BUG #13612: postgresql94-setup initdb in=20
kickstart fails



Bruce Momjian wrote:
> On Thu, Sep 10, 2015 at 09:23:45AM -0400, Bruce Momjian wrote:
> > On Thu, Sep 10, 2015 at 04:20:17PM +0300, Devrim Gunduz wrote:
> > >=20
> > > Hi,
> > >=20
> > > On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> > > > Uh, we didn't write or maintain that file.
> > >=20
> > > It comes with the RPMs.
> > >=20
> > > Allan, I'll take a look soon.
> >=20
> > Oh, OK.  I wasn't sure if it was something from the RPMs, or something
> > Red Hat wrote.
>=20
> FYI, I am getting an email failure from the original poster, so there
> might not be much point in replying to him:
>=20
>   User allan.kristsensen (allan.kristsensen@schneider-electric.com) not
>   listed in Domino Directory

He mistyped his address in the bug report form.  I corrected it here.

--=20
=C1lvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
This email has been scanned by the Symantec Email Security.cloud service.
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F

Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Bruce Momjian
Date:
On Fri, Sep 11, 2015 at 08:26:38AM +0200, Allan.Kristensen@schneider-electric.com wrote:
>  lvaro Herrera wrote:
> > Bruce Momjian wrote:
> > > On Thu, Sep 10, 2015 at 09:23:45AM -0400, Bruce Momjian wrote:
> > > > On Thu, Sep 10, 2015 at 04:20:17PM +0300, Devrim Gunduz wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> > > > > > Uh, we didn't write or maintain that file.
> > > > >
> > > > > It comes with the RPMs.
> > > > >
> > > > > Allan, I'll take a look soon.
> > > >
> > > > Oh, OK.  I wasn't sure if it was something from the RPMs, or something
> > > > Red Hat wrote.
> > >
> > > FYI, I am getting an email failure from the original poster, so there
> > > might not be much point in replying to him:
> > >
> > >   User allan.kristsensen (allan.kristsensen@schneider-electric.com) not
> > >   listed in Domino Directory
> >
> > He mistyped his address in the bug report form.  I corrected it here.
>
> Thanks  lvaro and sorry about the email address.
>
> The rpm in question postgresql94-server-9.4.4-1PGDG.rhel7.x86_64.rpm downloaded
> from the http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/ repo.

Thanks.  I would be interested to know how email list subscribers like
me can determine who the source of the OS-specific script is so we can
properly route such messsages.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + Everyone has their own god. +

Re: BUG #13612: postgresql94-setup initdb in kickstart fails

From
Allan.Kristensen@schneider-electric.com
Date:
> On Fri, Sep 11, 2015 at 08:26:38AM +0200,
Allan.Kristensen@schneider-electric.com wrote:
> >  lvaro Herrera wrote:
> > > Bruce Momjian wrote:
> > > > On Thu, Sep 10, 2015 at 09:23:45AM -0400, Bruce Momjian wrote:
> > > > > On Thu, Sep 10, 2015 at 04:20:17PM +0300, Devrim Gunduz wrote:
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > On Thu, 2015-09-10 at 09:11 -0400, Bruce Momjian wrote:
> > > > > > > Uh, we didn't write or maintain that file.
> > > > > >
> > > > > > It comes with the RPMs.
> > > > > >
> > > > > > Allan, I'll take a look soon.
> > > > >
> > > > > Oh, OK.  I wasn't sure if it was something from the RPMs, or
something
> > > > > Red Hat wrote.
> > > >
> > > > FYI, I am getting an email failure from the original poster, so
there
> > > > might not be much point in replying to him:
> > > >
> > > >   User allan.kristsensen
(allan.kristsensen@schneider-electric.com) not
> > > >   listed in Domino Directory
> > >
> > > He mistyped his address in the bug report form.  I corrected it
here.
> >
> > Thanks  lvaro and sorry about the email address.
> >
> > The rpm in question postgresql94-server-9.4.4-1PGDG.rhel7.x86_64.rpm
downloaded
> > from the http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/ repo.
>
> Thanks.  I would be interested to know how email list subscribers like
> me can determine who the source of the OS-specific script is so we can
> properly route such messsages.
>
> --
>   Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>   EnterpriseDB                             http://enterprisedb.com
>
>   + Everyone has their own god. +

I have been using the lines from OP for over a month now and did not find
any issues. What is the process for incorporating it into the next
release?

Here is the diff if that makes life easier.

########### Diff start ###########
--- /usr/pgsql-9.4/bin/postgresql94-setup       2015-06-11
13:19:27.000000000 +0200
+++ /usr/pgsql-9.4/bin/postgresql94-setup.new   2015-10-26
16:05:28.082858681 +0100
@@ -79,32 +79,34 @@
                 sed 's/^Environment=//' | tr ' ' '\n' |
                 sed -n 's/^PGDATA=//p' | tail -n 1`
 if [ x"$PGDATA" = x ]; then
-    echo "failed to find PGDATA setting in ${SERVICE_NAME}.service"
-    exit 1
+    # Find the unit file for new version.
+    if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]
+    then
+        SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
+    elif [ -f "/lib/systemd/system/${SERVICE_NAME}.service" ]
+    then
+        SERVICE_FILE="/lib/systemd/system/${SERVICE_NAME}.service"
+    else
+        echo "Could not find systemd unit file ${SERVICE_NAME}.service"
+        exit 1
+    fi
+
+    # Get data directory from the service file
+    PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`
+
+    if [ x"$PGDATA" = x ]; then
+        echo "Failed to find PGDATA setting in ${SERVICE_NAME}.service"
+        exit 1
+    fi
 fi

-# Find the unit file for new version.
-if [ -f "/etc/systemd/system/${SERVICE_NAME}.service" ]
-then
-    SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
-elif [ -f "/lib/systemd/system/${SERVICE_NAME}.service" ]
-then
-    SERVICE_FILE="/lib/systemd/system/${SERVICE_NAME}.service"
-else
-    echo "Could not find systemd unit file ${SERVICE_NAME}.service"
-    exit 1
-fi
+export PGDATA

 # Log file for pg_upgrade
 PGUPLOG=/var/lib/pgsql/$PGMAJORVERSION/pgupgrade.log
 # Log file for initdb
 PGLOG=/var/lib/pgsql/9.4/initdb.log

-# Get data directory from the service file
-PGDATA=`sed -n 's/Environment=PGDATA=//p' "${SERVICE_FILE}"`
-
-export PGDATA
-
 # For SELinux we need to use 'runuser' not 'su'
 if [ -x /sbin/runuser ]
 then
########### Diff end ###########


Best regards
Allan Kristensen
_____________________________________________________________________________________


Allan Kristensen  |   APC by Schneider Electric   |  IT Business  |
Denmark  |   Configuration Management Administrator
Phone: +45 72190143  |   Mobile: +45 20752220
Email: allan.kristensen@schneider-electric.com  |   Site:
www.schneider-electric.dk  |   Address: Silcon Alle, 6000 Kolding, Denmark


*** Please consider the environment before printing this e-mail ***