# PG::UndefinedTable: ERROR: relation "pg\_range" does not exist

**URL:** https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451
**Category:** Development
**Created:** [January 11, 2023, 6:34pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451 "2023-01-11T18:34:01Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![joecooldoo](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@joecooldoo](https://meta.discourse.org/u/joecooldoo)
#### Post date: [January 11, 2023, 6:34pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/1 "2023-01-11T18:34:01Z")

</div>

I am following the guide here:

> [@Install Discourse on Windows for development](https://meta.discourse.org/t/install-discourse-on-windows-10-for-development/75149):
>
> information_source This tutorial has been tested on Windows 10 and 11. To set up a development environment for Discourse on Windows, you can do it using [Windows Subsystem for Linux](https://msdn.microsoft.com/en-us/commandline/wsl/install-win10) feature. This setup requires the WSL 2 installation. It is only available in Windows 10 builds 18917 or higher. We’ll assume that you already installed [Windows Subsystem for Linux 2 (Ubuntu)](https://docs.microsoft.com/en-us/windows/wsl/install) on your Windows 10 system. WARNING: Install Ubuntu 18.04, and not 20.04 since some installations will fail on 20.04. For m…

When I run `bundle exec rake db:create` it just errors out and says:

```plaintext
[Warning] Discourse recommends developing using Ruby v3.1.3 or above. You are using v2.7.6.
PG::UndefinedTable: ERROR: relation "pg_range" does not exist
LINE 3: LEFT JOIN pg_range as r ON oid = rngtypid
                  ^
Couldn't create 'discourse_development' database. Please check your configuration.
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "pg_range" does not exist
LINE 3: LEFT JOIN pg_range as r ON oid = rngtypid
                  ^
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'

Caused by:
PG::UndefinedTable: ERROR: relation "pg_range" does not exist
LINE 3: LEFT JOIN pg_range as r ON oid = rngtypid
                  ^
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

```

What do I do?  
I am using WSL 2 and Ubuntu 18.04.5, and PostgreSQL version 9.2

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [January 11, 2023, 6:35pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/2 "2023-01-11T18:35:46Z")

</div>

> [@joecooldoo](#):
>
> PostgreSQL version 9.2

That’s _very_ old.

You should be running 13.x nowadays.

---

<div class="post-metadata">

### Author: ![joecooldoo](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@joecooldoo](https://meta.discourse.org/u/joecooldoo)
#### Post date: [January 11, 2023, 6:36pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/3 "2023-01-11T18:36:13Z")

</div>

Alright, I’ll try upgrading.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [January 11, 2023, 6:36pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/4 "2023-01-11T18:36:45Z")

</div>

Not sure it’s the source of your problem, but it will definitely be _more_ compatible :slight_smile:

---

<div class="post-metadata">

### Author: ![joecooldoo](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@joecooldoo](https://meta.discourse.org/u/joecooldoo)
#### Post date: [January 11, 2023, 6:38pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/5 "2023-01-11T18:38:11Z")

</div>

Now I have this error:

```plaintext
[Warning] Discourse recommends developing using Ruby v3.1.3 or above. You are using v2.7.6.
PG::UndefinedTable: ERROR: relation "pg_range" does not exist
LINE 3: LEFT JOIN pg_range as r ON oid = rngtypid
                  ^
Couldn't create 'discourse_development' database. Please check your configuration.
rake aborted!
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "pg_range" does not exist
LINE 3: LEFT JOIN pg_range as r ON oid = rngtypid
                  ^
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'

Caused by:
PG::UndefinedTable: ERROR: relation "pg_range" does not exist
LINE 3: LEFT JOIN pg_range as r ON oid = rngtypid
                  ^
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

```

---

<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: [January 11, 2023, 7:05pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/6 "2023-01-11T19:05:48Z")

</div>

> <https://stackoverflow.com/questions/57765528/rails-activerecordstatementinvalid-pgundefinedtable-error-relation-pg-ra/57765806#57765806>

According to that SO link you either have an old or corrupt database.

---

<div class="post-metadata">

### Author: ![joecooldoo](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@joecooldoo](https://meta.discourse.org/u/joecooldoo)
#### Post date: [January 11, 2023, 7:07pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/7 "2023-01-11T19:07:09Z")

</div>

How do I create a new one, then? I have never used PostgreSQL before.

---

<div class="post-metadata">

### Author: ![joecooldoo](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@joecooldoo](https://meta.discourse.org/u/joecooldoo)
#### Post date: [January 11, 2023, 7:23pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/8 "2023-01-11T19:23:44Z")

</div>

Well, now I’m getting a different error:

```plaintext
[Warning] Discourse recommends developing using Ruby v3.1.3 or above. You are using v2.7.6.
We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create
Couldn't create 'discourse_development' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'

Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `load'
/home/joecooldoo/.rbenv/versions/2.7.6/bin/bundle:25:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

```

---

<div class="post-metadata">

### Author: ![joecooldoo](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@joecooldoo](https://meta.discourse.org/u/joecooldoo)
#### Post date: [January 11, 2023, 9:47pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/9 "2023-01-11T21:47:40Z")

</div>

So I descided to follow this guide:

> [@Install Discourse for development using Docker](https://meta.discourse.org/t/install-discourse-for-development-using-docker/102009):
>
> Developing using Docker Since Discourse runs in Docker, you should be able to run Discourse directly from your source directory using a Discourse development container. white_check_mark Pros: No need to install any system dependencies, no configuration needed at all for setting up a development environment quickly. x Cons: Will be slightly slower than the native dev environment on Ubuntu, and much slower than a native install on MacOS. See also [Developing Discourse using a Dev Container](https://meta.discourse.org/t/developing-discourse-using-a-dev-container/336366) …

I get this error after the “migrating database”  
message:

```plaintext
Migrating database...
rake aborted!
Discourse::Utils::CommandError: /src/lib/discourse.rb:134:in `exec': mkdir: cannot create directory ‘/src/public/plugins/’: Permission denied
/src/lib/discourse.rb:168:in `execute_command'
/src/lib/discourse.rb:134:in `exec'
/src/lib/discourse.rb:30:in `execute_command'
/src/lib/plugin/instance.rb:727:in `activate!'
/src/lib/discourse.rb:337:in `block in activate_plugins!'
/src/lib/discourse.rb:334:in `each'
/src/lib/discourse.rb:334:in `activate_plugins!'
/src/config/application.rb:216:in `block in <class:Application>'
/src/lib/plugin.rb:6:in `initialization_guard'
/src/config/application.rb:216:in `<class:Application>'
/src/config/application.rb:75:in `<module:Discourse>'
/src/config/application.rb:74:in `<main>'
/home/discourse/.bundle/gems/ruby/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/home/discourse/.bundle/gems/ruby/3.1.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
/src/Rakefile:7:in `<main>'
(See full trace by running task with --trace)

```

---

<div class="post-metadata">

### Author: ![joecooldoo](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@joecooldoo](https://meta.discourse.org/u/joecooldoo)
#### Post date: [January 12, 2023, 7:44pm UTC](https://meta.discourse.org/t/pg-error-relation-pg-range-does-not-exist/251451/10 "2023-01-12T19:44:50Z")

</div>

I’m still having problems with this, any solutions?
