Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oWVF4-0002g5-F7 for pgsql-general@arkaria.postgresql.org; Fri, 09 Sep 2022 04:03:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oWVF2-00008v-B1 for pgsql-general@arkaria.postgresql.org; Fri, 09 Sep 2022 04:03:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oWVF1-00008l-TI for pgsql-general@lists.postgresql.org; Fri, 09 Sep 2022 04:03:43 +0000 Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oWVEv-0003pK-0Q for pgsql-general@lists.postgresql.org; Fri, 09 Sep 2022 04:03:43 +0000 Received: by mail-qt1-x82a.google.com with SMTP id j17so436921qtp.12 for ; Thu, 08 Sep 2022 21:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date; bh=gspsSeQszmb99oF+MV/tUX1a1IgXNd9K8x5ZtbVgnAA=; b=NgUrSERcMWTBLv8KyVc4d2vR4SS15BsNcINSew7AwO72cH31/xVs/+i0HPncTxxVYW G9RJLwTquNYXoKeaQwjvNRUfpPxpw+04AK9zsr0y/tY6wJ8ACgp1CWyyGOh3MttRiOg+ Zi6nV9Wq3lZN7TiUstmU4kuB/VUz68WeoQSCoXWf9CP/KCz+NbsJ8xtmdU79E6mxdn84 z+OgryPd1VnSiPYDhR5DW+DS1F3tW3Hhw9hjlUyZWhR4xizXtNmg2wnT6e5BpOd3TnsI zUDUsgmTOJJ/D3Z9PoHvVbFNU2riJPxYlZpJx81ejTPKBhsWzFqZ+h6fUStPp5T/ew9a 7Kaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date; bh=gspsSeQszmb99oF+MV/tUX1a1IgXNd9K8x5ZtbVgnAA=; b=Zyz2Ut8X195p1KgL2ReceN2cSpSHdQxdmDAmWa5/SOgCvXNLxTGHq59JlX+X+BkYrY 9Lh3GVvMsz1ntOgmJEbMZVdNmL/MaLYcpeh8a9V56xmsSXwzvBacO4Zi0HmOsmkuZxLt najQIRTiX0r05NxRDm5yZjrKlVEBqxSAML62o3pTzJ5SUU3xramxa+876pxSvflv07fO 7WmLRX5HYz1r/QnlIdmqZciszOU2heVGF/aZJivjNJZmehCFg+XMH9RcsQ5D5eSwxDB7 5pIIKfpOs32Rs5m1nfaSCXTQGIrO3yKyP2zYjDlOnTtq5+6NUckoGXNL1ZTKRAwt3it6 SlzQ== X-Gm-Message-State: ACgBeo0vpoIRmlz5Zz6AMPJqyL3/QtQcSJ35YdkJMvcPFivQHErT8FJe bnscfaQR8i9rwJpeuC0yi2FtYRhCsUfZt3Jg X-Google-Smtp-Source: AA6agR4n3vDwtKkSp/3UhtJnbpDrGSyabCC1gYucW7rrhaDEr5QdjZk3Lj/UlT/wDcxIB2QzamWfhw== X-Received: by 2002:ac8:7d53:0:b0:344:6545:5c02 with SMTP id h19-20020ac87d53000000b0034465455c02mr10803670qtb.365.1662696214865; Thu, 08 Sep 2022 21:03:34 -0700 (PDT) Received: from [192.168.2.100] (pool-72-79-30-4.nwrknj.east.verizon.net. [72.79.30.4]) by smtp.gmail.com with ESMTPSA id r1-20020a05620a298100b006b919c6749esm490384qkp.91.2022.09.08.21.03.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Sep 2022 21:03:34 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------cCsEcJW0lp6xLsyz5JhSRjEj" Message-ID: <8402e6d2-49a0-51d0-2693-d2596c48a25b@gmail.com> Date: Fri, 9 Sep 2022 00:03:33 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: WARNING: could not open statistics file "pg_stat_tmp/global.stat": Operation not permitted To: pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Mladen Gogala In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------cCsEcJW0lp6xLsyz5JhSRjEj Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 9/8/22 23:05, Perry Smith wrote: > This is an issue when PostgreSQL is running inside a container.  In my > quest to find an answer, I’ve discovered three instances that it has > come up and various people have talked about fixes but no one seemed > to notice what I found. > > I opened an issue here[1]. > > From within the container, files which I assume are created by > PostgreSQL are ending up being owned by root rather than Postgres. >  Thus, to me, it appears to NOT be an issue of mapping internal UIDs > and GIDs to external IDs since there should not be anything outside > the PostgreSQL container creating files inside Postgres’ data directory. > > The reason I’m sending this note to the general list is to ask how bad > is this error?  Some “solutions” are to make the pg_stat_tmp directory > internal to the image and that somehow resolves the issue but I don’t > think anyone really understands why and things like that bother me. >  But I’m also curious if that appears to be a viable solution.  The > result will be that when the Postgres is stopped and the container > exited, the next time Postgres starts back up, the pg_stat_tmp > directory will be gone.  Is that ok?  Does Postgres store anything > that that needs to survive a restart? > > Thank you for your help, > Perry > [1] https://github.com/docker-library/docs/issues/2188#issue-1367170047 > Hi Perry, You probably need to fix your Dockerfile because your postgres seems to be running as root. Here is my Dockerfile: FROM oraclelinux:8 LABEL Description="This install PostgreSQL 14 on top of Oracle Linux 8" LABEL maintainer="Mladen Gogala" RUN dnf -y update COPY RPMS/pgdg-redhat-repo-latest.noarch.rpm /tmp COPY RPMS/pg_hint_plan14-1.4-1.el8.x86_64.rpm /tmp/ COPY RPMS/pg_hint_plan14-llvmjit-1.4-1.el8.x86_64.rpm /tmp/ # Install PostgreSQL software RUN dnf localinstall -y /tmp/pgdg-redhat-repo-latest.noarch.rpm RUN dnf -qy module disable postgresql RUN dnf -y install postgresql14 RUN dnf -y install postgresql14-libs RUN dnf -y install postgresql14-server RUN dnf -y install postgresql14-llvmjit RUN dnf -y install postgresql14-contrib # Install pg_hint_plan 1.4 RUN cd /tmp;dnf -y localinstall `ls *.rpm` # Cleanup RUN rm -f /tmp/*.rpm RUN dnf clean all # Copy postgresql.auto.conf (modified parameters) and run initdb USER postgres ARG PGPASSWD="qwerty" ENV PGDATA=/var/lib/pgsql/14/data ENV PATH=/usr/pgsql-14/bin:/usr/bin:/usr/local/bin RUN echo "$PGPASSWD">/var/lib/pgsql/14/pgcluster.pwd RUN initdb -A password --pwfile=/var/lib/pgsql/14/pgcluster.pwd RUN echo "host all all 0.0.0.0/0 md5">>$PGDATA/pg_hba.conf COPY --chown=postgres:postgres RPMS/postgresql.auto.conf /var/lib/pgsql/14/data # Finish EXPOSE 5432/tcp ENTRYPOINT ["postgres"] Please note that I switch users in the file and that owners are switched. I don't have any issues with the container built this way. I have another container which is built by untaring backup of my sample database. I use ADD command to untar it to $PGDATA. Also, my trick with putting the modified parameters into postgresql.auto.conf goes contrary to the Postgres recommendations. You may want to avoid doing that. I haven't pushed the image to the Docker hub because I'm still working on it. -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------cCsEcJW0lp6xLsyz5JhSRjEj Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 9/8/22 23:05, Perry Smith wrote:
This is an issue when PostgreSQL is running inside a container.  In my quest to find an answer, I’ve discovered three instances that it has come up and various people have talked about fixes but no one seemed to notice what I found.

