postgres schema needs updating

Bug #765782 reported by Marc
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Medium
Mark Washenberger

Bug Description

I'm getting an error from nova-compute (cactus) running against a postgres db:

2011-04-13 14:35:12,073 AUDIT nova [-] Starting compute node (version 2011.2-workspace:tarmac-20110412221228-m3on9aiaj4eqhx8i)
2011-04-13 14:35:12,215 DEBUG nova.utils [-] backend <module 'nova.db.sqlalchemy.api' from '/usr/lib/pymodules/python2.6/nova/db/sqlalchemy/api.pyc'> from (pid=28546) __get_backend /usr/lib/pymodules/python2.6/nova/utils.py:427
2011-04-13 14:35:12,305 CRITICAL nova [-] (ProgrammingError) operator does not exist: character varying = integer
LINE 2: ...AS instance_types_1 ON instances.instance_type_id = instance...
                                                             ^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
 'SELECT instances.created_at AS instances_created_at, instances.updated_at AS instances_updated_at, instances.deleted_at AS instances_deleted_at, instances.deleted AS instances_deleted, instances.id AS instances_id, instances.admin_pass AS instances_admin_pass, instances.user_id AS instances_user_id, instances.project_id AS instances_project_id, instances.image_id AS instances_image_id, instances.kernel_id AS instances_kernel_id, instances.ramdisk_id AS instances_ramdisk_id, instances.launch_index AS instances_launch_index, instances.key_name AS instances_key_name, instances.key_data AS instances_key_data, instances.state AS instances_state, instances.state_description AS instances_state_description, instances.memory_mb AS instances_memory_mb, instances.vcpus AS instances_vcpus, instances.local_gb AS instances_local_gb, instances.hostname AS instances_hostname, instances.host AS instances_host, instances.instance_type_id AS instances_instance_type_id, instances.user_data AS instances_user_data, instances.reservation_id AS instances_reservation_id, instances.mac_address AS instances_mac_address, instances.scheduled_at AS instances_scheduled_at, instances.launched_at AS instances_launched_at, instances.terminated_at AS instances_terminated_at, instances.availability_zone AS instances_availability_zone, instances.display_name AS instances_display_name, instances.display_description AS instances_display_description, instances.launched_on AS instances_launched_on, instances.locked AS instances_locked, instances.os_type AS instances_os_type, networks_1.created_at AS networks_1_created_at, networks_1.updated_at AS networks_1_updated_at, networks_1.deleted_at AS networks_1_deleted_at, networks_1.deleted AS networks_1_deleted, networks_1.id AS networks_1_id, networks_1.label AS networks_1_label, networks_1.injected AS networks_1_injected, networks_1.cidr AS networks_1_cidr, networks_1.cidr_v6 AS networks_1_cidr_v6, networks_1.gateway_v6 AS networks_1_gateway_v6, networks_1.netmask_v6 AS networks_1_netmask_v6, networks_1.netmask AS networks_1_netmask, networks_1.bridge AS networks_1_bridge, networks_1.gateway AS networks_1_gateway, networks_1.broadcast AS networks_1_broadcast, networks_1.dns AS networks_1_dns, networks_1.vlan AS networks_1_vlan, networks_1.vpn_public_address AS networks_1_vpn_public_address, networks_1.vpn_public_port AS networks_1_vpn_public_port, networks_1.vpn_private_address AS networks_1_vpn_private_address, networks_1.dhcp_start AS networks_1_dhcp_start, networks_1.project_id AS networks_1_project_id, networks_1.host AS networks_1_host, fixed_ips_1.created_at AS fixed_ips_1_created_at, fixed_ips_1.updated_at AS fixed_ips_1_updated_at, fixed_ips_1.deleted_at AS fixed_ips_1_deleted_at, fixed_ips_1.deleted AS fixed_ips_1_deleted, fixed_ips_1.id AS fixed_ips_1_id, fixed_ips_1.address AS fixed_ips_1_address, fixed_ips_1.network_id AS fixed_ips_1_network_id, fixed_ips_1.instance_id AS fixed_ips_1_instance_id, fixed_ips_1.allocated AS fixed_ips_1_allocated, fixed_ips_1.leased AS fixed_ips_1_leased, fixed_ips_1.reserved AS fixed_ips_1_reserved, floating_ips_1.created_at AS floating_ips_1_created_at, floating_ips_1.updated_at AS floating_ips_1_updated_at, floating_ips_1.deleted_at AS floating_ips_1_deleted_at, floating_ips_1.deleted AS floating_ips_1_deleted, floating_ips_1.id AS floating_ips_1_id, floating_ips_1.address AS floating_ips_1_address, floating_ips_1.fixed_ip_id AS floating_ips_1_fixed_ip_id, floating_ips_1.project_id AS floating_ips_1_project_id, floating_ips_1.host AS floating_ips_1_host, security_groups_1.created_at AS security_groups_1_created_at, security_groups_1.updated_at AS security_groups_1_updated_at, security_groups_1.deleted_at AS security_groups_1_deleted_at, security_groups_1.deleted AS security_groups_1_deleted, security_groups_1.id AS security_groups_1_id, security_groups_1.name AS security_groups_1_name, security_groups_1.description AS security_groups_1_description, security_groups_1.user_id AS security_groups_1_user_id, security_groups_1.project_id AS security_groups_1_project_id, instance_types_1.created_at AS instance_types_1_created_at, instance_types_1.updated_at AS instance_types_1_updated_at, instance_types_1.deleted_at AS instance_types_1_deleted_at, instance_types_1.deleted AS instance_types_1_deleted, instance_types_1.id AS instance_types_1_id, instance_types_1.name AS instance_types_1_name, instance_types_1.memory_mb AS instance_types_1_memory_mb, instance_types_1.vcpus AS instance_types_1_vcpus, instance_types_1.local_gb AS instance_types_1_local_gb, instance_types_1.flavorid AS instance_types_1_flavorid, instance_types_1.swap AS instance_types_1_swap, instance_types_1.rxtx_quota AS instance_types_1_rxtx_quota, instance_types_1.rxtx_cap AS instance_types_1_rxtx_cap \nFROM instances LEFT OUTER JOIN fixed_ips AS fixed_ips_1 ON fixed_ips_1.instance_id = instances.id AND fixed_ips_1.deleted = %(deleted_1)s LEFT OUTER JOIN networks AS networks_1 ON networks_1.id = fixed_ips_1.network_id LEFT OUTER JOIN floating_ips AS floating_ips_1 ON floating_ips_1.fixed_ip_id = fixed_ips_1.id AND floating_ips_1.deleted = %(deleted_2)s LEFT OUTER JOIN security_group_instance_association AS security_group_instance_association_1 ON security_group_instance_association_1.instance_id = instances.id AND instances.deleted = %(deleted_3)s LEFT OUTER JOIN security_groups AS security_groups_1 ON security_groups_1.id = security_group_instance_association_1.security_group_id AND security_group_instance_association_1.deleted = %(deleted_4)s AND security_groups_1.deleted = %(deleted_5)s LEFT OUTER JOIN instance_types AS instance_types_1 ON instances.instance_type_id = instance_types_1.id \nWHERE instances.host = %(host_1)s AND instances.deleted = %(deleted_6)s' {'host_1': 'hera', 'deleted_6': False, 'deleted_5': False, 'deleted_4': False, 'deleted_3': False, 'deleted_2': False, 'deleted_1': False}
(nova): TRACE: Traceback (most recent call last):
(nova): TRACE: File "/usr/bin/nova-compute", line 48, in <module>
(nova): TRACE: service.serve()
(nova): TRACE: File "/usr/lib/pymodules/python2.6/nova/service.py", line 290, in serve
(nova): TRACE: x.start()
(nova): TRACE: File "/usr/lib/pymodules/python2.6/nova/service.py", line 84, in start
(nova): TRACE: self.manager.init_host()
(nova): TRACE: File "/usr/lib/pymodules/python2.6/nova/compute/manager.py", line 142, in init_host
(nova): TRACE: self.driver.init_host(host=self.host)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/nova/virt/libvirt_conn.py", line 225, in init_host
(nova): TRACE: for instance in db.instance_get_all_by_host(ctxt, host):
(nova): TRACE: File "/usr/lib/pymodules/python2.6/nova/db/api.py", line 431, in instance_get_all_by_host
(nova): TRACE: return IMPL.instance_get_all_by_host(context, host)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/nova/db/sqlalchemy/api.py", line 98, in wrapper
(nova): TRACE: return f(*args, **kwargs)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/nova/db/sqlalchemy/api.py", line 891, in instance_get_all_by_host
(nova): TRACE: filter_by(deleted=can_read_deleted(context)).\
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/orm/query.py", line 1453, in all
(nova): TRACE: return list(self)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/orm/query.py", line 1565, in __iter__
(nova): TRACE: return self._execute_and_instances(context)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/orm/query.py", line 1570, in _execute_and_instances
(nova): TRACE: mapper=self._mapper_zero_or_none())
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/orm/session.py", line 735, in execute
(nova): TRACE: clause, params or {})
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/engine/base.py", line 1157, in execute
(nova): TRACE: params)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/engine/base.py", line 1237, in _execute_clauseelement
(nova): TRACE: return self.__execute_context(context)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/engine/base.py", line 1268, in __execute_context
(nova): TRACE: context.parameters[0], context=context)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/engine/base.py", line 1367, in _cursor_execute
(nova): TRACE: context)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/engine/base.py", line 1360, in _cursor_execute
(nova): TRACE: context)
(nova): TRACE: File "/usr/lib/pymodules/python2.6/sqlalchemy/engine/default.py", line 288, in do_execute
(nova): TRACE: cursor.execute(statement, parameters)
(nova): TRACE: ProgrammingError: (ProgrammingError) operator does not exist: character varying = integer
(nova): TRACE: LINE 2: ...AS instance_types_1 ON instances.instance_type_id = instance...
(nova): TRACE: ^
(nova): TRACE: HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
(nova): TRACE: 'SELECT instances.created_at AS instances_created_at, instances.updated_at AS instances_updated_at, instances.deleted_at AS instances_deleted_at, instances.deleted AS instances_deleted, instances.id AS instances_id, instances.admin_pass AS instances_admin_pass, instances.user_id AS instances_user_id, instances.project_id AS instances_project_id, instances.image_id AS instances_image_id, instances.kernel_id AS instances_kernel_id, instances.ramdisk_id AS instances_ramdisk_id, instances.launch_index AS instances_launch_index, instances.key_name AS instances_key_name, instances.key_data AS instances_key_data, instances.state AS instances_state, instances.state_description AS instances_state_description, instances.memory_mb AS instances_memory_mb, instances.vcpus AS instances_vcpus, instances.local_gb AS instances_local_gb, instances.hostname AS instances_hostname, instances.host AS instances_host, instances.instance_type_id AS instances_instance_type_id, instances.user_data AS instances_user_data, instances.reservation_id AS instances_reservation_id, instances.mac_address AS instances_mac_address, instances.scheduled_at AS instances_scheduled_at, instances.launched_at AS instances_launched_at, instances.terminated_at AS instances_terminated_at, instances.availability_zone AS instances_availability_zone, instances.display_name AS instances_display_name, instances.display_description AS instances_display_description, instances.launched_on AS instances_launched_on, instances.locked AS instances_locked, instances.os_type AS instances_os_type, networks_1.created_at AS networks_1_created_at, networks_1.updated_at AS networks_1_updated_at, networks_1.deleted_at AS networks_1_deleted_at, networks_1.deleted AS networks_1_deleted, networks_1.id AS networks_1_id, networks_1.label AS networks_1_label, networks_1.injected AS networks_1_injected, networks_1.cidr AS networks_1_cidr, networks_1.cidr_v6 AS networks_1_cidr_v6, networks_1.gateway_v6 AS networks_1_gateway_v6, networks_1.netmask_v6 AS networks_1_netmask_v6, networks_1.netmask AS networks_1_netmask, networks_1.bridge AS networks_1_bridge, networks_1.gateway AS networks_1_gateway, networks_1.broadcast AS networks_1_broadcast, networks_1.dns AS networks_1_dns, networks_1.vlan AS networks_1_vlan, networks_1.vpn_public_address AS networks_1_vpn_public_address, networks_1.vpn_public_port AS networks_1_vpn_public_port, networks_1.vpn_private_address AS networks_1_vpn_private_address, networks_1.dhcp_start AS networks_1_dhcp_start, networks_1.project_id AS networks_1_project_id, networks_1.host AS networks_1_host, fixed_ips_1.created_at AS fixed_ips_1_created_at, fixed_ips_1.updated_at AS fixed_ips_1_updated_at, fixed_ips_1.deleted_at AS fixed_ips_1_deleted_at, fixed_ips_1.deleted AS fixed_ips_1_deleted, fixed_ips_1.id AS fixed_ips_1_id, fixed_ips_1.address AS fixed_ips_1_address, fixed_ips_1.network_id AS fixed_ips_1_network_id, fixed_ips_1.instance_id AS fixed_ips_1_instance_id, fixed_ips_1.allocated AS fixed_ips_1_allocated, fixed_ips_1.leased AS fixed_ips_1_leased, fixed_ips_1.reserved AS fixed_ips_1_reserved, floating_ips_1.created_at AS floating_ips_1_created_at, floating_ips_1.updated_at AS floating_ips_1_updated_at, floating_ips_1.deleted_at AS floating_ips_1_deleted_at, floating_ips_1.deleted AS floating_ips_1_deleted, floating_ips_1.id AS floating_ips_1_id, floating_ips_1.address AS floating_ips_1_address, floating_ips_1.fixed_ip_id AS floating_ips_1_fixed_ip_id, floating_ips_1.project_id AS floating_ips_1_project_id, floating_ips_1.host AS floating_ips_1_host, security_groups_1.created_at AS security_groups_1_created_at, security_groups_1.updated_at AS security_groups_1_updated_at, security_groups_1.deleted_at AS security_groups_1_deleted_at, security_groups_1.deleted AS security_groups_1_deleted, security_groups_1.id AS security_groups_1_id, security_groups_1.name AS security_groups_1_name, security_groups_1.description AS security_groups_1_description, security_groups_1.user_id AS security_groups_1_user_id, security_groups_1.project_id AS security_groups_1_project_id, instance_types_1.created_at AS instance_types_1_created_at, instance_types_1.updated_at AS instance_types_1_updated_at, instance_types_1.deleted_at AS instance_types_1_deleted_at, instance_types_1.deleted AS instance_types_1_deleted, instance_types_1.id AS instance_types_1_id, instance_types_1.name AS instance_types_1_name, instance_types_1.memory_mb AS instance_types_1_memory_mb, instance_types_1.vcpus AS instance_types_1_vcpus, instance_types_1.local_gb AS instance_types_1_local_gb, instance_types_1.flavorid AS instance_types_1_flavorid, instance_types_1.swap AS instance_types_1_swap, instance_types_1.rxtx_quota AS instance_types_1_rxtx_quota, instance_types_1.rxtx_cap AS instance_types_1_rxtx_cap \nFROM instances LEFT OUTER JOIN fixed_ips AS fixed_ips_1 ON fixed_ips_1.instance_id = instances.id AND fixed_ips_1.deleted = %(deleted_1)s LEFT OUTER JOIN networks AS networks_1 ON networks_1.id = fixed_ips_1.network_id LEFT OUTER JOIN floating_ips AS floating_ips_1 ON floating_ips_1.fixed_ip_id = fixed_ips_1.id AND floating_ips_1.deleted = %(deleted_2)s LEFT OUTER JOIN security_group_instance_association AS security_group_instance_association_1 ON security_group_instance_association_1.instance_id = instances.id AND instances.deleted = %(deleted_3)s LEFT OUTER JOIN security_groups AS security_groups_1 ON security_groups_1.id = security_group_instance_association_1.security_group_id AND security_group_instance_association_1.deleted = %(deleted_4)s AND security_groups_1.deleted = %(deleted_5)s LEFT OUTER JOIN instance_types AS instance_types_1 ON instances.instance_type_id = instance_types_1.id \nWHERE instances.host = %(host_1)s AND instances.deleted = %(deleted_6)s' {'host_1': 'hera', 'deleted_6': False, 'deleted_5': False, 'deleted_4': False, 'deleted_3': False, 'deleted_2': False, 'deleted_1': False}
(nova): TRACE:

The following SQL fixes this bug:

alter table instances alter instance_type_id type integer using cast(instance_type_id as integer);

Related branches

Revision history for this message
Dan Prince (dan-prince) wrote :

Just curious. Are you using a database instance that was installed pre-cactus? If so there was a late schema change in the Cactus release cycle that changed instance_type to instance_type_id.

Can you try running 'nova-manage db sync' on your database server. This should get your database in sync with the schema changes in the Cactus release.

Hope this helps.

Revision history for this message
Dan Prince (dan-prince) wrote :

One more thing. You can check to make sure your DB is up to date with the following query:

select version from migrate_version;
+---------+
| version |
+---------+
| 14 |

--

The Cactus release should have the version set to '14'.

Revision history for this message
Marc (nerens) wrote :

Hi Dan,

I created a new db to test cactus, this was during the RC release so not sure if the changes where made afterward?

I've just deleted and recreated my nova db, run nova-manage db sync and version says it's 14 but I'm still seeing those errors. After running that SQL again it's fixed the issue.

Thanks,
Marc

Dan Prince (dan-prince)
Changed in nova:
assignee: nobody → Dan Prince (dan-prince)
Dan Prince (dan-prince)
Changed in nova:
status: New → In Progress
Revision history for this message
Dan Prince (dan-prince) wrote :

Hmm. I think I see what is happening here. The instance_type_id column should have been an integer. When I created the migration to convert instance_type to instance_type_id I made it a string to match the type of some of the existing DB columns:

 image_id VARCHAR(255),
 kernel_id VARCHAR(255),
 ramdisk_id VARCHAR(255)

So I made instance_type_id a VARCHAR as well to make things consistent:

 instance_type_id VARCHAR(255)

Since instance_type_id is obviously used more heavily in joins, etc this appears to have been the wrong decision. MySQL and Sqlite seem to handle the casts fine. Apparently Postgres doesn't. Going to review this a bit but the solution here seems simple enough. We should just make instance_type_id an integer and go with it.

Changed in nova:
assignee: Dan Prince (dan-prince) → Mark Washenberger (markwash)
Thierry Carrez (ttx)
Changed in nova:
importance: Undecided → High
importance: High → Medium
Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → diablo-1
Thierry Carrez (ttx)
Changed in nova:
milestone: diablo-1 → 2011.3
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.