Controllers initially installed with MAAS 1.x fail to upgrade to 3.4

I tried to upgrade my maas install to 3.4 (from 3.2).

So I upgraded PostgreSQL to 14 first (worked perfect). After I upgraded to maas 3.3 with

snap refresh --channel=3.3 maas

which worked without problem.

but

snap refresh --channel=3.4 maas

results in SQL error:

Operations to perform:
  Apply all migrations: auth, contenttypes, maasserver, metadataserver, piston3, sessions, sites
Running migrations:
  Applying metadataserver.0034_use_builtin_json_field... OK
  Applying maasserver.0291_rdns_hostnames_as_array... OK
  Applying maasserver.0292_use_builtin_json_field...Traceback (most recent call last):
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.DatatypeMismatch: default for column "extra" cannot be cast automatically to type jsonb

Any idea what I’m missing?

Full stacktrace:

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

Traceback (most recent call last):
  File "/snap/maas/32469/bin/maas-region", line 8, in <module>
    sys.exit(run())
  File "/snap/maas/32469/lib/python3.10/site-packages/maasserver/region_script.py", line 81, in run
    run_django(is_snap, is_devenv)
  File "/snap/maas/32469/lib/python3.10/site-packages/maasserver/region_script.py", line 70, in run_django
    management.execute_from_command_line()
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/snap/maas/32469/lib/python3.10/site-packages/maasserver/management/commands/dbupgrade.py", line 125, in handle
    call_command(
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 181, in call_command
    return command.execute(*args, **defaults)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/base.py", line 89, in wrapped
    res = handle_func(*args, **kwargs)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/core/management/commands/migrate.py", line 244, in handle
    post_migrate_state = executor.migrate(
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/migrations/operations/fields.py", line 244, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/base/schema.py", line 608, in alter_field
    self._alter_field(model, old_field, new_field, old_type, new_type,
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/postgresql/schema.py", line 196, in _alter_field
    super()._alter_field(
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/base/schema.py", line 765, in _alter_field
    self.execute(
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/base/schema.py", line 145, in execute
    cursor.execute(sql, params)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 79, in _execute
    with self.db.wrap_database_errors:
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: default for column "extra" cannot be cast automatically to type jsonb

Traceback (most recent call last):
  File "/snap/maas/32469/bin/maas", line 8, in <module>
    sys.exit(main())
  File "/snap/maas/32469/lib/python3.10/site-packages/maascli/__init__.py", line 39, in main
    options.execute(options)
  File "/snap/maas/32469/lib/python3.10/site-packages/maascli/snap.py", line 481, in __call__
    raise exc
  File "/snap/maas/32469/lib/python3.10/site-packages/maascli/snap.py", line 478, in __call__
    self.handle(options)
  File "/snap/maas/32469/lib/python3.10/site-packages/maascli/snap.py", line 1037, in handle
    sys.exit(migrate_db())
  File "/snap/maas/32469/lib/python3.10/site-packages/maascli/snap.py", line 386, in migrate_db
    subprocess.check_call(
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/snap/maas/32469/bin/maas-region', 'dbupgrade']' returned non-zero exit status 1.
-----)

Hi @elektritter

thank you very much for reporting this.

May I ask you to login in the database and execute the following query on the db

select extra from maasserver_bootresourcefile;

and paste here the result?

This would help us to reproduce and fix it.

If you don’t know how to do it, I can provide you a guide step by step for it.

I could not reproduce this with the following steps on ubuntu 20.04

  • install postgresql-12
  • install maas snap 3.2/stable
  • upgrade postgresql-12 to postgresql-14
  • upgrade to 3.3/stable
  • upgrade to 3.4/stable

@elektritter could you execute that query and/or provide more information about your setup? For example if you are using custom images and similar.

Thank you very much

Here we go:

sudo -u postgres psql maasdb
could not change directory to "/root": Permission denied
psql (14.10 (Ubuntu 14.10-0ubuntu0.22.04.1))
Type "help" for help.

maasdb=# select extra from maasserver_bootresourcefile;
                                                  extra
-----------------------------------------------------------------------------------------------------------
 {"src_package": "grub2-signed", "src_release": "jammy", "src_version": "1.187.6+2.06-2ubuntu14.4"}
 {"src_package": "shim-signed", "src_release": "jammy", "src_version": "1.51.3+15.7-0ubuntu1"}
 {}
 {}
 {"kpackage": "linux-generic-hwe-18.04-edge"}
 {"kpackage": "linux-lowlatency-hwe-20.04-edge"}
 {"kpackage": "linux-generic-hwe-18.04-edge"}
 {}
 {"kpackage": "linux-lowlatency-hwe-18.04"}
 {"kpackage": "linux-lowlatency-hwe-18.04"}
 {}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {"kpackage": "linux-lowlatency"}
 {"kpackage": "linux-image-lowlatency"}
 {"kpackage": "linux-image-lowlatency"}
 {}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic-hwe-20.04"}
 {}
 {"kpackage": "linux-generic-hwe-20.04"}
 {"kpackage": "linux-generic-hwe-20.04"}
 {}
 {"kpackage": "linux-generic-hwe-20.04"}
 {}
 {"kpackage": "linux-generic-hwe-20.04-edge"}
 {"kpackage": "linux-generic-hwe-20.04-edge"}
 {"kpackage": "linux-lowlatency"}
 {}
 {}
 {"kpackage": "linux-lowlatency-hwe-20.04"}
 {"kpackage": "linux-lowlatency-hwe-20.04"}
 {"src_package": "grub2-signed", "src_release": "jammy", "src_version": "1.187.6+2.06-2ubuntu14.4"}
 {"src_package": "shim-signed", "src_release": "jammy", "src_version": "1.51.3+15.7-0ubuntu1"}
 {"kpackage": "linux-generic-hwe-18.04"}
 {"kpackage": "linux-generic-hwe-18.04"}
 {"kpackage": "linux-lowlatency-hwe-18.04-edge"}
 {"kpackage": "linux-lowlatency-hwe-18.04-edge"}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {}
 {"kpackage": "linux-lowlatency-hwe-20.04-edge"}
 {}
 {"kpackage": "linux-generic-hwe-20.04-edge"}
 {"kpackage": "linux-generic-hwe-20.04-edge"}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {"kpackage": "linux-lowlatency-hwe-22.04-edge"}
 {"kpackage": "linux-lowlatency-hwe-22.04-edge"}
 {}
 {}
 {"kpackage": "linux-generic-hwe-22.04"}
 {"kpackage": "linux-generic-hwe-22.04"}
 {}
 {"kpackage": "linux-generic-hwe-22.04-edge"}
 {"kpackage": "linux-generic-hwe-22.04-edge"}
 {}
 {"kpackage": "linux-lowlatency-hwe-22.04"}
 {"kpackage": "linux-lowlatency-hwe-22.04"}
 {}
 {"kpackage": "linux-lowlatency-hwe-22.04-edge"}
 {"kpackage": "linux-lowlatency-hwe-22.04-edge"}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {"kpackage": "linux-generic-hwe-22.04"}
 {"kpackage": "linux-generic-hwe-22.04"}
 {}
 {"kpackage": "linux-generic-hwe-22.04-edge"}
 {}
 {}
 {}
 {"src_package": "grub2", "src_release": "xenial", "src_version": "2.02~beta2-36ubuntu3.32"}
 {"src_package": "syslinux", "src_release": "focal", "src_version": "3:6.04~git20190206.bf6db5b4+dfsg1-2"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {"kpackage": "linux-image-lowlatency"}
 {"kpackage": "linux-generic-hwe-22.04-edge"}
 {"kpackage": "linux-image-lowlatency"}
 {}
 {}
 {"kpackage": "linux-lowlatency-hwe-22.04"}
 {"kpackage": "linux-lowlatency-hwe-22.04"}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-image-lowlatency"}
 {"kpackage": "linux-image-lowlatency"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
 {"kpackage": "linux-generic"}
(116 rows)

And no custom images, nothing. - at the end nothing extra, until today we just required the standard setup of MAAS for a cluster. One of the reasons for this upgrade was that I wanted to bring in required custom images.

Thank you. I still need some more debug from your side since I’m still not able to reproduce this. Could you please run in the database

maasdb=# \d maasserver_bootresourcefile;

and paste here the full output
?

psql (14.10 (Ubuntu 14.10-0ubuntu0.22.04.1))
Type "help" for help.

maasdb=# \d maasserver_bootresourcefile;
                                         Table "public.maasserver_bootresourcefile"
     Column      |           Type           | Collation | Nullable |                         Default
-----------------+--------------------------+-----------+----------+---------------------------------------------------------
 id              | integer                  |           | not null | nextval('maasserver_bootresourcefile_id_seq'::regclass)
 created         | timestamp with time zone |           | not null |
 updated         | timestamp with time zone |           | not null |
 resource_set_id | integer                  |           | not null |
 largefile_id    | integer                  |           | not null |
 filename        | character varying(255)   |           | not null |
 filetype        | character varying(20)    |           | not null | 'tgz'::character varying
 extra           | text                     |           | not null | '""'::text
Indexes:
    "maasserver_bootresourcefile_pkey" PRIMARY KEY, btree (id)
    "maasserver_bootresourcefi_resource_set_id_1bdfd52f7cc6de80_uniq" UNIQUE CONSTRAINT, btree (resource_set_id, filename)
    "maasserver_bootresourcefile_largefile_id" btree (largefile_id)
    "maasserver_bootresourcefile_resource_set_id" btree (resource_set_id)
Foreign-key constraints:
    "largefile_id_refs_id_6192daf196cc0427" FOREIGN KEY (largefile_id) REFERENCES maasserver_largefile(id) DEFERRABLE INITIALLY DEFERRED
    "resource_set_id_refs_id_5740a0afd6adefa0" FOREIGN KEY (resource_set_id) REFERENCES maasserver_bootresourceset(id) DEFERRABLE INITIALLY DEFERRED

maasdb=#

Thank you very much @elektritter , I see where is the issue now.

the default value for the column extra is '""'::text and the migration is failing to cast the column to jsonb as we should have specified how the conversion should be done.

The strange thing is that if I install maas from 3.2/stable I don’t get that default value for that column. Could you please clarify the exact history of this MAAS installation? I see you set the context in the first post, but since I could not reproduce it, I’m wondering if is there anything missing in the story.

FYI this bug has been reported as Bug #2048519 “Migration during the upgrade to 3.4 stable is fail...” : Bugs : MAAS

This is at the end an old installation - started with 2.x on Ubuntu 16 (ppa), migrated to snap on Ubuntu20 LTS in 2021, meanwhile migrated to Ubuntu 22 LTS because of the required PostgreSQL version.

Maybe somewhere in the middle of the upgrade process(es) a required migration was missing, which now results in this failure.

What should be the correct default value for the “extra” column? I could create a test-clone with current setup to test possible fixes.

Thanks for your effort and the bug report.

Right, I see now. I’d say we moved to null as default value at some point, but since your installation is from 2.x probably the default value at that time was "".
I’ll get back to you before EOD

@elektritter I went up to MAAS 2.5 but still I could not get such default column value. However, by manually setting that default value it’s possible to reproduce the issue.

The current workaround is to run

 ALTER TABLE maasserver_bootresourcefile ALTER COLUMN extra SET DEFAULT NULL;

But before you do that and you upgrade your snap, could you please run also

\d maasserver_bootresource;
\d maasserver_bootsourcecache;
\d maasserver_config;
\d maasserver_interface;
\d maasserver_notification;

so to see if also the other tables will need to be changed accordingly (paste here the output please)?

1 Like

sorry but I could not see an option for uploading a text file here, therefor all results inline.

                                         Table "public.maasserver_bootresource"
     Column      |           Type           | Collation | Nullable |                       Default                       
-----------------+--------------------------+-----------+----------+-----------------------------------------------------
 id              | integer                  |           | not null | nextval('maasserver_bootresource_id_seq'::regclass)
 created         | timestamp with time zone |           | not null | 
 updated         | timestamp with time zone |           | not null | 
 rtype           | integer                  |           | not null | 
 name            | character varying(255)   |           | not null | 
 architecture    | character varying(255)   |           | not null | 
 extra           | text                     |           | not null | '""'::text
 kflavor         | character varying(32)    |           |          | 
 bootloader_type | character varying(32)    |           |          | 
 rolling         | boolean                  |           | not null | 
 base_image      | character varying(255)   |           | not null | 
Indexes:
    "maasserver_bootresource_pkey" PRIMARY KEY, btree (id)
    "maasserver_bootresource_name_60e611bb5a9b3025_uniq" UNIQUE CONSTRAINT, btree (name, architecture)
Referenced by:
    TABLE "maasserver_bootresourceset" CONSTRAINT "resource_id_refs_id_3c29ead80420df0c" FOREIGN KEY (resource_id) REFERENCES maasserver_bootresource(id) DEFERRABLE INITIALLY DEFERRED

                                          Table "public.maasserver_bootsourcecache"
      Column      |           Type           | Collation | Nullable |                        Default                         
------------------+--------------------------+-----------+----------+--------------------------------------------------------
 id               | integer                  |           | not null | nextval('maasserver_bootsourcecache_id_seq'::regclass)
 created          | timestamp with time zone |           | not null | 
 updated          | timestamp with time zone |           | not null | 
 boot_source_id   | integer                  |           | not null | 
 os               | character varying(32)    |           | not null | 
 arch             | character varying(32)    |           | not null | 
 subarch          | character varying(32)    |           | not null | 
 release          | character varying(32)    |           | not null | 
 label            | character varying(32)    |           | not null | 
 release_codename | character varying(255)   |           |          | 
 release_title    | character varying(255)   |           |          | 
 support_eol      | date                     |           |          | 
 kflavor          | character varying(32)    |           |          | 
 bootloader_type  | character varying(32)    |           |          | 
 extra            | text                     |           | not null | 
Indexes:
    "maasserver_bootsourcecache_pkey" PRIMARY KEY, btree (id)
    "maasserver_bootsourcecache_boot_source_id" btree (boot_source_id)
Foreign-key constraints:
    "boot_source_id_refs_id_4a66762da0336fc0" FOREIGN KEY (boot_source_id) REFERENCES maasserver_bootsource(id) DEFERRABLE INITIALLY DEFERRED

                                    Table "public.maasserver_config"
 Column |          Type          | Collation | Nullable |                    Default                    
--------+------------------------+-----------+----------+-----------------------------------------------
 id     | integer                |           | not null | nextval('maasserver_config_id_seq'::regclass)
 name   | character varying(255) |           | not null | 
 value  | text                   |           |          | 
Indexes:
    "maasserver_config_pkey" PRIMARY KEY, btree (id)
    "maasserver_config_name_uniq" UNIQUE CONSTRAINT, btree (name)
Triggers:
    config_sys_dhcp_config_ntp_servers_delete AFTER DELETE ON maasserver_config FOR EACH ROW EXECUTE FUNCTION sys_dhcp_config_ntp_servers_delete()
    config_sys_dhcp_config_ntp_servers_insert AFTER INSERT ON maasserver_config FOR EACH ROW EXECUTE FUNCTION sys_dhcp_config_ntp_servers_insert()
    config_sys_dhcp_config_ntp_servers_update AFTER UPDATE ON maasserver_config FOR EACH ROW EXECUTE FUNCTION sys_dhcp_config_ntp_servers_update()
    config_sys_dns_config_insert AFTER INSERT ON maasserver_config FOR EACH ROW EXECUTE FUNCTION sys_dns_config_insert()
    config_sys_dns_config_update AFTER UPDATE ON maasserver_config FOR EACH ROW EXECUTE FUNCTION sys_dns_config_update()
    config_sys_proxy_config_use_peer_proxy_insert AFTER INSERT ON maasserver_config FOR EACH ROW EXECUTE FUNCTION sys_proxy_config_use_peer_proxy_insert()
    config_sys_proxy_config_use_peer_proxy_update AFTER UPDATE ON maasserver_config FOR EACH ROW EXECUTE FUNCTION sys_proxy_config_use_peer_proxy_update()

                                              Table "public.maasserver_interface"
          Column           |           Type           | Collation | Nullable |                     Default                      
---------------------------+--------------------------+-----------+----------+--------------------------------------------------
 id                        | integer                  |           | not null | nextval('maasserver_interface_id_seq'::regclass)
 created                   | timestamp with time zone |           | not null | 
 updated                   | timestamp with time zone |           | not null | 
 name                      | character varying(255)   |           | not null | 
 type                      | character varying(20)    |           | not null | 
 vlan_id                   | integer                  |           |          | 0
 ipv4_params               | text                     |           | not null | '""'::text
 ipv6_params               | text                     |           | not null | '""'::text
 params                    | text                     |           | not null | '""'::text
 tags                      | text[]                   |           |          | 
 mac_address               | macaddr                  |           |          | 
 enabled                   | boolean                  |           | not null | 
 acquired                  | boolean                  |           | not null | 
 mdns_discovery_state      | boolean                  |           | not null | 
 neighbour_discovery_state | boolean                  |           | not null | 
 firmware_version          | character varying(255)   |           |          | 
 product                   | character varying(255)   |           |          | 
 vendor                    | character varying(255)   |           |          | 
 interface_speed           | integer                  |           | not null | 
 link_connected            | boolean                  |           | not null | 
 link_speed                | integer                  |           | not null | 
 numa_node_id              | integer                  |           |          | 
 sriov_max_vf              | integer                  |           | not null | 
 node_config_id            | integer                  |           |          | 
Indexes:
    "maasserver_interface_pkey" PRIMARY KEY, btree (id)
    "maasserver_interface_node_config_id_a52b0f8a" btree (node_config_id)
    "maasserver_interface_node_config_id_name_348eea09_uniq" UNIQUE CONSTRAINT, btree (node_config_id, name)
    "maasserver_interface_node_config_mac_address_uniq" UNIQUE, btree (node_config_id, mac_address) WHERE type::text = 'physical'::text
    "maasserver_interface_numa_node_id_6e790407" btree (numa_node_id)
    "maasserver_interface_vlan_id" btree (vlan_id)
Check constraints:
    "maasserver_interface_interface_speed_check" CHECK (interface_speed >= 0)
    "maasserver_interface_link_speed_check" CHECK (link_speed >= 0)
    "maasserver_interface_sriov_max_vf_check" CHECK (sriov_max_vf >= 0)
Foreign-key constraints:
    "maasserver_interf_vlan_id_8b9cf77d98d6e56_fk_maasserver_vlan_id" FOREIGN KEY (vlan_id) REFERENCES maasserver_vlan(id) DEFERRABLE INITIALLY DEFERRED
    "maasserver_interface_node_config_id_a52b0f8a_fk_maasserve" FOREIGN KEY (node_config_id) REFERENCES maasserver_nodeconfig(id) DEFERRABLE INITIALLY DEFERRED
    "maasserver_interface_numa_node_id_6e790407_fk_maasserve" FOREIGN KEY (numa_node_id) REFERENCES maasserver_numanode(id) DEFERRABLE INITIALLY DEFERRED
Referenced by:
    TABLE "maasserver_node" CONSTRAINT "boot_interface_id_refs_id_2a6884e970eb7165" FOREIGN KEY (boot_interface_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "maasserver_interfacerelationship" CONSTRAINT "child_id_refs_id_14965a34c1e9f96d" FOREIGN KEY (child_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "maasserver_interface_ip_addresses" CONSTRAINT "interface_id_refs_id_1d0a9cd9772ab207" FOREIGN KEY (interface_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "maasserver_mdns" CONSTRAINT "maasse_interface_id_59293bdc17c7b4a1_fk_maasserver_interface_id" FOREIGN KEY (interface_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "maasserver_neighbour" CONSTRAINT "maasse_interface_id_5e7a94a2d3b506a3_fk_maasserver_interface_id" FOREIGN KEY (interface_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "maasserver_nodedevice" CONSTRAINT "maasserver_nodedevic_physical_interface_i_ee476ae3_fk_maasserve" FOREIGN KEY (physical_interface_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "maasserver_virtualmachineinterface" CONSTRAINT "maasserver_virtualma_host_interface_id_9408be99_fk_maasserve" FOREIGN KEY (host_interface_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "metadataserver_scriptresult" CONSTRAINT "metadataserver_scrip_interface_id_a120e25e_fk_maasserve" FOREIGN KEY (interface_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
    TABLE "maasserver_interfacerelationship" CONSTRAINT "parent_id_refs_id_14965a34c1e9f96d" FOREIGN KEY (parent_id) REFERENCES maasserver_interface(id) DEFERRABLE INITIALLY DEFERRED
Triggers:
    interface_interface_pod_notify AFTER INSERT OR DELETE OR UPDATE ON maasserver_interface FOR EACH ROW EXECUTE FUNCTION interface_pod_notify()
    interface_nd_interface_link_notify AFTER INSERT ON maasserver_interface FOR EACH ROW EXECUTE FUNCTION nd_interface_link_notify()
    interface_nd_interface_unlink_notify AFTER DELETE ON maasserver_interface FOR EACH ROW EXECUTE FUNCTION nd_interface_unlink_notify()
    interface_nd_interface_update_notify AFTER UPDATE ON maasserver_interface FOR EACH ROW EXECUTE FUNCTION nd_interface_update_notify()
    interface_sys_dhcp_interface_update AFTER UPDATE ON maasserver_interface FOR EACH ROW EXECUTE FUNCTION sys_dhcp_interface_update()
    interface_sys_dns_interface_update AFTER UPDATE ON maasserver_interface FOR EACH ROW EXECUTE FUNCTION sys_dns_interface_update()
    interface_sys_dns_updates_maasserver_interface_delete AFTER DELETE ON maasserver_interface FOR EACH ROW EXECUTE FUNCTION sys_dns_updates_maasserver_interface_delete()

                                       Table "public.maasserver_notification"
   Column    |           Type           | Collation | Nullable |                       Default                       
-------------+--------------------------+-----------+----------+-----------------------------------------------------
 id          | integer                  |           | not null | nextval('maasserver_notification_id_seq'::regclass)
 created     | timestamp with time zone |           | not null | 
 updated     | timestamp with time zone |           | not null | 
 ident       | character varying(40)    |           |          | 
 users       | boolean                  |           | not null | 
 admins      | boolean                  |           | not null | 
 message     | text                     |           | not null | 
 context     | text                     |           | not null | 
 user_id     | integer                  |           |          | 
 category    | character varying(10)    |           | not null | 
 dismissable | boolean                  |           | not null | 
Indexes:
    "maasserver_notification_pkey" PRIMARY KEY, btree (id)
    "maasserver_notification_e8701ad4" btree (user_id)
    "maasserver_notification_ident_d81e5931_like" btree (ident varchar_pattern_ops)
    "maasserver_notification_ident_d81e5931_uniq" UNIQUE CONSTRAINT, btree (ident)
Foreign-key constraints:
    "maasserver_notification_user_id_5a4d1d18_fk" FOREIGN KEY (user_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED
Referenced by:
    TABLE "maasserver_notificationdismissal" CONSTRAINT "notification_id_319d0205c6009f14_fk_maasserver_notification_id" FOREIGN KEY (notification_id) REFERENCES maasserver_notification(id) DEFERRABLE INITIALLY DEFERRED
Triggers:
    notification_notification_create_notify AFTER INSERT ON maasserver_notification FOR EACH ROW EXECUTE FUNCTION notification_create_notify()
    notification_notification_delete_notify AFTER DELETE ON maasserver_notification FOR EACH ROW EXECUTE FUNCTION notification_delete_notify()
    notification_notification_update_notify AFTER UPDATE ON maasserver_notification FOR EACH ROW EXECUTE FUNCTION notification_update_notify()

Tried to upgrade, but failed.
Together with your information I tried following:

maasdb=# ALTER TABLE maasserver_bootresourcefile ALTER COLUMN extra SET DEFAULT NULL;
ALTER TABLE
maasdb=# ALTER TABLE maasserver_bootresource ALTER COLUMN extra SET DEFAULT NULL;
ALTER TABLE
maasdb=# ALTER TABLE maasserver_interface ALTER COLUMN ipv4_params SET DEFAULT NULL;
ALTER TABLE
maasdb=# ALTER TABLE maasserver_interface ALTER COLUMN ipv6_params SET DEFAULT NULL;
ALTER TABLE
maasdb=# ALTER TABLE maasserver_interface ALTER COLUMN params SET DEFAULT NULL;
ALTER TABLE
maasdb=#

So the jsonb error went away. But now I get

django.db.utils.DataError: setval: value 0 is out of bounds for sequence "maasserver_vlan_id_seq" (1..9223372036854775807)

And this drives me somewhat crazy - of course 0 is out of bounds. Meanwhile I believe I should think about an alternative way to fix the database.

Edit: We have no vlans defined until today because our setup/use case didn’t require it. That’s why it tries to set it to 0. I think, the upgrade script should simply ignore the value “0” (eg, no vlan available)

@elektritter what is the migration that is failing with

django.db.utils.DataError: setval: value 0 is out of bounds for sequence "maasserver_vlan_id_seq" (1..9223372036854775807)

?

Operations to perform:
  Apply all migrations: auth, contenttypes, maasserver, metadataserver, piston3, sessions, sites
Running migrations:
  Applying metadataserver.0034_use_builtin_json_field... OK
  Applying maasserver.0291_rdns_hostnames_as_array... OK
  Applying maasserver.0292_use_builtin_json_field... OK
  Applying maasserver.0293_drop_verbose_regex_validator... OK
  Applying maasserver.0294_keyring_data_binary_field... OK
  Applying maasserver.0295_macaddress_text_field... OK
  Applying metadataserver.0035_move_metadata_node_models... OK
  Applying metadataserver.0036_move_metadata_script_models... OK
  Applying maasserver.0296_move_metadata_node_models... OK
  Applying maasserver.0297_move_metadata_script_models... OK
  Applying maasserver.0298_current_script_set_foreign_keys_drop_indexes... OK
  Applying maasserver.0299_current_script_set_foreign_keys_cleanup... OK
  Applying maasserver.0300_current_script_set_foreign_keys_readd... OK
  Applying maasserver.0301_discovery_ignore_fks... OK
  Applying maasserver.0302_big_auto_field...Traceback (most recent call last):
  File "/snap/maas/32469/usr/lib/python3/dist-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.NumericValueOutOfRange: setval: value 0 is out of bounds for sequence "maasserver_vlan_id_seq" (1..9223372036854775807)

Allright I managed to reproduce the errors.

FYI your original installation was even a MAAS 1.x :slight_smile: We are working on the fixes

May be. I just took this over years ago :slight_smile:

Thanks!

@elektritter here’s the fix Merge into master : lp-2048519 : lp:~r00ta/maas : Git : Code : MAAS

As temporary workaround, before we release 3.4.1 with the fix, you can run

ALTER TABLE maasserver_bootresourcefile ALTER COLUMN extra SET DEFAULT NULL;
ALTER TABLE maasserver_bootresource ALTER COLUMN extra SET DEFAULT NULL;
ALTER TABLE maasserver_interface ALTER COLUMN ipv4_params SET DEFAULT NULL;
ALTER TABLE maasserver_interface ALTER COLUMN ipv6_params SET DEFAULT NULL;
ALTER TABLE maasserver_interface ALTER COLUMN params SET DEFAULT NULL;
ALTER TABLE maasserver_interface ALTER COLUMN vlan_id SET DEFAULT NULL;

CREATE OR REPLACE FUNCTION migrate_vlan_sequence_lp_2048519(original_id int)
RETURNS void AS $$
DECLARE
    new_record_id INT;
BEGIN
    IF EXISTS ( 
        SELECT id from maasserver_vlan WHERE id = original_id
    )
    THEN 
        new_record_id := nextval('maasserver_vlan_id_seq');
        UPDATE maasserver_vlan
            SET id = new_record_id
            WHERE id = original_id;
        
        UPDATE maasserver_interface
            SET vlan_id = new_record_id
            WHERE vlan_id = original_id;
    
        UPDATE maasserver_subnet
            SET vlan_id = new_record_id
            WHERE vlan_id = original_id;
    
        UPDATE maasserver_vlan
            SET relay_vlan_id = new_record_id
            WHERE relay_vlan_id = original_id;
    END IF;
END;
$$ LANGUAGE plpgsql;

SELECT migrate_vlan_sequence_lp_2048519(0);
DROP FUNCTION migrate_vlan_sequence_lp_2048519;

CREATE OR REPLACE FUNCTION migrate_space_sequence_lp_2048519(original_id int)
RETURNS void AS $$
DECLARE
    new_record_id INT;
BEGIN
    IF EXISTS ( 
        SELECT id from maasserver_space WHERE id = original_id
    )
    THEN
        new_record_id := nextval('maasserver_space_id_seq');
        UPDATE maasserver_space
            SET id = new_record_id
            WHERE id = original_id;

        UPDATE maasserver_vlan
            SET space_id = new_record_id
            WHERE space_id = original_id;
    END IF;
END;
$$ LANGUAGE plpgsql;

SELECT migrate_space_sequence_lp_2048519(0);
DROP FUNCTION migrate_space_sequence_lp_2048519;

and then you refresh the snap with 3.4. Please let me know if you face any other issue!

WORKED! :slight_smile:

Thanks for this.

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