I opened an issue here[1].

From within the container, files which I assume are created by PostgreSQL are ending up being owned by root rather than Postgres.  Thus, to me, it appears to NOT be an issue of mapping internal UIDs and GIDs to external IDs since there should not be anything outside the PostgreSQL container creating files inside Postgres’ data directory.

The reason I’m sending this note to the general list is to ask how bad is this error?  Some “solutions” are to make the pg_stat_tmp directory internal to the image and that somehow resolves the issue but I don’t think anyone really understands why and things like that bother me.  But I’m also curious if that appears to be a viable solution.  The result will be that when the Postgres is stopped and the container exited, the next time Postgres starts back up, the pg_stat_tmp directory will be gone.  Is that ok?  Does Postgres store anything that that needs to survive a restart?

Thank you for your help,
Perry

Hi Perry,

You probably need to fix your Dockerfile because your postgres seems to be running as root. Here is my Dockerfile:

FROM oraclelinux:8
LABEL Description="This install PostgreSQL 14 on top of Oracle Linux 8"
LABEL maintainer="Mladen Gogala"
RUN dnf -y update
COPY RPMS/pgdg-redhat-repo-latest.noarch.rpm /tmp
COPY RPMS/pg_hint_plan14-1.4-1.el8.x86_64.rpm /tmp/
COPY RPMS/pg_hint_plan14-llvmjit-1.4-1.el8.x86_64.rpm /tmp/
# Install PostgreSQL software
RUN dnf localinstall -y /tmp/pgdg-redhat-repo-latest.noarch.rpm
RUN dnf -qy module disable postgresql
RUN dnf -y install postgresql14
RUN dnf -y install postgresql14-libs
RUN dnf -y install postgresql14-server
RUN dnf -y install postgresql14-llvmjit
RUN dnf -y install postgresql14-contrib
# Install pg_hint_plan 1.4
RUN cd /tmp;dnf -y localinstall `ls *.rpm`
# Cleanup
RUN rm -f /tmp/*.rpm
RUN dnf clean all

# Copy postgresql.auto.conf (modified parameters) and run initdb
USER postgres
ARG PGPASSWD="qwerty"
ENV PGDATA=/var/lib/pgsql/14/data
ENV PATH=/usr/pgsql-14/bin:/usr/bin:/usr/local/bin
RUN echo "$PGPASSWD">/var/lib/pgsql/14/pgcluster.pwd
RUN initdb -A password --pwfile=/var/lib/pgsql/14/pgcluster.pwd
RUN echo "host all all 0.0.0.0/0  md5">>$PGDATA/pg_hba.conf
COPY --chown=postgres:postgres RPMS/postgresql.auto.conf /var/lib/pgsql/14/data
# Finish
EXPOSE 5432/tcp
ENTRYPOINT ["postgres"]

Please note that I switch users in the file and that owners are switched. I don't have any issues with the container built this way. I have another container which is built by untaring backup of my sample database. I use ADD command to untar it to $PGDATA. Also, my trick with putting the modified parameters into postgresql.auto.conf goes contrary to the Postgres recommendations. You may want to avoid doing that. I haven't pushed the image to the Docker hub because I'm still working on it.

-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
--------------cCsEcJW0lp6xLsyz5JhSRjEj--