# Moving postgres db to central db server: build error

**URL:** https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615
**Category:** Self-hosting
**Created:** [November 6, 2023, 7:44pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615 "2023-11-06T19:44:34Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 6, 2023, 7:44pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/1 "2023-11-06T19:44:35Z")

</div>

Hi,  
I am currently migrating from a classical two container setup (separated web\_only and data containers) to a setup where the database is hosted on a central database server (not inside a docker container).

The central database was created from the dump.sql which is part of the backup file. The docker compose web\_only.yaml uses

## connect to central postgres database

DISCOURSE\_DB\_SOCKET: ‘’  
DISCOURSE\_DB\_USERNAME: discourse  
DISCOURSE\_DB\_PASSWORD: xxxx  
DISCOURSE\_DB\_HOST: 10.10.10.xx  
DISCOURSE\_DB\_NAME: discourse

During the build of web\_only I get the following error:

```plaintext
FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 741 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
bootstrap failed with exit code 1
**FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.

```

The database host is accessible with these data. Any ideas whats happening here? The same build with the standard database container finishes successfully.

---

<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: [November 8, 2023, 5:32am UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/2 "2023-11-08T05:32:52Z")

</div>

Are you sure that the remote database is available from the server? It looks like it’s not. Can you telnet to the database port from the web server machine?

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 10, 2023, 3:26pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/3 "2023-11-10T15:26:20Z")

</div>

Hi Jay,

I followed the thread of Falco at [Configure Discourse to use a separate PostgreSQL server](https://meta.discourse.org/t/configure-discourse-to-use-a-separate-postgresql-server/46375) The database server is available from the VM:

```plaintext
root@docker2:/var/discourse# pg_isready -d discourse -h 10.10.10.18 -p 5432 -U discourse    
10.10.10.18:5432 - Verbindungen werden angenommen

```

(connections are accepted)

The DB name, user and password in web\_only.yml are also correct. The build error is

```plaintext
FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process:
:Status: pid 829 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migra
te'"]}
bootstrap failed with exit code 1

```

I am not a ruby expert, so I would need some help with the debugging starting from the error which appears here.

Bye, Thommie

---

<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: [November 10, 2023, 4:41pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/4 "2023-11-10T16:41:48Z")

</div>

> [@Thomas\_Rother](#):
>
> The DB name, user and password in web\_only.yml are also correct.

IN that case:

> [@Thomas\_Rother](#):
>
> ```plaintext
> **FAILED TO BOOTSTRAP** please scroll up and look for earlier error messages, there may be more than one.
> 
> ```

What plugins do you have? Do you have the AI plugin?

What version of postgres are you running?

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 10, 2023, 5:33pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/5 "2023-11-10T17:33:57Z")

</div>

- PostgreSQL 13.12
- no AI plugin
- plugins:

```plaintext
cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/discourse/discourse-shared-edits.git
          - git clone https://github.com/discourse/discourse-chat-integration
          - git clone https://github.com/discourse/wp-discourse
          - git clone https://github.com/discourse/discourse-openid-connect
          - git clone https://github.com/discourse/discourse-calendar
          - git clone https://github.com/discourse/discourse-data-explorer
          - git clone https://github.com/paviliondev/discourse-events
          - git clone https://github.com/paviliondev/discourse-locations
          - git clone https://github.com/discourse/discourse-reactions
          - git clone https://github.com/discourse/discourse-chat
          - git clone https://github.com/discourse/discourse-voting.git
          - git clone https://github.com/discourse/discourse-user-notes.git
          - git clone https://github.com/discourse/discourse-solved.git
          - git clone https://github.com/discourse/discourse-footnote.git
          - git clone https://github.com/discourse/discourse-docs.git
          - git clone https://github.com/discourse/discourse-docs-card-filter.git
          - git clone https://github.com/discourse/discourse-assign.git
          - git clone https://github.com/discourse/discourse-templates.git
          - git clone https://github.com/discourse/discourse-saved-searches.git
          - git clone https://github.com/discourse/discourse-tooltips
          - git clone https://github.com/nathan-nz/discourse-wikified-posts
          - git clone https://github.com/discourse/discourse-post-voting.git
          - git clone https://github.com/discourse/discourse-encrypt.git
          - git clone https://github.com/discourse/discourse-zoom.git
          - git clone https://github.com/discourse/discourse-spoiler-alert.git
          - git clone https://github.com/discourse/discourse-category-experts.git

```

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [November 10, 2023, 6:56pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/6 "2023-11-10T18:56:17Z")

</div>

Can you

> [@Thomas\_Rother](#):
>
> please scroll up and look for earlier error messages, there may be more than one.

?

The exact error message in the backtrace will tell us exactly what is the problem 😄

> [@Thomas\_Rother](#):
>
> I am currently migrating from a classical two container setup (separated web\_only and data containers) to a setup where the database is hosted on a central database server (not inside a docker container).

Is your plan to ditch the data container?

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 10, 2023, 8:30pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/7 "2023-11-10T20:30:20Z")

</div>

error code:

```plaintext
> FAILED
> --------------------
> Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 816 exit 1>
> Location of failure: /usr/local/lib/ruby/gems/3.2.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
> exec failed with the params {"cd"=>"$home", "hook"=>"db_migrate", "cmd"=>["su discourse -c 'bundle exec rake db:migrate'"]}
> bootstrap failed with exit code 1

```

On the new system the data shall come from the central db instead of the docker db if possible.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 10, 2023, 8:37pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/8 "2023-11-10T20:37:51Z")

</div>

> [@Thomas\_Rother](#):
>
> DISCOURSE\_DB\_SOCKET: ‘’

I wonder if having this set to a blank value rather than unset will cause problems.

In any case, please post the complete output.

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 10, 2023, 9:20pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/9 "2023-11-10T21:20:26Z")

</div>

the complete build log after

./launcher rebuild web\_only

[web\_only\_build.zip](https://meta.discourse.org/uploads/short-url/JFX6IkCiv0mKA8D6FFInpLS6zM.zip) (9.4 KB)

the yaml

[web\_only.zip](https://meta.discourse.org/uploads/short-url/8wm7ks77Ej0CCqE7whGCGZU4Dx0.zip) (2.4 KB)

Concerning the DISCOURSE\_DB\_SOCKET: ‘’: as we use a remote connection, I would guess that the socket value is not relevant in both cases (dockered data or remote data)

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 10, 2023, 9:22pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/10 "2023-11-10T21:22:22Z")

</div>

The error was farther up in the build log:

```plaintext
…
docker_manager is already at latest compatible version
wp-discourse is already at latest compatible version

I, [2023-11-10T21:08:17.388213 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
Plugin name is 'discourse-topic-voting', but plugin directory is named 'discourse-voting'
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied for table users (ActiveRecord::StatementInvalid)

```

So good news! It’s connecting fine, it’s that DB permissions need adjusting.

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 10, 2023, 9:31pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/11 "2023-11-10T21:31:12Z")

</div>

Hmmmm, strange, the discourse database user has

`postgres=# GRANT ALL ON DATABASE discourse TO discourse;`

on the central postgres server. Do we need anything else for this role?

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [November 10, 2023, 9:39pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/12 "2023-11-10T21:39:27Z")

</div>

That doesn’t affect existing tables.

Offhand, perhaps:

```plaintext
ALTER DATABASE "discourse" OWNER TO "discourse";

```

or:

```plaintext
ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT ALL ON TABLES TO "discourse";

```

The postgres logs should also tell you in more detail what operations are failing.

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 10, 2023, 10:14pm UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/13 "2023-11-10T22:14:58Z")

</div>

… ok ok, irt looks as if I have some more permission issues here, see /var/log/postgresql/postgresql-13-main.log:

```plaintext
2023-11-10 22:07:58.371 UTC [196127] postgres@postgres STATEMENT: ALTER DEFAULT PRIVILEGES IN SCHEMA 'public' GRANT ALL ON TABLES TO 'discourse';
2023-11-10 22:10:18.270 UTC [196160] discourse@discourse ERROR: permission denied for table site_settings
2023-11-10 22:10:18.270 UTC [196160] discourse@discourse STATEMENT: SELECT name, data_type, value FROM site_settings
2023-11-10 22:10:18.313 UTC [196160] discourse@discourse ERROR: permission denied for table users
2023-11-10 22:10:18.313 UTC [196160] discourse@discourse STATEMENT: SELECT COUNT(*) FROM (SELECT 1 AS one FROM "users" LIMIT 20) subquery_for_count

```

---

<div class="post-metadata">

### Author: ![Thomas\_Rother](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thomas_rother/32/423597_2.png) [@Thomas\_Rother](https://meta.discourse.org/u/Thomas_Rother)
#### Post date: [November 11, 2023, 9:00am UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/14 "2023-11-11T09:00:08Z")

</div>

> [@Thomas\_Rother](#):
>
> `permission denied for table site_settings`

OK, as always, it was a “layer 8 problem” 🥲

I already had a discourse database in the postgres but the discourse user/role had not all required privileges on it. And I did miss some major “behavioural” differences between mariadb and postgres …

Now I re-created all: user, database, permissions for the user/role (including ALTER DEFAULT PRIVILEGES FOR ROLE discourse IN SCHEMA public GRANT ALL ON TABLES TO “discourse”; to match tables created by this user in the future)

The build finished and the instance runs fine with the remote postgres server, so its ready for importing the backup from the older instance.

---

<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: [December 11, 2023, 9:00am UTC](https://meta.discourse.org/t/moving-postgres-db-to-central-db-server-build-error/284615/15 "2023-12-11T09:00:17Z")

</div>

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