Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2223567 - Postgresql logs contain PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "katello_available_module_streams_name_stream_context"
Summary: Postgresql logs contain PG::UniqueViolation: ERROR: duplicate key value viola...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Hosts - Content
Version: 6.13.2
Hardware: Unspecified
OS: Unspecified
high
medium
Target Milestone: 6.15.0
Assignee: Jeremy Lenz
QA Contact: visawant
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-07-18 09:42 UTC by Jan Jansky
Modified: 2024-05-05 11:29 UTC (History)
12 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2266147 (view as bug list)
Environment:
Last Closed: 2024-04-23 17:11:43 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 37137 0 High New Postgresql logs contain PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "katello_available_mo... 2024-02-01 22:03:15 UTC
Red Hat Bugzilla 2139545 0 high CLOSED Registration error: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "katello_available_modul... 2024-05-20 09:09:27 UTC
Red Hat Issue Tracker SAT-19116 0 None None None 2023-07-24 12:53:23 UTC
Red Hat Product Errata RHSA-2024:2010 0 None None None 2024-04-23 17:11:45 UTC

Description Jan Jansky 2023-07-18 09:42:23 UTC
Description of problem:
This seems to be regression of BZ 2139545.

During registration violation of unique constraint is hit as below

PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "katello_available_module_streams_name_stream_context"

It seems like previous bugzilla just removed the log from /var/log/foreman/production, but postgresql still reflects same issue as below:

2023-07-18 13:31:36 CEST ERROR:  duplicate key value violates unique constraint "katello_available_module_streams_name_stream_context"
2023-07-18 13:31:36 CEST DETAIL:  Key (name, stream, context)=(python36, 3.6, 683b2e54) already exists.
2023-07-18 13:31:36 CEST STATEMENT:  INSERT INTO "katello_available_module_streams" ("name", "stream", "context") VALUES ($1, $2, $3) RETURNING "id"
2023-07-18 13:31:36 CEST ERROR:  duplicate key value violates unique constraint "katello_available_module_streams_name_stream_context"
2023-07-18 13:31:36 CEST DETAIL:  Key (name, stream, context)=(ruby, 2.5, ad008a3a) already exists.
2023-07-18 13:31:36 CEST STATEMENT:  INSERT INTO "katello_available_module_streams" ("name", "stream", "context") VALUES ($1, $2, $3) RETURNING "id"

Version-Release number of selected component (if applicable):
Satellite 6.13.2

How reproducible:
Always

Steps to Reproduce:
1. re-register RHEL8 host

Actual results:
/var/log/foreman/production.log
2023-07-18T13:31:36 [I|app|9ba09d93] Processing by Katello::Api::Rhsm::CandlepinDynflowProxyController#upload_profiles as JSON
2023-07-18T13:31:36 [I|app|9ba09d93]   Parameters: {"id"=>"1b137c1f-62d0-440b-acb7-9a55c342dd45"}
2023-07-18T13:31:36 [I|app|9ba09d93] Completed 200 OK in 167ms (Views: 6.1ms | ActiveRecord: 56.7ms | Allocations: 52327)

/var/lib/pgsql/data/log/postgresql-Tue.log
2023-07-18 13:31:36 CEST ERROR:  duplicate key value violates unique constraint "katello_available_module_streams_name_stream_context"
2023-07-18 13:31:36 CEST DETAIL:  Key (name, stream, context)=(python36, 3.6, 683b2e54) already exists.
2023-07-18 13:31:36 CEST STATEMENT:  INSERT INTO "katello_available_module_streams" ("name", "stream", "context") VALUES ($1, $2, $3) RETURNING "id"
2023-07-18 13:31:36 CEST ERROR:  duplicate key value violates unique constraint "katello_available_module_streams_name_stream_context"
2023-07-18 13:31:36 CEST DETAIL:  Key (name, stream, context)=(ruby, 2.5, ad008a3a) already exists.
2023-07-18 13:31:36 CEST STATEMENT:  INSERT INTO "katello_available_module_streams" ("name", "stream", "context") VALUES ($1, $2, $3) RETURNING "id"

Expected results:
No index violation.

Additional info:
Reported by customer but also reproduced locally, i will share reproducer details.

Comment 6 Jeremy Lenz 2023-08-25 13:57:09 UTC
I see what's happening now.

In the previous fix we switched to using Active Record `create_or_find_by` to avoid the race condition in concurrent registrations.

According to [1], the way that create_or_find_by works is

"If a row already exists with one or several of these unique constraints, the exception such an insertion would normally raise is caught, and the existing record with those attributes is found using #find_by!."

Therefore, the errors in Postgres are expected, and should not cause any harm.

[1] https://apidock.com/rails/v6.0.0/ActiveRecord/Relation/create_or_find_by

Comment 8 Jeremy Lenz 2023-09-18 13:24:04 UTC
Closing as NOTABUG; see https://bugzilla.redhat.com/show_bug.cgi?id=2223567#c6

Comment 20 Jeremy Lenz 2024-02-01 22:03:14 UTC
Created redmine issue https://projects.theforeman.org/issues/37137 from this bug

Comment 21 visawant 2024-03-13 11:40:30 UTC
Verified
Tested on 6.15.0 snap 10.1


Steps performed:
1. re-register RHEL8 host


#tail -f /var/log/foreman/production.log

2024-03-13T07:29:24 [I|app|ec960f3c] Started PUT "/rhsm/consumers/ee644f3d-945a-4370-8d5b-78bf0578a801/profiles" for 10.0.168.31 at 2024-03-13 07:29:24 -0400
2024-03-13T07:29:24 [I|app|ec960f3c] Processing by Katello::Api::Rhsm::CandlepinDynflowProxyController#upload_profiles as JSON
2024-03-13T07:29:24 [I|app|ec960f3c]   Parameters: {"id"=>"ee644f3d-945a-4370-8d5b-78bf0578a801"}
2024-03-13T07:29:24 [I|app|ec960f3c] Completed 200 OK in 146ms (Views: 1.5ms | ActiveRecord: 51.2ms | Allocations: 57452)
2024-03-13T07:29:24 [I|app|18be0722] Started GET "/rhsm/consumers/ee644f3d-945a-4370-8d5b-78bf0578a801/compliance" for 10.0.168.31 at 2024-03-13 07:29:24 -0400

# grep -ri "duplicate key value violates unique constraint \"katello_available_module_streams_name_stream_context\"" /var/lib/pgsql/data/log/
# tail -f /var/lib/pgsql/data/log/postgresql-Wed.log 
^C
#

Observation: Don't see any log inside /var/lib/pgsql/data/log/ related to index violation.

Comment 24 errata-xmlrpc 2024-04-23 17:11:43 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: Satellite 6.15.0 release), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2024:2010


Note You need to log in before you can comment on or make changes to this bug.