unable to connect to postgresql server

(venv) corey-james@corey-james-HP-Laptop-14-dq0xxx:~/Arborhub/MyProject$ psql -h localhost -U cortek arbordb
Password for user cortek: 
psql (16.8 (Ubuntu 16.8-0ubuntu0.24.10.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

arbordb=> psql -h localhost -U cortek arbordb
arbordb-> \q
(venv) corey-james@corey-james-HP-Laptop-14-dq0xxx:~/Arborhub/MyProject$ python manage.py makemigrations
/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/drf_haystack/__init__.py:42: UserWarning: 
==============================================================================
The `drf-haystack` project urgently needs new maintainers!

The current maintainers are no longer actively using drf-haystack and would
like to hand over the project to other developers who are using the package.

We will still do the bare minimum maintenance of keeping dependency references
up to date with new releases of related packages until January 1st 2026.

If by that time no new maintainers have joined to take over the project, we
will archive the project and make the repository read-only, with a final
release with whatever versions the dependencies have at that time.

This gives everyone more than a year to either consider joining as maintainers
or switch to other packages for handling their search in DRF.

Do you want to join as a maintainer? Have a look at:
<https://github.com/rhblind/drf-haystack/issues/146>
==============================================================================

  show_sunset_warning()
No changes detected
(venv) corey-james@corey-james-HP-Laptop-14-dq0xxx:~/Arborhub/MyProject$ python manage.py migrate
/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/drf_haystack/__init__.py:42: UserWarning: 
==============================================================================
The `drf-haystack` project urgently needs new maintainers!

The current maintainers are no longer actively using drf-haystack and would
like to hand over the project to other developers who are using the package.

We will still do the bare minimum maintenance of keeping dependency references
up to date with new releases of related packages until January 1st 2026.

If by that time no new maintainers have joined to take over the project, we
will archive the project and make the repository read-only, with a final
release with whatever versions the dependencies have at that time.

This gives everyone more than a year to either consider joining as maintainers
or switch to other packages for handling their search in DRF.

Do you want to join as a maintainer? Have a look at:
<https://github.com/rhblind/drf-haystack/issues/146>
==============================================================================

  show_sunset_warning()
Operations to perform:
  Apply all migrations: admin, arborchat, arborfindr, auth, contenttypes, django_rest_passwordreset, sessions
Running migrations:
Traceback (most recent call last):
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.InsufficientPrivilege: permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
                     ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 78, in ensure_schema
    editor.create_model(self.Migration)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 505, in create_model
    self.execute(sql, params or None)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 45, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 202, in execute
    cursor.execute(sql, params)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 122, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.ProgrammingError: permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
                     ^


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/corey-james/Arborhub/MyProject/manage.py", line 23, in <module>
    main()
  File "/home/corey-james/Arborhub/MyProject/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 357, in handle
    post_migrate_state = executor.migrate(
                         ^^^^^^^^^^^^^^^^^
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/migrations/executor.py", line 107, in migrate
    self.recorder.ensure_schema()
  File "/home/corey-james/Arborhub/MyProject/venv/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 80, in ensure_schema
    raise MigrationSchemaMissing(
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (permission denied for schema public
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
                     ^
)

Please show the shell session where you issued the grant command in my previous reply.

(venv) corey-james@corey-james-HP-Laptop-14-dq0xxx:~/Arborhub/MyProject$ psql -h localhost -U cortek arbordb
Password for user cortek: 
psql (16.8 (Ubuntu 16.8-0ubuntu0.24.10.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

arbordb=> psql -h localhost -U cortek arbordb
arbordb-> \q

I’m looking for you to show where you’re issuing the command at unable to connect to postgresql server - #41 by KenWhitesell

I don’t understand. This is specifically where I entered the command you’re talking about.

Can you please be more clear on what you’re asking me for?

I showed you a grant command to issue in psql. I want to see that command being issued in the full context of the psql output.

Okay now it shows GRANT. I’ll try and migrate again

arbordb=> grant all on schema public to cortek;
WARNING:  no privileges were granted for "public"
GRANT

And I’m still unable to run python manage.py migrate

Ok, try this command next:

alter database arbordb owner to cortek;

Inside the postgres shell correct?

1 Like
arbordb=> alter database arbordb owner to cortek;
ERROR:  must be owner of database arbordb
arbordb=> 

Damn it lol. I don’t understand what I’m doing wrong

From within psql, issue the \l command.

                                                        List of databases
    Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
------------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 arborcor   | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =Tc/postgres         +
            |          |          |                 |             |             |            |           | postgres=CTc/postgres+
            |          |          |                 |             |             |            |           | cortec=CTc/postgres
 arbordb    | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =Tc/postgres         +
            |          |          |                 |             |             |            |           | postgres=CTc/postgres+
            |          |          |                 |             |             |            |           | cortek=CTc/postgres
 arbortek78 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | 
 postgres   | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | 
 template0  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |            |           | =c/postgres          +
            |          |          |                 |             |             |            |           | postgres=CTc/postgres
 template1  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 :

Only postgres is the owner apparently

Ok, connect to the database as postgres (sudo -u postgres psql) and then run the alter database arbordb owner to cortek; command.

1 Like
postgres=# alter database arbordb owner to cortek;
ALTER DATABASE
postgres=# 

If you run the \l command again, you should see that the database is now owned by cortek. If so, try the migrate command again.

1 Like
\q
psql -h localhost -U cortek arbordb
\q
grant all on schema public to cortek;
\q
alter database arbordb owner to cortek;
\l
\q
\s
(END)