PG::UndefinedTable: ERROR: relation "pg_range" does not exist

I am following the guide here:

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

[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

That’s very old.

You should be running 13.x nowadays.

2 Likes

Alright, I’ll try upgrading.

1 Like

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

Now I have this error:

[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)

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

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

Well, now I’m getting a different error:

[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)

So I descided to follow this guide:

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

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)

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