# Herbouw mislukt: Datadirectory /shared/postgres\_data mag niet eigendom zijn van root

**URL:** https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658
**Category:** Self-hosting
**Created:** [5 februari 2025 om 15:45 UTC](https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658 "2025-02-05T15:45:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![JamesChevalier](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jameschevalier/32/116235_2.png) [@JamesChevalier](https://meta.discourse.org/u/JamesChevalier)
#### Post date: [5 februari 2025 om 15:45 UTC](https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658/1 "2025-02-05T15:45:52Z")

</div>

Apologies ahead of time for some lack of details… I really got myself into it here…  
If you know a lot about the file permission requirements in `/var/discourse/shared/standalone` you might be able to skip down to the bottom of this post for the core question & skip the details that got me here 😓

The latest web-based upgrade hosed my install - I think it was similar to [Error Updating from 3.4.0.beta3-dev to 3.4.0.beta3](https://meta.discourse.org/t/error-updating-from-3-4-0-beta3-dev-to-3-4-0-beta3/349847) but I think I was on 3.4.0.beta4-dev

I’m also on Ubuntu 20, so now `./launcher rebuild app` returns the error:

> ERROR: Docker version 19.03.13 not supported, please upgrade to at least 20.10.0, or recommended 24.0.7

I don’t believe this is possible, so I created a new server and followed the steps in [Move a Discourse site to another VPS with rsync](https://meta.discourse.org/t/move-a-discourse-site-to-another-vps-with-rsync/43812) with the additional command to bring over the volumes from my old server as well:  
`rsync -rvz root@104.236.77.249:/var/lib/docker/volumes/ /var/lib/docker/volumes`

Now, on the new Ubuntu 24 server, `./launcher rebuild app` is returning this error:

> Stopping PostgreSQL 15 database server: mainError: Data directory /shared/postgres\_data must not be owned by root … failed!

> **full command output**
>
> ```plaintext
> x86_64 arch detected.
> WARNING: containers/app.yml file is world-readable. You can secure this file by running: chmod o-rwx containers/app.yml
> Ensuring launcher is up to date
> Launcher is up-to-date
> 2.0.20250129-0720: Pulling from discourse/base
> Digest: sha256:01b8516e5504c0e9bc3707773015ff4407be03a89154194ff3b5b8699291bc26
> Status: Image is up to date for discourse/base:2.0.20250129-0720
> docker.io/discourse/base:2.0.20250129-0720
> /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups.rb
> /usr/local/bin/pups --stdin
> I, [2025-02-05T15:28:12.350842 #1] INFO -- : Reading from stdin
> I, [2025-02-05T15:28:12.364293 #1] INFO -- : File > /etc/service/postgres/run chmod: +x chown: 
> I, [2025-02-05T15:28:12.369358 #1] INFO -- : File > /etc/service/postgres/log/run chmod: +x chown: 
> I, [2025-02-05T15:28:12.373684 #1] INFO -- : File > /etc/runit/3.d/99-postgres chmod: +x chown: 
> I, [2025-02-05T15:28:12.378720 #1] INFO -- : File > /root/install_postgres chmod: +x chown: 
> I, [2025-02-05T15:28:12.383793 #1] INFO -- : File > /root/upgrade_postgres chmod: +x chown: 
> I, [2025-02-05T15:28:12.384811 #1] INFO -- : Replacing data_directory = '/var/lib/postgresql/15/main' with data_directory = '/shared/postgres_data' in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.386020 #1] INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.391549 #1] INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.392476 #1] INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.393539 #1] INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.394234 #1] INFO -- : Replacing (?-mix:#?default_text_search_config *=.*) with default_text_search_config = '$db_default_text_search_config' in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.394860 #1] INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.395701 #1] INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.396354 #1] INFO -- : Replacing (?-mix:#?log_min_duration_statement *=.*) with log_min_duration_statement = $db_log_min_duration_statement in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T15:28:12.396997 #1] INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres peer in /etc/postgresql/15/main/pg_hba.conf
> I, [2025-02-05T15:28:12.397677 #1] INFO -- : Replacing (?-mix:^host.*all.*all.*127.*$) with host all all 0.0.0.0/0 md5 in /etc/postgresql/15/main/pg_hba.conf
> I, [2025-02-05T15:28:12.398272 #1] INFO -- : Replacing (?-mix:^host.*all.*all.*::1\/128.*$) with host all all ::/0 md5 in /etc/postgresql/15/main/pg_hba.conf
> I, [2025-02-05T15:28:12.398841 #1] INFO -- : > if [-f /root/install_postgres]; then
> /root/install_postgres && rm -f /root/install_postgres
> elif [-e /shared/postgres_run/.s.PGSQL.5432]; then
> socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
> fi
> 
> initdb: warning: enabling "trust" authentication for local connections
> initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
> W: https://dl.yarnpkg.com/debian/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
> debconf: delaying package configuration, since apt-utils is not installed
> I, [2025-02-05T15:28:32.940792 #1] INFO -- : Generating locales (this might take a while)...
> en_US.UTF-8... done
> Generation complete.
> Upgrading PostgreSQL from version 13 to 15
> The files belonging to this database system will be owned by user "postgres".
> This user must also own the server process.
> 
> The database cluster will be initialized with locale "en_US.UTF-8".
> The default database encoding has accordingly been set to "UTF8".
> The default text search configuration will be set to "english".
> 
> Data page checksums are disabled.
> 
> fixing permissions on existing directory /shared/postgres_data_new ... ok
> creating subdirectories ... ok
> selecting dynamic shared memory implementation ... posix
> selecting default max_connections ... 100
> selecting default shared_buffers ... 128MB
> selecting default time zone ... Etc/UTC
> creating configuration files ... ok
> running bootstrap script ... ok
> performing post-bootstrap initialization ... ok
> syncing data to disk ... ok
> 
> Success. You can now start the database server using:
> 
> /usr/lib/postgresql/15/bin/pg_ctl -D /shared/postgres_data_new -l logfile start
> 
> Get:1 http://deb.debian.org/debian bookworm-backports InRelease [59.0 kB]
> Get:2 http://deb.debian.org/debian bookworm InRelease [151 kB]
> Get:3 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
> Get:4 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
> Get:5 https://deb.nodesource.com/node_22.x nodistro InRelease [12.1 kB]
> Get:6 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]
> Get:7 http://deb.debian.org/debian bookworm-backports/main amd64 Packages [282 kB]
> Get:8 http://deb.debian.org/debian bookworm/main amd64 Packages [8,792 kB]
> Get:9 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg InRelease [129 kB]
> Get:10 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.5 kB]
> Get:11 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [243 kB]
> Get:12 https://deb.nodesource.com/node_22.x nodistro/main amd64 Packages [5,274 B]
> Get:13 https://dl.yarnpkg.com/debian stable/main all Packages [10.9 kB]
> Get:14 https://dl.yarnpkg.com/debian stable/main amd64 Packages [10.9 kB]
> Get:15 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 Packages [360 kB]
> Fetched 10.2 MB in 2s (4,214 kB/s)
> Reading package lists...
> Reading package lists...
> Building dependency tree...
> Reading state information...
> The following additional packages will be installed:
> postgresql-client-13
> Suggested packages:
> postgresql-doc-13
> The following NEW packages will be installed:
> postgresql-13 postgresql-13-pgvector postgresql-client-13
> 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
> Need to get 17.3 MB of archives.
> After this operation, 56.7 MB of additional disk space will be used.
> Get:1 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-client-13 amd64 13.18-1.pgdg120+1 [1,523 kB]
> Get:2 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13 amd64 13.18-1.pgdg120+1 [15.4 MB]
> Get:3 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13-pgvector amd64 0.8.0-1.pgdg120+1 [297 kB]
> Fetched 17.3 MB in 2s (8,411 kB/s)
> Selecting previously unselected package postgresql-client-13.
> (Reading database ... 33363 files and directories currently installed.)
> Preparing to unpack .../postgresql-client-13_13.18-1.pgdg120+1_amd64.deb ...
> Unpacking postgresql-client-13 (13.18-1.pgdg120+1) ...
> Selecting previously unselected package postgresql-13.
> Preparing to unpack .../postgresql-13_13.18-1.pgdg120+1_amd64.deb ...
> Unpacking postgresql-13 (13.18-1.pgdg120+1) ...
> Selecting previously unselected package postgresql-13-pgvector.
> Preparing to unpack .../postgresql-13-pgvector_0.8.0-1.pgdg120+1_amd64.deb ...
> Unpacking postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
> Setting up postgresql-client-13 (13.18-1.pgdg120+1) ...
> Setting up postgresql-13 (13.18-1.pgdg120+1) ...
> Creating new PostgreSQL cluster 13/main ...
> /usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main --auth-local peer --auth-host md5
> The files belonging to this database system will be owned by user "postgres".
> This user must also own the server process.
> 
> The database cluster will be initialized with locale "C.UTF-8".
> The default database encoding has accordingly been set to "UTF8".
> The default text search configuration will be set to "english".
> 
> Data page checksums are disabled.
> 
> fixing permissions on existing directory /var/lib/postgresql/13/main ... ok
> creating subdirectories ... ok
> selecting dynamic shared memory implementation ... posix
> selecting default max_connections ... 100
> selecting default shared_buffers ... 128MB
> selecting default time zone ... Etc/UTC
> creating configuration files ... ok
> running bootstrap script ... ok
> performing post-bootstrap initialization ... ok
> syncing data to disk ... ok
> 
> Success. You can now start the database server using:
> 
> pg_ctlcluster 13 main start
> 
> Warning: The selected stats_temp_directory /var/run/postgresql/13-main.pg_stat_tmp
> is not writable for the cluster owner. Not adding this setting in
> postgresql.conf.
> invoke-rc.d: could not determine current runlevel
> invoke-rc.d: policy-rc.d denied execution of start.
> Setting up postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
> Processing triggers for postgresql-common (267.pgdg120+1) ...
> Building PostgreSQL dictionaries from installed myspell/hunspell packages...
> Removing obsolete dictionary files:
> Stopping PostgreSQL 13 database server: main.
> Stopping PostgreSQL 15 database server: mainError: Data directory /shared/postgres_data must not be owned by root ... failed!
> failed!
> 
> could not open version file "/shared/postgres_data/PG_VERSION": Permission denied
> Failure, exiting
> -------------------------------------------------------------------------------------
> UPGRADE OF POSTGRES FAILED
> 
> Please visit https://meta.discourse.org/t/postgresql-15-update/349515 for support.
> 
> You can run ./launcher start app to restart your app in the meanwhile
> -------------------------------------------------------------------------------------
> 
> FAILED
> --------------------
> Pups::ExecError: if [-f /root/install_postgres]; then
> /root/install_postgres && rm -f /root/install_postgres
> elif [-e /shared/postgres_run/.s.PGSQL.5432]; then
> socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
> fi
> failed with return #<Process::Status: pid 18 exit 1>
> Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
> exec failed with the params {"tag"=>"db", "cmd"=>"if [-f /root/install_postgres]; then\n /root/install_postgres && rm -f /root/install_postgres\nelif [-e /shared/postgres_run/.s.PGSQL.5432]; then\n socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1\nfi\n"}
> bootstrap failed with exit code 1
> **FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
> ./discourse-doctor may help diagnose the problem.
> 
> ```

The `/var/discourse/shared` folder is owned by root on both old and new servers. Digging in some more levels, though, I notice that there were some permission differences in some folders in `/var/discourse/shared/standalone`…

Old server:

```plaintext
/var/discourse/shared/standalone# ls -alh
total 56K
drwxr-xr-x 14 root root 4.0K Jan 22 2021 .
drwxr-xr-x 3 root root 4.0K Mar 12 2016 ..
drwxr-xr-x 3 1000 www-data 4.0K Sep 21 2015 backups
drwxr-xr-x 8 root root 4.0K Dec 10 19:36 letsencrypt
drwxr-xr-x 4 root root 4.0K Jun 12 2015 log
drwxr-xr-x 2 syslog syslog 4.0K Jun 12 2015 postgres_backup
drwx------ 19 syslog syslog 4.0K Feb 4 20:03 postgres_data
drwx------ 20 colord landscape 4.0K Jan 22 2021 postgres_data_old
drwxrwsr-x 7 syslog syslog 4.0K Feb 4 20:03 postgres_run
drwxr-xr-x 2 landscape messagebus 4.0K Feb 4 20:03 redis_data
drwxr-xr-x 2 root root 4.0K Nov 7 2019 ssl
drwxr-xr-x 4 root root 4.0K Jun 12 2015 state
drwxr-xr-x 4 1000 www-data 4.0K Feb 4 20:03 tmp
drwxr-xr-x 4 1000 www-data 4.0K Jun 16 2017 uploads

```

New server:

```plaintext
/var/discourse/shared/standalone# ls -alh
total 60K
drwxr-xr-x 15 root root 4.0K Feb 5 15:32 .
drwxr-xr-x 3 root root 4.0K Feb 5 01:59 ..
drwxr-xr-x 3 root root 4.0K Feb 5 01:59 backups
drwxr-xr-x 8 root root 4.0K Feb 5 02:00 letsencrypt
drwxr-xr-x 4 root root 4.0K Feb 5 01:59 log
drwxr-xr-x 2 root root 4.0K Feb 5 01:59 postgres_backup
drwx------ 20 root root 4.0K Feb 5 02:42 postgres_data
drwx------ 20 messagebus tss 4.0K Feb 5 15:33 postgres_data_new
drwx------ 20 root root 4.0K Feb 5 02:04 postgres_data_older
drwxrwxr-x 8 messagebus tss 4.0K Feb 5 02:41 postgres_run
drwxr-xr-x 2 root root 4.0K Feb 5 02:05 redis_data
drwxr-xr-x 2 root root 4.0K Feb 5 02:05 ssl
drwxr-xr-x 4 root root 4.0K Feb 5 02:04 state
drwxr-xr-x 4 root root 4.0K Feb 5 02:04 tmp
drwxr-xr-x 4 root root 4.0K Feb 5 02:04 uploads

```

So I changed ownership on two of them in the new server:

```plaintext
chown -R syslog: postgres_data
chown -R syslog: postgres_backup

```

This changed the error message to something that I don’t know what to do with:

> Stopping PostgreSQL 15 database server: mainError: Config owner (postgres:101) and data owner (messagebus:102) do not match, and config owner is not root … failed!

To clarify, my _current_ permission in the new server are:

```plaintext
/var/discourse/shared/standalone# ls -alh
total 60K
drwxr-xr-x 15 root root 4.0K Feb 5 15:32 .
drwxr-xr-x 3 root root 4.0K Feb 5 01:59 ..
drwxr-xr-x 3 root root 4.0K Feb 5 01:59 backups
drwxr-xr-x 8 root root 4.0K Feb 5 02:00 letsencrypt
drwxr-xr-x 4 root root 4.0K Feb 5 01:59 log
drwxr-xr-x 2 syslog syslog 4.0K Feb 5 01:59 postgres_backup
drwx------ 20 syslog syslog 4.0K Feb 5 02:42 postgres_data
drwx------ 20 messagebus tss 4.0K Feb 5 15:33 postgres_data_new
drwx------ 20 root root 4.0K Feb 5 02:04 postgres_data_older
drwxrwxr-x 8 messagebus tss 4.0K Feb 5 02:41 postgres_run
drwxr-xr-x 2 root root 4.0K Feb 5 02:05 redis_data
drwxr-xr-x 2 root root 4.0K Feb 5 02:05 ssl
drwxr-xr-x 4 root root 4.0K Feb 5 02:04 state
drwxr-xr-x 4 root root 4.0K Feb 5 02:04 tmp
drwxr-xr-x 4 root root 4.0K Feb 5 02:04 uploads

```

🤷  
I’m assuming some `chown` is going to fix this up for me, but I don’t know what/why/how…

---

<div class="post-metadata">

### Author: ![JamesChevalier](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jameschevalier/32/116235_2.png) [@JamesChevalier](https://meta.discourse.org/u/JamesChevalier)
#### Post date: [5 februari 2025 om 16:26 UTC](https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658/2 "2025-02-05T16:26:04Z")

</div>

Since I had documentation of the original (albeit incorrect) permissions, I decided to move forward with testing different `chown` variations. Ultimately, this set got me past that error:

```plaintext
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_backup
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_data
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_run
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_data_new
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_data_older

```

I’m now met with the same error mentioned at [PostgreSQL 15 update - #61 by xFocus](https://meta.discourse.org/t/postgresql-15-update/349515/61) when I run `./launcher rebuild app`

> The source cluster was not shut down cleanly.  
> Failure, exiting

> **Full command output**
>
> ```plaintext
> x86_64 arch detected.
> Ensuring launcher is up to date
> Launcher is up-to-date
> 2.0.20250129-0720: Pulling from discourse/base
> Digest: sha256:01b8516e5504c0e9bc3707773015ff4407be03a89154194ff3b5b8699291bc26
> Status: Image is up to date for discourse/base:2.0.20250129-0720
> docker.io/discourse/base:2.0.20250129-0720
> /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups.rb
> /usr/local/bin/pups --stdin
> I, [2025-02-05T16:19:09.574812 #1] INFO -- : Reading from stdin
> I, [2025-02-05T16:19:09.605350 #1] INFO -- : File > /etc/service/postgres/run chmod: +x chown: 
> I, [2025-02-05T16:19:09.614043 #1] INFO -- : File > /etc/service/postgres/log/run chmod: +x chown: 
> I, [2025-02-05T16:19:09.626167 #1] INFO -- : File > /etc/runit/3.d/99-postgres chmod: +x chown: 
> I, [2025-02-05T16:19:09.634599 #1] INFO -- : File > /root/install_postgres chmod: +x chown: 
> I, [2025-02-05T16:19:09.643169 #1] INFO -- : File > /root/upgrade_postgres chmod: +x chown: 
> I, [2025-02-05T16:19:09.644682 #1] INFO -- : Replacing data_directory = '/var/lib/postgresql/15/main' with data_directory = '/shared/postgres_data' in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.646186 #1] INFO -- : Replacing (?-mix:#?listen_addresses *=.*) with listen_addresses = '*' in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.653810 #1] INFO -- : Replacing (?-mix:#?synchronous_commit *=.*) with synchronous_commit = $db_synchronous_commit in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.655422 #1] INFO -- : Replacing (?-mix:#?shared_buffers *=.*) with shared_buffers = $db_shared_buffers in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.656864 #1] INFO -- : Replacing (?-mix:#?work_mem *=.*) with work_mem = $db_work_mem in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.657789 #1] INFO -- : Replacing (?-mix:#?default_text_search_config *=.*) with default_text_search_config = '$db_default_text_search_config' in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.659640 #1] INFO -- : Replacing (?-mix:#?checkpoint_segments *=.*) with checkpoint_segments = $db_checkpoint_segments in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.660906 #1] INFO -- : Replacing (?-mix:#?logging_collector *=.*) with logging_collector = $db_logging_collector in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.661925 #1] INFO -- : Replacing (?-mix:#?log_min_duration_statement *=.*) with log_min_duration_statement = $db_log_min_duration_statement in /etc/postgresql/15/main/postgresql.conf
> I, [2025-02-05T16:19:09.663114 #1] INFO -- : Replacing (?-mix:^#local +replication +postgres +peer$) with local replication postgres peer in /etc/postgresql/15/main/pg_hba.conf
> I, [2025-02-05T16:19:09.663912 #1] INFO -- : Replacing (?-mix:^host.*all.*all.*127.*$) with host all all 0.0.0.0/0 md5 in /etc/postgresql/15/main/pg_hba.conf
> I, [2025-02-05T16:19:09.664817 #1] INFO -- : Replacing (?-mix:^host.*all.*all.*::1\/128.*$) with host all all ::/0 md5 in /etc/postgresql/15/main/pg_hba.conf
> I, [2025-02-05T16:19:09.665701 #1] INFO -- : > if [-f /root/install_postgres]; then
> /root/install_postgres && rm -f /root/install_postgres
> elif [-e /shared/postgres_run/.s.PGSQL.5432]; then
> socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
> fi
> 
> initdb: warning: enabling "trust" authentication for local connections
> initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
> W: https://dl.yarnpkg.com/debian/dists/stable/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
> debconf: delaying package configuration, since apt-utils is not installed
> I, [2025-02-05T16:19:29.797884 #1] INFO -- : Generating locales (this might take a while)...
> en_US.UTF-8... done
> Generation complete.
> Upgrading PostgreSQL from version 13 to 15
> The files belonging to this database system will be owned by user "postgres".
> This user must also own the server process.
> 
> The database cluster will be initialized with locale "en_US.UTF-8".
> The default database encoding has accordingly been set to "UTF8".
> The default text search configuration will be set to "english".
> 
> Data page checksums are disabled.
> 
> fixing permissions on existing directory /shared/postgres_data_new ... ok
> creating subdirectories ... ok
> selecting dynamic shared memory implementation ... posix
> selecting default max_connections ... 100
> selecting default shared_buffers ... 128MB
> selecting default time zone ... Etc/UTC
> creating configuration files ... ok
> running bootstrap script ... ok
> performing post-bootstrap initialization ... ok
> syncing data to disk ... ok
> 
> Success. You can now start the database server using:
> 
> /usr/lib/postgresql/15/bin/pg_ctl -D /shared/postgres_data_new -l logfile start
> 
> Get:1 http://deb.debian.org/debian bookworm-backports InRelease [59.0 kB]
> Get:2 http://deb.debian.org/debian bookworm InRelease [151 kB]
> Get:3 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
> Get:4 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
> Get:5 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]
> Get:6 https://deb.nodesource.com/node_22.x nodistro InRelease [12.1 kB]
> Get:7 http://deb.debian.org/debian bookworm-backports/main amd64 Packages [282 kB]
> Get:8 http://deb.debian.org/debian bookworm/main amd64 Packages [8,792 kB]
> Get:9 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.5 kB]
> Get:10 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg InRelease [129 kB]
> Get:11 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [243 kB]
> Get:12 https://dl.yarnpkg.com/debian stable/main amd64 Packages [10.9 kB]
> Get:13 https://dl.yarnpkg.com/debian stable/main all Packages [10.9 kB]
> Get:14 https://deb.nodesource.com/node_22.x nodistro/main amd64 Packages [5,274 B]
> Get:15 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 Packages [360 kB]
> Fetched 10.2 MB in 3s (3,942 kB/s)
> Reading package lists...
> Reading package lists...
> Building dependency tree...
> Reading state information...
> The following additional packages will be installed:
> postgresql-client-13
> Suggested packages:
> postgresql-doc-13
> The following NEW packages will be installed:
> postgresql-13 postgresql-13-pgvector postgresql-client-13
> 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
> Need to get 17.3 MB of archives.
> After this operation, 56.7 MB of additional disk space will be used.
> Get:1 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-client-13 amd64 13.18-1.pgdg120+1 [1,523 kB]
> Get:2 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13 amd64 13.18-1.pgdg120+1 [15.4 MB]
> Get:3 https://apt.postgresql.org/pub/repos/apt bookworm-pgdg/main amd64 postgresql-13-pgvector amd64 0.8.0-1.pgdg120+1 [297 kB]
> Fetched 17.3 MB in 2s (9,988 kB/s)
> Selecting previously unselected package postgresql-client-13.
> (Reading database ... 33363 files and directories currently installed.)
> Preparing to unpack .../postgresql-client-13_13.18-1.pgdg120+1_amd64.deb ...
> Unpacking postgresql-client-13 (13.18-1.pgdg120+1) ...
> Selecting previously unselected package postgresql-13.
> Preparing to unpack .../postgresql-13_13.18-1.pgdg120+1_amd64.deb ...
> Unpacking postgresql-13 (13.18-1.pgdg120+1) ...
> Selecting previously unselected package postgresql-13-pgvector.
> Preparing to unpack .../postgresql-13-pgvector_0.8.0-1.pgdg120+1_amd64.deb ...
> Unpacking postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
> Setting up postgresql-client-13 (13.18-1.pgdg120+1) ...
> Setting up postgresql-13 (13.18-1.pgdg120+1) ...
> Creating new PostgreSQL cluster 13/main ...
> /usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main --auth-local peer --auth-host md5
> The files belonging to this database system will be owned by user "postgres".
> This user must also own the server process.
> 
> The database cluster will be initialized with locale "C.UTF-8".
> The default database encoding has accordingly been set to "UTF8".
> The default text search configuration will be set to "english".
> 
> Data page checksums are disabled.
> 
> fixing permissions on existing directory /var/lib/postgresql/13/main ... ok
> creating subdirectories ... ok
> selecting dynamic shared memory implementation ... posix
> selecting default max_connections ... 100
> selecting default shared_buffers ... 128MB
> selecting default time zone ... Etc/UTC
> creating configuration files ... ok
> running bootstrap script ... ok
> performing post-bootstrap initialization ... ok
> syncing data to disk ... ok
> 
> Success. You can now start the database server using:
> 
> pg_ctlcluster 13 main start
> 
> invoke-rc.d: could not determine current runlevel
> invoke-rc.d: policy-rc.d denied execution of start.
> Setting up postgresql-13-pgvector (0.8.0-1.pgdg120+1) ...
> Processing triggers for postgresql-common (267.pgdg120+1) ...
> Building PostgreSQL dictionaries from installed myspell/hunspell packages...
> Removing obsolete dictionary files:
> Stopping PostgreSQL 13 database server: main.
> Stopping PostgreSQL 15 database server: main.
> Performing Consistency Checks
> -----------------------------
> Checking cluster versions ok
> 
> The source cluster was not shut down cleanly.
> Failure, exiting
> -------------------------------------------------------------------------------------
> UPGRADE OF POSTGRES FAILED
> 
> Please visit https://meta.discourse.org/t/postgresql-15-update/349515 for support.
> 
> You can run ./launcher start app to restart your app in the meanwhile
> -------------------------------------------------------------------------------------
> 
> FAILED
> --------------------
> Pups::ExecError: if [-f /root/install_postgres]; then
> /root/install_postgres && rm -f /root/install_postgres
> elif [-e /shared/postgres_run/.s.PGSQL.5432]; then
> socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
> fi
> failed with return #<Process::Status: pid 18 exit 1>
> Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
> exec failed with the params {"tag"=>"db", "cmd"=>"if [-f /root/install_postgres]; then\n /root/install_postgres && rm -f /root/install_postgres\nelif [-e /shared/postgres_run/.s.PGSQL.5432]; then\n socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1\nfi\n"}
> bootstrap failed with exit code 1
> **FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
> ./discourse-doctor may help diagnose the problem.
> e2940f8bb9e51f0f290e0b6cb78257d5fa5d7563542591405689531d1af8432b
> 
> ```

In that other thread, it was suggested to check the output of  
`tail /var/discourse/shared/standalone/log/var-log/postgres/current`

```plaintext
2025-02-05 01:03:07.494 UTC [567] LOG: received smart shutdown request
2025-02-05 01:03:08.698 UTC [567] LOG: background worker "logical replication launcher" (PID 593) exited with exit code 1
2025-02-05 01:03:08.701 UTC [588] LOG: shutting down
2025-02-05 01:03:08.786 UTC [567] LOG: database system is shut down
2025-02-05 01:03:34.209 UTC [565] LOG: starting PostgreSQL 13.14 (Debian 13.14-1.pgdg110+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2025-02-05 01:03:34.211 UTC [565] LOG: listening on IPv4 address "0.0.0.0", port 5432
2025-02-05 01:03:34.211 UTC [565] LOG: listening on IPv6 address "::", port 5432
2025-02-05 01:03:34.222 UTC [565] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2025-02-05 01:03:34.261 UTC [587] LOG: database system was shut down at 2025-02-05 01:03:08 UTC
2025-02-05 01:03:34.339 UTC [565] LOG: database system is ready to accept connections

```

There were also mentions of stopping processes etc, but I currently have zero running containers, so that doesn’t seem to apply to my situation.

I have _absolutely_ no idea what to do from here.

---

<div class="post-metadata">

### Author: ![JamesChevalier](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jameschevalier/32/116235_2.png) [@JamesChevalier](https://meta.discourse.org/u/JamesChevalier)
#### Post date: [5 februari 2025 om 16:58 UTC](https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658/3 "2025-02-05T16:58:08Z")

</div>

I decided to try again with this process:

```plaintext
rm -rf /var/discourse
rm -rf /var/lib/docker/volumes
docker stop app # on old server - I didn't realize it was still running
rsync -rvzgop root@IP:/var/discourse /var
rsync -rvz root@IP:/var/lib/docker/volumes/ /var/lib/docker/volumes
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_backup
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_data
chown -R messagebus:tss /var/discourse/shared/standalone/postgres_data_older
./launcher rebuild app

```

This _seems_ to have worked. It produced this output which I now have to decode:

```plaintext
Checking for extension updates notice

Your installation contains extensions that should be updated
with the ALTER EXTENSION command. The file
    update_extensions.sql
when executed by psql by the database superuser will update
these extensions.

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade.
Once you start the new server, consider running:
    /usr/lib/postgresql/15/bin/vacuumdb --all --analyze-in-stages

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh
-------------------------------------------------------------------------------------
UPGRADE OF POSTGRES COMPLETE

Old 13 database is stored at /shared/postgres_data_old

To complete the upgrade, rebuild again using:

./launcher rebuild app
-------------------------------------------------------------------------------------

2aa0a17599100bb507a82e6b420826c135da1e06c9623408aa4579a53ece6cb2

```

Ah, I just had to run `./launcher rebuild app` one more time. The other output about update\_extensions.sql etc seems to be from PostgreSQL itself, not Discourse’s upgrade process.

After that second rebuild run, I chose to do a cleanup with `./launcher cleanup` and then vacuum/reindex with:

```plaintext
./launcher enter app
su postgres
psql
\connect discourse
REINDEX SCHEMA CONCURRENTLY public;
VACUUM VERBOSE ANALYZE;
\q
exit
exit

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [5 februari 2025 om 17:23 UTC](https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658/4 "2025-02-05T17:23:10Z")

</div>

> [@JamesChevalier](#):
>
> I created a new server and followed the steps in [Move a Discourse site to another VPS with rsync](https://meta.discourse.org/t/move-a-discourse-site-to-another-vps-with-rsync/43812)

Well, it looks like you worked it out, but it would have been much easier to instead backup on the old server and restore the database on the new one. That way you don’t have to go through the postgres upgrade and you won’t need to muck with permissions. And you wouldn’t need to fool with the indexing and such that you probably didn’t read about in the [PostgreSQL 15 update](https://meta.discourse.org/t/postgresql-15-update/349515) topic.

---

<div class="post-metadata">

### Author: ![JamesChevalier](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jameschevalier/32/116235_2.png) [@JamesChevalier](https://meta.discourse.org/u/JamesChevalier)
#### Post date: [5 februari 2025 om 17:28 UTC](https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658/5 "2025-02-05T17:28:20Z")

</div>

I intended to do that, but the in-site upgrade fully broke everything to a state where I was required to go the rsync route.  
I didn’t save the error output in the in-site upgrade UI, so I can’t recall what the error messaging was, but I _think_ it was tied to the forum wanting something newer than Ubuntu 20.  
My first step was to try the `do-release-upgrade` in place, but that also failed - something around Docker using aufs … and the fix _there_ did not leave me feeling like the data would be safe.

I’m definitely going to read up on the indexing, thanks for the link … This new site is _slow_ 😅

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [7 maart 2025 om 17:28 UTC](https://meta.discourse.org/t/rebuild-fails-data-directory-shared-postgres-data-must-not-be-owned-by-root/350658/6 "2025-03-07T17:28:39Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
