Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1837207

Summary: Drop temporary tables on transaction end to prevent vacuuming issues when upgrading to RHV 4.4 [RHV clone - 4.3.11]
Product: Red Hat Enterprise Virtualization Manager Reporter: RHV bug bot <rhv-bugzilla-bot>
Component: ovirt-engineAssignee: Eli Mesika <emesika>
Status: CLOSED ERRATA QA Contact: Petr Matyáš <pmatyas>
Severity: medium Docs Contact:
Priority: high    
Version: unspecifiedCC: aoconnor, bugs, emesika, mperina, mtessun, sgoodman
Target Milestone: ovirt-4.3.11Keywords: Automation, Regression, ZStream
Target Release: 4.3.11   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: rhv-4.3.11-2 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: 1828931 Environment:
Last Closed: 2020-09-30 10:07:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1828931    
Bug Blocks:    

Description RHV bug bot 2020-05-19 05:34:47 UTC
+++ This bug is an upstream to downstream clone. The original bug is: +++
+++   bug 1828931 +++
======================================================================

Description of problem:
When running engine-vacuum command it fails with permission denied for schema pg_temp_23 and various other schemas, I reproduced this with pg_temp_19, pg_temp_9 and pg_temp_23.

Version-Release number of selected component (if applicable):
ovirt-engine-tools-4.4.0-0.33.master.el8ev.noarch

How reproducible:
always

Steps to Reproduce:
1. run engine-vacuum
2.
3.

Actual results:
vacuumdb: vacuuming database "engine"
vacuumdb: error: vacuuming of table "pg_temp_23.tt_vm_pool_group" in database "engine" failed: ERROR:  permission denied for schema pg_temp_23

Expected results:
should vacuum the DB without errors

Additional info:

(Originally by Petr Matyas)

Comment 1 RHV bug bot 2020-05-19 05:34:50 UTC
engine-vacuum actually calls PG's vacuumdb utility 
I checked running directly vacuumdb with user 'engine' on the 'engine' db 

/usr/bin/vacuumdb -d engine -U engine

vacuumdb: error: vacuuming of table "pg_temp_6.tt_vm_pool_running" in database "engine" failed: ERROR:  permission denied for schema pg_temp_6

googling this a bit I found that [1]

So, this seems as a PG regression that forces vacuumdb to use postgres admin user to perform vacuum 

[1] https://github.com/greenplum-db/gpdb/pull/9304

(Originally by Eli Mesika)

Comment 2 RHV bug bot 2020-05-19 05:34:52 UTC
It seems like orphan schemas are left in the database , those schemas are not owned by the 'engine' role and can not be dropped by it 

engine=> select nspname from pg_namespace where nspname like 'pg_temp%';
  nspname   
------------
 pg_temp_1
 pg_temp_11
 pg_temp_12
 pg_temp_8
 pg_temp_6
 pg_temp_3
 pg_temp_14
 pg_temp_13
 pg_temp_4
 pg_temp_7
(10 rows)

The drop statements for those orphan schemas can be extracted to a sql script by;

 psql -U engine -Atc "select 'drop schema if exists ' || nspname || ' cascade;' from (select nspname from pg_namespace where nspname like 'pg_temp%') as foo" engine > drop_orphan_schemas.sql

Then we can run psql to execute this script before running vacuumdb , but still , the sql script must run from psql with the 'postgres' user

(Originally by Eli Mesika)

Comment 5 RHV bug bot 2020-05-19 05:34:59 UTC
This bug report has Keywords: Regression or TestBlocker.
Since no regressions or test blockers are allowed between releases, it is also being identified as a blocker for this release. Please resolve ASAP.

(Originally by pm-rhel)

Comment 6 RHV bug bot 2020-05-19 05:35:01 UTC
The documentation text flag should only be set after 'doc text' field is provided. Please provide the documentation text and set the flag to '?' again.

(Originally by pm-rhel)

Comment 7 RHV bug bot 2020-05-19 05:35:03 UTC
This paragraph should be added to the release doc:


For remote vacuuming if you got errors like 'permission denied for schema pg_temp_XX' please do the following:
     1) log in into the remote database machine
     2) run
           psql  -U <db-admin-role> -Atc \"select 'drop schema if exists ' || nspname || ' cascade;'
           from (select distinct nspname from pg_class join pg_namespace on (relnamespace=pg_namespace.oid)
           where pg_is_other_temp_schema(relnamespace)) as foo\" <engine database name > <temporary file>
     3) run
           psql  -U <db-admin-role> -f <temporary file>
     4) try to run engine-vacuum again"

(Originally by Eli Mesika)

Comment 8 RHV bug bot 2020-05-19 05:35:05 UTC
(In reply to Eli Mesika from comment #5)
> This paragraph should be added to the release doc:
> 
> 
> For remote vacuuming if you got errors like 'permission denied for schema
> pg_temp_XX' please do the following:
>      1) log in into the remote database machine
>      2) run
>            psql  -U <db-admin-role> -Atc \"select 'drop schema if exists '
> || nspname || ' cascade;'
>            from (select distinct nspname from pg_class join pg_namespace on
> (relnamespace=pg_namespace.oid)
>            where pg_is_other_temp_schema(relnamespace)) as foo\" <engine
> database name > <temporary file>
>      3) run
>            psql  -U <db-admin-role> -f <temporary file>
>      4) try to run engine-vacuum again"

Steven, we should also add this as a step into 4.4 upgrade guide to upgrade remote database chapters. Probably after restoring 4.3 database backup and upgrading this database from 10.6 to 12 and before running engine-setup.

(Originally by Martin Perina)

Comment 9 RHV bug bot 2020-05-19 05:35:08 UTC
OK. I added this comment to bug 1802650.

(Originally by Steve Goodman)

Comment 10 Martin Perina 2020-05-19 05:42:28 UTC
Currently we are leaving temporary tables on postgresql and it removes them as needed. Unfortunately it's not frequent enough and those temporary tables (respectively temporary tablespaces where those tables are stored) cause a permissions issue on PostgreSQL 12 when we try to run vacuumdb (vacuumdb needs to be executed under postgres user, which is not possible for remote databases). To minimize that issue we are going to backport changes in RHV database scripts to drop temporary tables at the end of transaction, so there's a good chance that existing temporary tables are already removed by PostgreSQL before RHV 4.3 setup is going to be upgraded to 4.4

Comment 11 Sandro Bonazzola 2020-06-16 08:54:58 UTC
$ git tag --contains 6cb2a16e51c52e4f21b068a535916052983ab48d
ovirt-engine-4.3.11

Comment 16 Petr Matyáš 2020-07-13 10:11:26 UTC
Verified on ovirt-engine-4.3.11.2-0.1.el7.noarch

Comment 19 errata-xmlrpc 2020-09-30 10:07:13 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 (Red Hat Virtualization Engine security, bug fix 4.3.11), 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/RHBA-2020:4112