Satellite-sync command fail with IntegrityError: duplicate key value violates unique constraint "rhn_dcm_id_pk"

Solution Verified - Updated -

Environment

  • Red Hat Satellite 5.6

Issue

  • satellite-sync command fails with :
SYNC ERROR: unhandled exception occurred:

Exception reported from freppau-lpsat01.main.glb.corp.local
Time: Fri Feb 28 12:52:29 2014
Exception type <class 'psycopg2.IntegrityError'>

Exception Handler Information
Traceback (most recent call last):
  File "/usr/bin/satellite-sync", line 139, in main
    return satsync.Runner().main()
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 229, in main
    ret = method()
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 349, in _step_errata
    self.syncer.import_errata()
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 1675, in import_errata
    sync_handlers.import_errata)
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 1576, in _proces_batch
    prompt, nevermorethan, process_function_args)
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 1556, in _processWithProgressBar
    process_function(chunk, *process_function_args)
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/sync_handlers.py", line 400, in import_errata
    importer.run()
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/importLib.py", line 647, in run
    self.submit()
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/errataImport.py", line 196, in submit
    dml = self.backend.processErrata(self.batch)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 832, in processErrata
    transactional=1)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1508, in __processObjectCollection
    return self.__processObjectCollection__(objColl, parentTable, childDict, **kwargs)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1678, in __processObjectCollection__
    return self.__doDML(dml)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1786, in __doDML
    self.__doInsert(dml.insert, dml.tables)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1793, in __doInsert
    self.__doInsertTable(tname, dict)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1807, in __doInsertTable
    insertObj.query(hash)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backendLib.py", line 431, in query
    executeStatement(statement, values, chunksize)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backendLib.py", line 456, in executeStatement
    count += statement.executemany(**tempdict)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/rhnSQL/sql_base.py", line 172, in executemany
    return apply(self._execute_wrapper, (self._executemany, ) + p, kw)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/rhnSQL/driver_postgresql.py", line 273, in _execute_wrapper
    retval = apply(function, p, kw)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/rhnSQL/driver_postgresql.py", line 310, in _executemany
    self._real_cursor.executemany(self.sql, all_kwargs)
IntegrityError: null value in column "package_id" violates not-null constrait "rhn_dcm_id_pk"
  • satellite-sync fails with
SYNC ERROR: unhandled exception occurred:

(Check logs/email for potentially more detail)

IntegrityError('duplicate key value violates unique constraint "rhn_dcm_id_pk"\n',) duplicate key value violates unique constraint "rhn_dcm_id_pk"

Resolution

  • Clearing the satellite sync cache and then attempting the satellite-sync command again proved to be successful
  • To clear the satellite sync cache and sync the channel , run the below commands:
# rm -rf /var/cache/rhn/satsync/*
# satellite-sync -c  <channel_label>

Diagnostic Steps

2013/10/18 15:11:14 -04:00 Commandline: ['/usr/bin/satellite-sync', '--debug-level=6']
....
2013/10/18 15:12:42 -04:00 17293 0.0.0.0: rhnSQL/driver_postgresql.convert_named_query_params('Converting query for PostgreSQL: insert into rhnDistChannelMap (release, channel_arch_id, org_id, channel_id, os) values (:release, :channel_arch_id, :org_id, :channel_id, :os)',)
2013/10/18 15:12:42 -04:00 17293 0.0.0.0: rhnSQL/driver_postgresql.convert_named_query_params('New query: insert into rhnDistChannelMap (release, channel_arch_id, org_id, channel_id, os) values (%(release)s, %(channel_arch_id)s, %(org_id)s, %(channel_id)s, %(os)s)',)
2013/10/18 15:12:42 -04:00 17293 0.0.0.0: rhnSQL/driver_postgresql._execute_wrapper('Executing SQL: "insert into rhnDistChannelMap (release, channel_arch_id, org_id, channel_id, os) values (%(release)s, %(channel_arch_id)s, %(org_id)s, %(channel_id)s, %(os)s)" with bind params: {release: [\'5Server\'],channel_id: [102],channel_arch_id: [508],os: [\'Red Hat Linux\'],org_id: [None]}',)
2013/10/18 15:12:42 -04:00 
SYNC ERROR: unhandled exception occurred:

Exception reported from xxxxxxx
Time: Fri Oct 18 15:12:42 2013
Exception type <class 'psycopg2.IntegrityError'>

Exception Handler Information
Traceback (most recent call last):
  File "/usr/bin/satellite-sync", line 139, in main
    return satsync.Runner().main()
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 229, in main
    ret = method()
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 305, in _step_channels
    self.syncer.process_channels()
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/satsync.py", line 682, in process_channels
    master=OPTIONS.master or None)
  File "/usr/lib/python2.6/site-packages/spacewalk/satellite_tools/sync_handlers.py", line 248, in import_channels
    importer.run()
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/importLib.py", line 647, in run
    self.submit()
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/channelImport.py", line 155, in submit
    self.backend.processChannels(nullParentBatch, True)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 938, in processChannels
    'channel_id', uploadForce=4, ignoreUploaded=1, forceVerify=1)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1508, in __processObjectCollection
    return self.__processObjectCollection__(objColl, parentTable, childDict, **kwargs)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1678, in __processObjectCollection__
    return self.__doDML(dml)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1786, in __doDML
    self.__doInsert(dml.insert, dml.tables)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1793, in __doInsert
    self.__doInsertTable(tname, dict)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backend.py", line 1807, in __doInsertTable
    insertObj.query(hash)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backendLib.py", line 431, in query
    executeStatement(statement, values, chunksize)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/importlib/backendLib.py", line 456, in executeStatement
    count += statement.executemany(**tempdict)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/rhnSQL/sql_base.py", line 172, in executemany
    return apply(self._execute_wrapper, (self._executemany, ) + p, kw)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/rhnSQL/driver_postgresql.py", line 273, in _execute_wrapper
    retval = apply(function, p, kw)
  File "/usr/lib/python2.6/site-packages/spacewalk/server/rhnSQL/driver_postgresql.py", line 310, in _executemany
    self._real_cursor.executemany(self.sql, all_kwargs)
IntegrityError: duplicate key value violates unique constraint "rhn_dcm_id_pk"

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments